Blame gnulib/lib/mbslen.c
|
Packit |
15a5a8 |
/* Counting the multibyte characters in a string.
|
|
Packit |
15a5a8 |
Copyright (C) 2007 Free Software Foundation, Inc.
|
|
Packit |
15a5a8 |
Written by Bruno Haible <bruno@clisp.org>, 2007.
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
This program is free software; you can redistribute it and/or modify
|
|
Packit |
15a5a8 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
15a5a8 |
the Free Software Foundation; either version 2, or (at your option)
|
|
Packit |
15a5a8 |
any later version.
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
15a5a8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
15a5a8 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
15a5a8 |
GNU General Public License for more details.
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
You should have received a copy of the GNU General Public License
|
|
Packit |
15a5a8 |
along with this program; if not, write to the Free Software Foundation,
|
|
Packit |
15a5a8 |
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
#include <config.h>
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
/* Specification. */
|
|
Packit |
15a5a8 |
#include <string.h>
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
#include <stdlib.h>
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
#if HAVE_MBRTOWC
|
|
Packit |
15a5a8 |
# include "mbuiter.h"
|
|
Packit |
15a5a8 |
#endif
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
/* Return the number of multibyte characters in the character string STRING. */
|
|
Packit |
15a5a8 |
size_t
|
|
Packit |
15a5a8 |
mbslen (const char *string)
|
|
Packit |
15a5a8 |
{
|
|
Packit |
15a5a8 |
#if HAVE_MBRTOWC
|
|
Packit |
15a5a8 |
if (MB_CUR_MAX > 1)
|
|
Packit |
15a5a8 |
{
|
|
Packit |
15a5a8 |
size_t count;
|
|
Packit |
15a5a8 |
mbui_iterator_t iter;
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
count = 0;
|
|
Packit |
15a5a8 |
for (mbui_init (iter, string); mbui_avail (iter); mbui_advance (iter))
|
|
Packit |
15a5a8 |
count++;
|
|
Packit |
15a5a8 |
|
|
Packit |
15a5a8 |
return count;
|
|
Packit |
15a5a8 |
}
|
|
Packit |
15a5a8 |
else
|
|
Packit |
15a5a8 |
#endif
|
|
Packit |
15a5a8 |
return strlen (string);
|
|
Packit |
15a5a8 |
}
|