2N/A Copyright (C) 1995-1996, 2001-2010 Free Software Foundation, Inc. 2N/A This program is free software; you can redistribute it and/or modify 2N/A it under the terms of the GNU General Public License as published by 2N/A the Free Software Foundation; either version 3, or (at your option) 2N/A This program is distributed in the hope that it will be useful, 2N/A but WITHOUT ANY WARRANTY; without even the implied warranty of 2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 2N/A GNU General Public License for more details. 2N/A You should have received a copy of the GNU General Public License 2N/A along with this program; if not, write to the Free Software Foundation, 2N/A Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 2N/A/* The include_next requires a split double-inclusion guard. */ 2N/A/* NetBSD 5.0 mis-defines NULL. */ 2N/A/* MirBSD defines mbslen as a macro. */ 2N/A/* This feature is available in gcc versions 2.5 and later. */ 2N/A/* The attribute __pure__ was added in gcc 2.96. */ 2N/A/* But avoid namespace pollution on glibc systems. */ 2N/A/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ 2N/A/* The definition of _GL_ARG_NONNULL is copied here. */ 2N/A/* The definition of _GL_WARN_ON_USE is copied here. */ 2N/A/* Return the first instance of C within N bytes of S, or NULL. */ 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C" { const void * std::memchr (const void *, int, size_t); } 2N/A extern "C++" { void * std::memchr (void *, int, size_t); } */ 2N/A/* Assume memchr is always declared. */ 2N/A "use gnulib module memchr for portability" );
2N/A/* Return the first occurrence of NEEDLE in HAYSTACK. */ 2N/A "use gnulib module memmem-simple for portability, " 2N/A "and module memmem for speed" );
2N/A/* Copy N bytes of SRC to DEST, return pointer to bytes after the 2N/A last written byte. */ 2N/A "use gnulib module mempcpy for portability");
2N/A/* Search backwards through a block for a byte (specified as an int). */ 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C++" { const void * std::memrchr (const void *, int, size_t); } 2N/A extern "C++" { void * std::memrchr (void *, int, size_t); } */ 2N/A "use gnulib module memrchr for portability");
2N/A/* Find the first occurrence of C in S. More efficient than 2N/A memchr(S,C,N), at the expense of undefined behavior if C does not 2N/A occur within N bytes. */ 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C++" { const void * std::rawmemchr (const void *, int); } 2N/A extern "C++" { void * std::rawmemchr (void *, int); } */ 2N/A "use gnulib module rawmemchr for portability");
2N/A/* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ 2N/A "use gnulib module stpcpy for portability");
2N/A/* Copy no more than N bytes of SRC to DST, returning a pointer past the 2N/A last non-NUL byte written into DST. */ 2N/A "use gnulib module stpncpy for portability");
2N/A/* strchr() does not work with multibyte strings if the locale encoding is 2N/A GB18030 and the character to be searched is a digit. */ 2N/A/* Assume strchr is always declared. */ 2N/A "in some multibyte locales - " 2N/A "use mbschr if you care about internationalization");
2N/A/* Find the first occurrence of C in S or the final NUL byte. */ 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C++" { const char * std::strchrnul (const char *, int); } 2N/A extern "C++" { char * std::strchrnul (char *, int); } */ 2N/A "use gnulib module strchrnul for portability");
2N/A/* Duplicate S, returning an identical malloc'd string. */ 2N/A /* strdup exists as a function and as a macro. Get rid of the macro. */ 2N/A "use gnulib module strdup for portability");
2N/A/* Append no more than N characters from SRC onto DEST. */ 2N/A "use gnulib module strncat for portability");
2N/A/* Return a newly allocated copy of at most N bytes of STRING. */ 2N/A "use gnulib module strndup for portability");
2N/A/* Find the length (number of bytes) of STRING, but scan at most 2N/A MAXLEN bytes. If no '\0' terminator is found in that many bytes, 2N/A "use gnulib module strnlen for portability");
2N/A/* strcspn() assumes the second argument is a list of single-byte characters. 2N/A Even in this simple case, it does not work with multibyte strings if the 2N/A locale encoding is GB18030 and one of the characters to be searched is a 2N/A/* Assume strcspn is always declared. */ 2N/A "in multibyte locales - " 2N/A "use mbscspn if you care about internationalization");
2N/A/* Find the first occurrence in S of any character in ACCEPT. */ 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C" { const char * strpbrk (const char *, const char *); } 2N/A extern "C++" { char * strpbrk (char *, const char *); } */ 2N/A/* strpbrk() assumes the second argument is a list of single-byte characters. 2N/A Even in this simple case, it does not work with multibyte strings if the 2N/A locale encoding is GB18030 and one of the characters to be searched is a 2N/A "in multibyte locales - " 2N/A "use mbspbrk if you care about internationalization");
2N/A "use gnulib module strpbrk for portability");
2N/A/* strspn() assumes the second argument is a list of single-byte characters. 2N/A Even in this simple case, it cannot work with multibyte strings. */ 2N/A/* Assume strspn is always declared. */ 2N/A "in multibyte locales - " 2N/A "use mbsspn if you care about internationalization");
2N/A/* strrchr() does not work with multibyte strings if the locale encoding is 2N/A GB18030 and the character to be searched is a digit. */ 2N/A/* Assume strrchr is always declared. */ 2N/A "in some multibyte locales - " 2N/A "use mbsrchr if you care about internationalization");
2N/A/* Search the next delimiter (char listed in DELIM) starting at *STRINGP. 2N/A If one is found, overwrite it with a NUL, and advance *STRINGP 2N/A to point to the next char after it. Otherwise, set *STRINGP to NULL. 2N/A If *STRINGP was already NULL, nothing happens. 2N/A Return the old value of *STRINGP. 2N/A This is a variant of strtok() that is multithread-safe and supports 2N/A Caveat: It modifies the original string. 2N/A Caveat: These functions cannot be used on constant strings. 2N/A Caveat: The identity of the delimiting character is lost. 2N/A Caveat: It doesn't work with multibyte strings unless all of the delimiter 2N/A characters are ASCII characters < 0x30. 2N/A See also strtok_r(). */ 2N/A "in multibyte locales - " 2N/A "use mbssep if you care about internationalization");
2N/A "use gnulib module strsep for portability");
2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C++" { const char * strstr (const char *, const char *); } 2N/A extern "C++" { char * strstr (char *, const char *); } */ 2N/A/* strstr() does not work with multibyte strings if the locale encoding is 2N/A different from UTF-8: 2N/A POSIX says that it operates on "strings", and "string" in POSIX is defined 2N/A as a sequence of bytes, not of characters. */ 2N/A/* Assume strstr is always declared. */ 2N/A "work correctly on character strings in most " 2N/A "multibyte locales - " 2N/A "use mbsstr if you care about internationalization, " 2N/A "or use strstr if you care about speed");
2N/A/* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive 2N/A /* On some systems, this function is defined as an overloaded function: 2N/A extern "C++" { const char * strcasestr (const char *, const char *); } 2N/A extern "C++" { char * strcasestr (char *, const char *); } */ 2N/A/* strcasestr() does not work with multibyte strings: 2N/A It is a glibc extension, and glibc implements it only for unibyte 2N/A "strings in multibyte locales - " 2N/A "use mbscasestr if you care about " 2N/A "internationalization, or use c-strcasestr if you want " 2N/A "a locale independent function");
2N/A/* Parse S into tokens separated by characters in DELIM. 2N/A If S is NULL, the saved pointer in SAVE_PTR is used as 2N/A the next starting point. For example: 2N/A char s[] = "-abc-=-def"; 2N/A x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" 2N/A x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL 2N/A x = strtok_r(NULL, "=", &sp); // x = NULL 2N/A // s = "abc\0-def\0" 2N/A This is a variant of strtok() that is multithread-safe. 2N/A For the POSIX documentation for this function, see: 2N/A Caveat: It modifies the original string. 2N/A Caveat: These functions cannot be used on constant strings. 2N/A Caveat: The identity of the delimiting character is lost. 2N/A Caveat: It doesn't work with multibyte strings unless all of the delimiter 2N/A characters are ASCII characters < 0x30. 2N/A See also strsep(). */ 2N/A (
char *
restrict s,
char const *
restrict delim,
2N/A (
char *
restrict s,
char const *
restrict delim,
2N/A (
char *
restrict s,
char const *
restrict delim,
2N/A (
char *
restrict s,
char const *
restrict delim,
2N/A "strings in multibyte locales - " 2N/A "use mbstok_r if you care about internationalization");
2N/A "use gnulib module strtok_r for portability");
2N/A/* The following functions are not specified by POSIX. They are gnulib 2N/A/* Return the number of multibyte characters in the character string STRING. 2N/A This considers multibyte characters, unlike strlen, which counts bytes. */ 2N/A#
ifdef __MirBSD__ /* MirBSD defines mbslen as a macro. Override it. */ 2N/A#
if @
HAVE_MBSLEN@
/* AIX, OSF/1, MirBSD define mbslen already in libc. */ 2N/A/* Return the number of multibyte characters in the character string starting 2N/A at STRING and ending at STRING + LEN. */ 2N/A/* Locate the first single-byte character C in the character string STRING, 2N/A and return a pointer to it. Return NULL if C is not found in STRING. 2N/A Unlike strchr(), this function works correctly in multibyte locales with 2N/A encodings such as GB18030. */ 2N/A/* Locate the last single-byte character C in the character string STRING, 2N/A and return a pointer to it. Return NULL if C is not found in STRING. 2N/A Unlike strrchr(), this function works correctly in multibyte locales with 2N/A encodings such as GB18030. */ 2N/A/* Find the first occurrence of the character string NEEDLE in the character 2N/A string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. 2N/A Unlike strstr(), this function works correctly in multibyte locales with 2N/A encodings different from UTF-8. */ 2N/A/* Compare the character strings S1 and S2, ignoring case, returning less than, 2N/A equal to or greater than zero if S1 is lexicographically less than, equal to 2N/A Note: This function may, in multibyte locales, return 0 for strings of 2N/A Unlike strcasecmp(), this function works correctly in multibyte locales. */ 2N/A/* Compare the initial segment of the character string S1 consisting of at most 2N/A N characters with the initial segment of the character string S2 consisting 2N/A of at most N characters, ignoring case, returning less than, equal to or 2N/A greater than zero if the initial segment of S1 is lexicographically less 2N/A than, equal to or greater than the initial segment of S2. 2N/A Note: This function may, in multibyte locales, return 0 for initial segments 2N/A of different lengths! 2N/A Unlike strncasecmp(), this function works correctly in multibyte locales. 2N/A But beware that N is not a byte count but a character count! */ 2N/A/* Compare the initial segment of the character string STRING consisting of 2N/A at most mbslen (PREFIX) characters with the character string PREFIX, 2N/A ignoring case. If the two match, return a pointer to the first byte 2N/A after this prefix in STRING. Otherwise, return NULL. 2N/A Note: This function may, in multibyte locales, return non-NULL if STRING 2N/A is of smaller length than PREFIX! 2N/A Unlike strncasecmp(), this function works correctly in multibyte 2N/A/* Find the first occurrence of the character string NEEDLE in the character 2N/A string HAYSTACK, using case-insensitive comparison. 2N/A Note: This function may, in multibyte locales, return success even if 2N/A strlen (haystack) < strlen (needle) ! 2N/A Unlike strcasestr(), this function works correctly in multibyte locales. */ 2N/A/* Find the first occurrence in the character string STRING of any character 2N/A in the character string ACCEPT. Return the number of bytes from the 2N/A beginning of the string to this occurrence, or to the end of the string 2N/A Unlike strcspn(), this function works correctly in multibyte locales. */ 2N/A/* Find the first occurrence in the character string STRING of any character 2N/A in the character string ACCEPT. Return the pointer to it, or NULL if none 2N/A Unlike strpbrk(), this function works correctly in multibyte locales. */ 2N/A/* Find the first occurrence in the character string STRING of any character 2N/A not in the character string REJECT. Return the number of bytes from the 2N/A beginning of the string to this occurrence, or to the end of the string 2N/A Unlike strspn(), this function works correctly in multibyte locales. */ 2N/A/* Search the next delimiter (multibyte character listed in the character 2N/A string DELIM) starting at the character string *STRINGP. 2N/A If one is found, overwrite it with a NUL, and advance *STRINGP to point 2N/A to the next multibyte character after it. Otherwise, set *STRINGP to NULL. 2N/A If *STRINGP was already NULL, nothing happens. 2N/A Return the old value of *STRINGP. 2N/A This is a variant of mbstok_r() that supports empty fields. 2N/A Caveat: It modifies the original string. 2N/A Caveat: These functions cannot be used on constant strings. 2N/A Caveat: The identity of the delimiting character is lost. 2N/A See also mbstok_r(). */ 2N/A/* Parse the character string STRING into tokens separated by characters in 2N/A the character string DELIM. 2N/A If STRING is NULL, the saved pointer in SAVE_PTR is used as 2N/A the next starting point. For example: 2N/A char s[] = "-abc-=-def"; 2N/A x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" 2N/A x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL 2N/A x = mbstok_r(NULL, "=", &sp); // x = NULL 2N/A // s = "abc\0-def\0" 2N/A Caveat: It modifies the original string. 2N/A Caveat: These functions cannot be used on constant strings. 2N/A Caveat: The identity of the delimiting character is lost. 2N/A See also mbssep(). */ 2N/A/* Map any int, typically from errno, into an error message. */ 2N/A/* Assume strerror is always declared. */ 2N/A "use gnulib module strerror to guarantee non-NULL result");
2N/A/* Need to cast, because on Cygwin 1.5.x systems, the return type is 2N/A "use gnulib module strsignal for portability");
2N/A "use gnulib module strverscmp for portability");
2N/A#
endif /* _GL_STRING_H */ 2N/A#
endif /* _GL_STRING_H */