summaryrefslogtreecommitdiff
path: root/lib/mbuiter.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mbuiter.h')
-rw-r--r--lib/mbuiter.h132
1 files changed, 71 insertions, 61 deletions
diff --git a/lib/mbuiter.h b/lib/mbuiter.h
index e6ad488..aad4fea 100644
--- a/lib/mbuiter.h
+++ b/lib/mbuiter.h
@@ -1,10 +1,10 @@
/* Iterating through multibyte strings: macros for multi-byte encodings.
- Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2005, 2007, 2009-2016 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,8 +12,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Written by Bruno Haible <bruno@clisp.org>. */
@@ -56,9 +55,9 @@
initializes the iterator, starting at startptr.
mbui_avail (iter)
- returns true if there are more multibyte chracters available before
+ returns true if there are more multibyte characters available before
the end of string is reached. In this case, mbui_cur (iter) is
- initialized to the next multibyte chracter.
+ initialized to the next multibyte character.
mbui_advance (iter)
advances the iterator by one multibyte character.
@@ -78,13 +77,13 @@
Here are the function prototypes of the macros.
- extern void mbui_init (mbui_iterator_t iter, const char *startptr);
- extern bool mbui_avail (mbui_iterator_t iter);
- extern void mbui_advance (mbui_iterator_t iter);
- extern mbchar_t mbui_cur (mbui_iterator_t iter);
- extern const char * mbui_cur_ptr (mbui_iterator_t iter);
- extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff);
- extern void mbui_copy (mbui_iterator_t *new, const mbui_iterator_t *old);
+ extern void mbui_init (mbui_iterator_t iter, const char *startptr);
+ extern bool mbui_avail (mbui_iterator_t iter);
+ extern void mbui_advance (mbui_iterator_t iter);
+ extern mbchar_t mbui_cur (mbui_iterator_t iter);
+ extern const char * mbui_cur_ptr (mbui_iterator_t iter);
+ extern void mbui_reloc (mbui_iterator_t iter, ptrdiff_t ptrdiff);
+ extern void mbui_copy (mbui_iterator_t *new, const mbui_iterator_t *old);
*/
#ifndef _MBUITER_H
@@ -92,6 +91,7 @@
#include <assert.h>
#include <stdbool.h>
+#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -106,21 +106,29 @@
#include "mbchar.h"
#include "strnlen1.h"
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef MBUITER_INLINE
+# define MBUITER_INLINE _GL_INLINE
+#endif
+
struct mbuiter_multi
{
- bool in_shift; /* true if next byte may not be interpreted as ASCII */
- mbstate_t state; /* if in_shift: current shift state */
- bool next_done; /* true if mbui_avail has already filled the following */
- struct mbchar cur; /* the current character:
- const char *cur.ptr pointer to current character
- The following are only valid after mbui_avail.
- size_t cur.bytes number of bytes of current character
- bool cur.wc_valid true if wc is a valid wide character
- wchar_t cur.wc if wc_valid: the current character
- */
+ bool in_shift; /* true if next byte may not be interpreted as ASCII */
+ mbstate_t state; /* if in_shift: current shift state */
+ bool next_done; /* true if mbui_avail has already filled the following */
+ struct mbchar cur; /* the current character:
+ const char *cur.ptr pointer to current character
+ The following are only valid after mbui_avail.
+ size_t cur.bytes number of bytes of current character
+ bool cur.wc_valid true if wc is a valid wide character
+ wchar_t cur.wc if wc_valid: the current character
+ */
};
-static inline void
+MBUITER_INLINE void
mbuiter_multi_next (struct mbuiter_multi *iter)
{
if (iter->next_done)
@@ -131,8 +139,8 @@ mbuiter_multi_next (struct mbuiter_multi *iter)
if (is_basic (*iter->cur.ptr))
{
/* These characters are part of the basic character set. ISO C 99
- guarantees that their wide character code is identical to their
- char code. */
+ guarantees that their wide character code is identical to their
+ char code. */
iter->cur.bytes = 1;
iter->cur.wc = *iter->cur.ptr;
iter->cur.wc_valid = true;
@@ -143,51 +151,51 @@ mbuiter_multi_next (struct mbuiter_multi *iter)
iter->in_shift = true;
with_shift:
iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr,
- strnlen1 (iter->cur.ptr, MB_CUR_MAX),
- &iter->state);
+ strnlen1 (iter->cur.ptr, MB_CUR_MAX),
+ &iter->state);
if (iter->cur.bytes == (size_t) -1)
- {
- /* An invalid multibyte sequence was encountered. */
- iter->cur.bytes = 1;
- iter->cur.wc_valid = false;
- /* Whether to set iter->in_shift = false and reset iter->state
- or not is not very important; the string is bogus anyway. */
- }
+ {
+ /* An invalid multibyte sequence was encountered. */
+ iter->cur.bytes = 1;
+ iter->cur.wc_valid = false;
+ /* Whether to set iter->in_shift = false and reset iter->state
+ or not is not very important; the string is bogus anyway. */
+ }
else if (iter->cur.bytes == (size_t) -2)
- {
- /* An incomplete multibyte character at the end. */
- iter->cur.bytes = strlen (iter->cur.ptr);
- iter->cur.wc_valid = false;
- /* Whether to set iter->in_shift = false and reset iter->state
- or not is not important; the string end is reached anyway. */
- }
+ {
+ /* An incomplete multibyte character at the end. */
+ iter->cur.bytes = strlen (iter->cur.ptr);
+ iter->cur.wc_valid = false;
+ /* Whether to set iter->in_shift = false and reset iter->state
+ or not is not important; the string end is reached anyway. */
+ }
else
- {
- if (iter->cur.bytes == 0)
- {
- /* A null wide character was encountered. */
- iter->cur.bytes = 1;
- assert (*iter->cur.ptr == '\0');
- assert (iter->cur.wc == 0);
- }
- iter->cur.wc_valid = true;
-
- /* When in the initial state, we can go back treating ASCII
- characters more quickly. */
- if (mbsinit (&iter->state))
- iter->in_shift = false;
- }
+ {
+ if (iter->cur.bytes == 0)
+ {
+ /* A null wide character was encountered. */
+ iter->cur.bytes = 1;
+ assert (*iter->cur.ptr == '\0');
+ assert (iter->cur.wc == 0);
+ }
+ iter->cur.wc_valid = true;
+
+ /* When in the initial state, we can go back treating ASCII
+ characters more quickly. */
+ if (mbsinit (&iter->state))
+ iter->in_shift = false;
+ }
}
iter->next_done = true;
}
-static inline void
+MBUITER_INLINE void
mbuiter_multi_reloc (struct mbuiter_multi *iter, ptrdiff_t ptrdiff)
{
iter->cur.ptr += ptrdiff;
}
-static inline void
+MBUITER_INLINE void
mbuiter_multi_copy (struct mbuiter_multi *new_iter, const struct mbuiter_multi *old_iter)
{
if ((new_iter->in_shift = old_iter->in_shift))
@@ -219,4 +227,6 @@ typedef struct mbuiter_multi mbui_iterator_t;
/* Copying an iterator. */
#define mbui_copy mbuiter_multi_copy
+_GL_INLINE_HEADER_END
+
#endif /* _MBUITER_H */