NEWS.stable: log cherry-pick [e446f25]->[c092018] relocatable-shell: Update suggested...
[gnulib.git] / lib / mbiter.h
index b274da7..32fff8c 100644 (file)
@@ -1,5 +1,5 @@
 /* Iterating through multibyte strings: macros for multi-byte encodings.
-   Copyright (C) 2001, 2005, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2005, 2007, 2009-2014 Free Software Foundation, Inc.
 
    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
@@ -47,9 +47,9 @@
      initializes the iterator, starting at startptr and crossing length bytes.
 
    mbi_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, mbi_cur (iter) is
-     initialized to the next multibyte chracter.
+     initialized to the next multibyte character.
 
    mbi_advance (iter)
      advances the iterator by one multibyte character.
 
    Here are the function prototypes of the macros.
 
-   extern void         mbi_init (mbi_iterator_t iter,
-                                 const char *startptr, size_t length);
-   extern bool         mbi_avail (mbi_iterator_t iter);
-   extern void         mbi_advance (mbi_iterator_t iter);
-   extern mbchar_t     mbi_cur (mbi_iterator_t iter);
-   extern const char * mbi_cur_ptr (mbi_iterator_t iter);
-   extern void         mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff);
-   extern void         mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old);
+   extern void          mbi_init (mbi_iterator_t iter,
+                                  const char *startptr, size_t length);
+   extern bool          mbi_avail (mbi_iterator_t iter);
+   extern void          mbi_advance (mbi_iterator_t iter);
+   extern mbchar_t      mbi_cur (mbi_iterator_t iter);
+   extern const char *  mbi_cur_ptr (mbi_iterator_t iter);
+   extern void          mbi_reloc (mbi_iterator_t iter, ptrdiff_t ptrdiff);
+   extern void          mbi_copy (mbi_iterator_t *new, const mbi_iterator_t *old);
  */
 
 #ifndef _MBITER_H
 
 #include "mbchar.h"
 
+#ifndef _GL_INLINE_HEADER_BEGIN
+ #error "Please include config.h first."
+#endif
+_GL_INLINE_HEADER_BEGIN
+#ifndef MBITER_INLINE
+# define MBITER_INLINE _GL_INLINE
+#endif
+
 struct mbiter_multi
 {
-  const char *limit;   /* pointer to end of string */
-  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 mbi_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 mbi_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
-       */
+  const char *limit;    /* pointer to end of string */
+  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 mbi_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 mbi_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
+MBITER_INLINE void
 mbiter_multi_next (struct mbiter_multi *iter)
 {
   if (iter->next_done)
@@ -123,8 +131,8 @@ mbiter_multi_next (struct mbiter_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;
@@ -135,51 +143,51 @@ mbiter_multi_next (struct mbiter_multi *iter)
       iter->in_shift = true;
     with_shift:
       iter->cur.bytes = mbrtowc (&iter->cur.wc, iter->cur.ptr,
-                                iter->limit - iter->cur.ptr, &iter->state);
+                                 iter->limit - iter->cur.ptr, &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 = iter->limit - 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 = iter->limit - 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
+MBITER_INLINE void
 mbiter_multi_reloc (struct mbiter_multi *iter, ptrdiff_t ptrdiff)
 {
   iter->cur.ptr += ptrdiff;
   iter->limit += ptrdiff;
 }
 
-static inline void
+MBITER_INLINE void
 mbiter_multi_copy (struct mbiter_multi *new_iter, const struct mbiter_multi *old_iter)
 {
   new_iter->limit = old_iter->limit;
@@ -212,4 +220,6 @@ typedef struct mbiter_multi mbi_iterator_t;
 /* Copying an iterator.  */
 #define mbi_copy mbiter_multi_copy
 
+_GL_INLINE_HEADER_END
+
 #endif /* _MBITER_H */