Mercurial > hg > octave-kai > gnulib-hg
annotate lib/string.in.h @ 9600:99268e709d31
Avoid quadratic strstr implementations.
* lib/strstr.c: New file.
* m4/strstr.m4: Likewise.
* modules/strstr: Likewise.
* modules/strstr-tests: Likewise.
* tests/test-strstr.c: Likewise.
* lib/string.in.h (rpl_strstr): Declare.
(memmem) [GNULIB_POSIXCHECK]: Document speed issue.
* m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Support strstr.
* modules/string (Makefile.am): Likewise.
* MODULES.html.sh (string handling): Mention new module.
* doc/functions/strstr.texi (strstr): Document the bug.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Thu, 10 Jan 2008 07:38:11 -0700 |
parents | 246fc6fd3787 |
children | c4fa39bf5223 |
rev | line source |
---|---|
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* A GNU-like <string.h>. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
2 |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
3 Copyright (C) 1995-1996, 2001-2008 Free Software Foundation, Inc. |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
4 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
7 the Free Software Foundation; either version 2, or (at your option) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
8 any later version. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
9 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU General Public License for more details. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
14 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
16 along with this program; if not, write to the Free Software Foundation, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 #ifndef _GL_STRING_H |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 /* The include_next requires a split double-inclusion guard. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
22 #@INCLUDE_NEXT@ @NEXT_STRING_H@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
23 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
24 #ifndef _GL_STRING_H |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
25 #define _GL_STRING_H |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
26 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
27 |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
28 #ifndef __attribute__ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
29 /* This feature is available in gcc versions 2.5 and later. */ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
30 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
31 # define __attribute__(Spec) /* empty */ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
32 # endif |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
33 /* The attribute __pure__ was added in gcc 2.96. */ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
34 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 96) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
35 # define __pure__ /* empty */ |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
36 # endif |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
37 #endif |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
38 |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
39 |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 /* The definition of GL_LINK_WARNING is copied here. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
41 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
42 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 #ifdef __cplusplus |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 extern "C" { |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 |
9496
d7da1f241448
Move declarations of str{,n}casecmp from <string.h> to <strings.h>.
Bruno Haible <bruno@clisp.org>
parents:
9321
diff
changeset
|
47 |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 /* Return the first occurrence of NEEDLE in HAYSTACK. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 #if @GNULIB_MEMMEM@ |
9538
43d9769bf4d0
Fix memmem to avoid O(n^2) worst-case complexity.
Eric Blake <ebb9@byu.net>
parents:
9496
diff
changeset
|
50 # if @REPLACE_MEMMEM@ |
43d9769bf4d0
Fix memmem to avoid O(n^2) worst-case complexity.
Eric Blake <ebb9@byu.net>
parents:
9496
diff
changeset
|
51 # define memmem rpl_memmem |
43d9769bf4d0
Fix memmem to avoid O(n^2) worst-case complexity.
Eric Blake <ebb9@byu.net>
parents:
9496
diff
changeset
|
52 # endif |
43d9769bf4d0
Fix memmem to avoid O(n^2) worst-case complexity.
Eric Blake <ebb9@byu.net>
parents:
9496
diff
changeset
|
53 # if ! @HAVE_DECL_MEMMEM@ || @REPLACE_MEMMEM@ |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 extern void *memmem (void const *__haystack, size_t __haystack_len, |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
55 void const *__needle, size_t __needle_len) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
56 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
58 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
59 # undef memmem |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 # define memmem(a,al,b,bl) \ |
9600
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
61 (GL_LINK_WARNING ("memmem is unportable and often quadratic - " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
62 "use gnulib module memmem-simple for portability, " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
63 "and module memmem for speed" ), \ |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 memmem (a, al, b, bl)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 /* Copy N bytes of SRC to DEST, return pointer to bytes after the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 last written byte. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 #if @GNULIB_MEMPCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 # if ! @HAVE_MEMPCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 extern void *mempcpy (void *restrict __dest, void const *restrict __src, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 size_t __n); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
75 # undef mempcpy |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
76 # define mempcpy(a,b,n) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
77 (GL_LINK_WARNING ("mempcpy is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
78 "use gnulib module mempcpy for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
79 mempcpy (a, b, n)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
80 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
81 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
82 /* Search backwards through a block for a byte (specified as an int). */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
83 #if @GNULIB_MEMRCHR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
84 # if ! @HAVE_DECL_MEMRCHR@ |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
85 extern void *memrchr (void const *, int, size_t) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
86 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
87 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
88 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
89 # undef memrchr |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
90 # define memrchr(a,b,c) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
91 (GL_LINK_WARNING ("memrchr is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
92 "use gnulib module memrchr for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
93 memrchr (a, b, c)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
94 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
95 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
96 /* Copy SRC to DST, returning the address of the terminating '\0' in DST. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
97 #if @GNULIB_STPCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
98 # if ! @HAVE_STPCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
99 extern char *stpcpy (char *restrict __dst, char const *restrict __src); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
100 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
101 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
102 # undef stpcpy |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 # define stpcpy(a,b) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 (GL_LINK_WARNING ("stpcpy is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 "use gnulib module stpcpy for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 stpcpy (a, b)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 /* Copy no more than N bytes of SRC to DST, returning a pointer past the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 last non-NUL byte written into DST. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 #if @GNULIB_STPNCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 # if ! @HAVE_STPNCPY@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 # define stpncpy gnu_stpncpy |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 extern char *stpncpy (char *restrict __dst, char const *restrict __src, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 size_t __n); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 # undef stpncpy |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
119 # define stpncpy(a,b,n) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 (GL_LINK_WARNING ("stpncpy is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 "use gnulib module stpncpy for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 stpncpy (a, b, n)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 #if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 /* strchr() does not work with multibyte strings if the locale encoding is |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 GB18030 and the character to be searched is a digit. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 # undef strchr |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 # define strchr(s,c) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 (GL_LINK_WARNING ("strchr cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 "in some multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 "use mbschr if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 strchr (s, c)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 /* Find the first occurrence of C in S or the final NUL byte. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 #if @GNULIB_STRCHRNUL@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 # if ! @HAVE_STRCHRNUL@ |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
139 extern char *strchrnul (char const *__s, int __c_in) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
140 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 # undef strchrnul |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 # define strchrnul(a,b) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 (GL_LINK_WARNING ("strchrnul is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 "use gnulib module strchrnul for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 strchrnul (a, b)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 /* Duplicate S, returning an identical malloc'd string. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 #if @GNULIB_STRDUP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 # if ! @HAVE_DECL_STRDUP@ && ! defined strdup |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 extern char *strdup (char const *__s); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 # undef strdup |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 # define strdup(a) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 (GL_LINK_WARNING ("strdup is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 "use gnulib module strdup for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 strdup (a)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 /* Return a newly allocated copy of at most N bytes of STRING. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 #if @GNULIB_STRNDUP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 # if ! @HAVE_STRNDUP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 # undef strndup |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 # define strndup rpl_strndup |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 # if ! @HAVE_STRNDUP@ || ! @HAVE_DECL_STRNDUP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 extern char *strndup (char const *__string, size_t __n); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 # undef strndup |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 # define strndup(a,n) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 (GL_LINK_WARNING ("strndup is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 "use gnulib module strndup for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 strndup (a, n)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 /* Find the length (number of bytes) of STRING, but scan at most |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 MAXLEN bytes. If no '\0' terminator is found in that many bytes, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 return MAXLEN. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 #if @GNULIB_STRNLEN@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 # if ! @HAVE_DECL_STRNLEN@ |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
185 extern size_t strnlen (char const *__string, size_t __maxlen) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
186 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 # undef strnlen |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 # define strnlen(a,n) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 (GL_LINK_WARNING ("strnlen is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 "use gnulib module strnlen for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 strnlen (a, n)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
196 #if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 /* strcspn() assumes the second argument is a list of single-byte characters. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 Even in this simple case, it does not work with multibyte strings if the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
199 locale encoding is GB18030 and one of the characters to be searched is a |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
200 digit. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
201 # undef strcspn |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
202 # define strcspn(s,a) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
203 (GL_LINK_WARNING ("strcspn cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
204 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
205 "use mbscspn if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
206 strcspn (s, a)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
207 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
208 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
209 /* Find the first occurrence in S of any character in ACCEPT. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
210 #if @GNULIB_STRPBRK@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
211 # if ! @HAVE_STRPBRK@ |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
212 extern char *strpbrk (char const *__s, char const *__accept) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
213 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
214 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
215 # if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
216 /* strpbrk() assumes the second argument is a list of single-byte characters. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
217 Even in this simple case, it does not work with multibyte strings if the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
218 locale encoding is GB18030 and one of the characters to be searched is a |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
219 digit. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
220 # undef strpbrk |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
221 # define strpbrk(s,a) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
222 (GL_LINK_WARNING ("strpbrk cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
223 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
224 "use mbspbrk if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
225 strpbrk (s, a)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
226 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
227 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
228 # undef strpbrk |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
229 # define strpbrk(s,a) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
230 (GL_LINK_WARNING ("strpbrk is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
231 "use gnulib module strpbrk for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
232 strpbrk (s, a)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
233 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
234 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
235 #if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
236 /* strspn() assumes the second argument is a list of single-byte characters. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
237 Even in this simple case, it cannot work with multibyte strings. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
238 # undef strspn |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
239 # define strspn(s,a) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
240 (GL_LINK_WARNING ("strspn cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
241 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
242 "use mbsspn if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
243 strspn (s, a)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
244 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
245 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
246 #if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
247 /* strrchr() does not work with multibyte strings if the locale encoding is |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
248 GB18030 and the character to be searched is a digit. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
249 # undef strrchr |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
250 # define strrchr(s,c) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
251 (GL_LINK_WARNING ("strrchr cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
252 "in some multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
253 "use mbsrchr if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
254 strrchr (s, c)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
255 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
256 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
257 /* Search the next delimiter (char listed in DELIM) starting at *STRINGP. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
258 If one is found, overwrite it with a NUL, and advance *STRINGP |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
259 to point to the next char after it. Otherwise, set *STRINGP to NULL. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
260 If *STRINGP was already NULL, nothing happens. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
261 Return the old value of *STRINGP. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
262 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
263 This is a variant of strtok() that is multithread-safe and supports |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
264 empty fields. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
265 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
266 Caveat: It modifies the original string. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
267 Caveat: These functions cannot be used on constant strings. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
268 Caveat: The identity of the delimiting character is lost. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
269 Caveat: It doesn't work with multibyte strings unless all of the delimiter |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
270 characters are ASCII characters < 0x30. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
271 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
272 See also strtok_r(). */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
273 #if @GNULIB_STRSEP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
274 # if ! @HAVE_STRSEP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
275 extern char *strsep (char **restrict __stringp, char const *restrict __delim); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
276 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
277 # if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
278 # undef strsep |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
279 # define strsep(s,d) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
280 (GL_LINK_WARNING ("strsep cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
281 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
282 "use mbssep if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
283 strsep (s, d)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
284 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
285 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
286 # undef strsep |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
287 # define strsep(s,d) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
288 (GL_LINK_WARNING ("strsep is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
289 "use gnulib module strsep for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
290 strsep (s, d)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
291 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
292 |
9600
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
293 #if @GNULIB_STRSTR@ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
294 # if @REPLACE_STRSTR@ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
295 # define strstr rpl_strstr |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
296 char *strstr (const char *haystack, const char *needle) |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
297 __attribute__ ((__pure__)); |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
298 # endif |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
299 #elif defined GNULIB_POSIXCHECK |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
300 /* strstr() does not work with multibyte strings if the locale encoding is |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
301 different from UTF-8: |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
302 POSIX says that it operates on "strings", and "string" in POSIX is defined |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
303 as a sequence of bytes, not of characters. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
304 # undef strstr |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
305 # define strstr(a,b) \ |
9600
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
306 (GL_LINK_WARNING ("strstr is quadratic on many systems, and cannot " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
307 "work correctly on character strings in most " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
308 "multibyte locales - " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
309 "use mbsstr if you care about internationalization, " \ |
99268e709d31
Avoid quadratic strstr implementations.
Eric Blake <ebb9@byu.net>
parents:
9590
diff
changeset
|
310 "or use strstr if you care about speed"), \ |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
311 strstr (a, b)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
312 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
313 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
314 /* Find the first occurrence of NEEDLE in HAYSTACK, using case-insensitive |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
315 comparison. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
316 #if ! @HAVE_STRCASESTR@ |
9590
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
317 extern char *strcasestr (const char *haystack, const char *needle) |
246fc6fd3787
Give gcc some memmem optimization hints.
Eric Blake <ebb9@byu.net>
parents:
9538
diff
changeset
|
318 __attribute__ ((__pure__)); |
9264
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
319 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
320 #if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
321 /* strcasestr() does not work with multibyte strings: |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
322 It is a glibc extension, and glibc implements it only for unibyte |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
323 locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
324 # undef strcasestr |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
325 # define strcasestr(a,b) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
326 (GL_LINK_WARNING ("strcasestr does work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
327 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
328 "use mbscasestr if you care about " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
329 "internationalization, or use c-strcasestr if you want " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
330 "a locale independent function"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
331 strcasestr (a, b)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
332 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
333 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
334 /* Parse S into tokens separated by characters in DELIM. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
335 If S is NULL, the saved pointer in SAVE_PTR is used as |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
336 the next starting point. For example: |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
337 char s[] = "-abc-=-def"; |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
338 char *sp; |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
339 x = strtok_r(s, "-", &sp); // x = "abc", sp = "=-def" |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
340 x = strtok_r(NULL, "-=", &sp); // x = "def", sp = NULL |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
341 x = strtok_r(NULL, "=", &sp); // x = NULL |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
342 // s = "abc\0-def\0" |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
343 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
344 This is a variant of strtok() that is multithread-safe. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
345 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
346 For the POSIX documentation for this function, see: |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
347 http://www.opengroup.org/susv3xsh/strtok.html |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
348 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
349 Caveat: It modifies the original string. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
350 Caveat: These functions cannot be used on constant strings. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
351 Caveat: The identity of the delimiting character is lost. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
352 Caveat: It doesn't work with multibyte strings unless all of the delimiter |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
353 characters are ASCII characters < 0x30. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
354 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
355 See also strsep(). */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
356 #if @GNULIB_STRTOK_R@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
357 # if ! @HAVE_DECL_STRTOK_R@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
358 extern char *strtok_r (char *restrict s, char const *restrict delim, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
359 char **restrict save_ptr); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
360 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
361 # if defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
362 # undef strtok_r |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
363 # define strtok_r(s,d,p) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
364 (GL_LINK_WARNING ("strtok_r cannot work correctly on character strings " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
365 "in multibyte locales - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
366 "use mbstok_r if you care about internationalization"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
367 strtok_r (s, d, p)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
368 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
369 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
370 # undef strtok_r |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
371 # define strtok_r(s,d,p) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
372 (GL_LINK_WARNING ("strtok_r is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
373 "use gnulib module strtok_r for portability"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
374 strtok_r (s, d, p)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
375 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
376 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
377 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
378 /* The following functions are not specified by POSIX. They are gnulib |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
379 extensions. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
380 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
381 #if @GNULIB_MBSLEN@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
382 /* Return the number of multibyte characters in the character string STRING. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
383 This considers multibyte characters, unlike strlen, which counts bytes. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
384 extern size_t mbslen (const char *string); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
385 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
386 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
387 #if @GNULIB_MBSNLEN@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
388 /* Return the number of multibyte characters in the character string starting |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
389 at STRING and ending at STRING + LEN. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
390 extern size_t mbsnlen (const char *string, size_t len); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
391 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
392 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
393 #if @GNULIB_MBSCHR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
394 /* Locate the first single-byte character C in the character string STRING, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
395 and return a pointer to it. Return NULL if C is not found in STRING. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
396 Unlike strchr(), this function works correctly in multibyte locales with |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
397 encodings such as GB18030. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
398 # define mbschr rpl_mbschr /* avoid collision with HP-UX function */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
399 extern char * mbschr (const char *string, int c); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
400 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
401 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
402 #if @GNULIB_MBSRCHR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
403 /* Locate the last single-byte character C in the character string STRING, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
404 and return a pointer to it. Return NULL if C is not found in STRING. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
405 Unlike strrchr(), this function works correctly in multibyte locales with |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
406 encodings such as GB18030. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
407 # define mbsrchr rpl_mbsrchr /* avoid collision with HP-UX function */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
408 extern char * mbsrchr (const char *string, int c); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
409 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
410 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
411 #if @GNULIB_MBSSTR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
412 /* Find the first occurrence of the character string NEEDLE in the character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
413 string HAYSTACK. Return NULL if NEEDLE is not found in HAYSTACK. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
414 Unlike strstr(), this function works correctly in multibyte locales with |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
415 encodings different from UTF-8. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
416 extern char * mbsstr (const char *haystack, const char *needle); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
417 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
418 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
419 #if @GNULIB_MBSCASECMP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
420 /* Compare the character strings S1 and S2, ignoring case, returning less than, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
421 equal to or greater than zero if S1 is lexicographically less than, equal to |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
422 or greater than S2. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
423 Note: This function may, in multibyte locales, return 0 for strings of |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
424 different lengths! |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
425 Unlike strcasecmp(), this function works correctly in multibyte locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
426 extern int mbscasecmp (const char *s1, const char *s2); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
427 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
428 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
429 #if @GNULIB_MBSNCASECMP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
430 /* Compare the initial segment of the character string S1 consisting of at most |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
431 N characters with the initial segment of the character string S2 consisting |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
432 of at most N characters, ignoring case, returning less than, equal to or |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
433 greater than zero if the initial segment of S1 is lexicographically less |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
434 than, equal to or greater than the initial segment of S2. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
435 Note: This function may, in multibyte locales, return 0 for initial segments |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
436 of different lengths! |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
437 Unlike strncasecmp(), this function works correctly in multibyte locales. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
438 But beware that N is not a byte count but a character count! */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
439 extern int mbsncasecmp (const char *s1, const char *s2, size_t n); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
440 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
441 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
442 #if @GNULIB_MBSPCASECMP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
443 /* Compare the initial segment of the character string STRING consisting of |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
444 at most mbslen (PREFIX) characters with the character string PREFIX, |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
445 ignoring case, returning less than, equal to or greater than zero if this |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
446 initial segment is lexicographically less than, equal to or greater than |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
447 PREFIX. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
448 Note: This function may, in multibyte locales, return 0 if STRING is of |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
449 smaller length than PREFIX! |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
450 Unlike strncasecmp(), this function works correctly in multibyte |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
451 locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
452 extern char * mbspcasecmp (const char *string, const char *prefix); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
453 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
454 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
455 #if @GNULIB_MBSCASESTR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
456 /* Find the first occurrence of the character string NEEDLE in the character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
457 string HAYSTACK, using case-insensitive comparison. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
458 Note: This function may, in multibyte locales, return success even if |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
459 strlen (haystack) < strlen (needle) ! |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
460 Unlike strcasestr(), this function works correctly in multibyte locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
461 extern char * mbscasestr (const char *haystack, const char *needle); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
462 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
463 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
464 #if @GNULIB_MBSCSPN@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
465 /* Find the first occurrence in the character string STRING of any character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
466 in the character string ACCEPT. Return the number of bytes from the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
467 beginning of the string to this occurrence, or to the end of the string |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
468 if none exists. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
469 Unlike strcspn(), this function works correctly in multibyte locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
470 extern size_t mbscspn (const char *string, const char *accept); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
471 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
472 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
473 #if @GNULIB_MBSPBRK@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
474 /* Find the first occurrence in the character string STRING of any character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
475 in the character string ACCEPT. Return the pointer to it, or NULL if none |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
476 exists. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
477 Unlike strpbrk(), this function works correctly in multibyte locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
478 # define mbspbrk rpl_mbspbrk /* avoid collision with HP-UX function */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
479 extern char * mbspbrk (const char *string, const char *accept); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
480 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
481 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
482 #if @GNULIB_MBSSPN@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
483 /* Find the first occurrence in the character string STRING of any character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
484 not in the character string REJECT. Return the number of bytes from the |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
485 beginning of the string to this occurrence, or to the end of the string |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
486 if none exists. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
487 Unlike strspn(), this function works correctly in multibyte locales. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
488 extern size_t mbsspn (const char *string, const char *reject); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
489 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
490 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
491 #if @GNULIB_MBSSEP@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
492 /* Search the next delimiter (multibyte character listed in the character |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
493 string DELIM) starting at the character string *STRINGP. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
494 If one is found, overwrite it with a NUL, and advance *STRINGP to point |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
495 to the next multibyte character after it. Otherwise, set *STRINGP to NULL. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
496 If *STRINGP was already NULL, nothing happens. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
497 Return the old value of *STRINGP. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
498 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
499 This is a variant of mbstok_r() that supports empty fields. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
500 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
501 Caveat: It modifies the original string. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
502 Caveat: These functions cannot be used on constant strings. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
503 Caveat: The identity of the delimiting character is lost. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
504 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
505 See also mbstok_r(). */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
506 extern char * mbssep (char **stringp, const char *delim); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
507 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
508 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
509 #if @GNULIB_MBSTOK_R@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
510 /* Parse the character string STRING into tokens separated by characters in |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
511 the character string DELIM. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
512 If STRING is NULL, the saved pointer in SAVE_PTR is used as |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
513 the next starting point. For example: |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
514 char s[] = "-abc-=-def"; |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
515 char *sp; |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
516 x = mbstok_r(s, "-", &sp); // x = "abc", sp = "=-def" |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
517 x = mbstok_r(NULL, "-=", &sp); // x = "def", sp = NULL |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
518 x = mbstok_r(NULL, "=", &sp); // x = NULL |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
519 // s = "abc\0-def\0" |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
520 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
521 Caveat: It modifies the original string. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
522 Caveat: These functions cannot be used on constant strings. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
523 Caveat: The identity of the delimiting character is lost. |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
524 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
525 See also mbssep(). */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
526 extern char * mbstok_r (char *string, const char *delim, char **save_ptr); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
527 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
528 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
529 /* Map any int, typically from errno, into an error message. */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
530 #if @GNULIB_STRERROR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
531 # if @REPLACE_STRERROR@ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
532 # undef strerror |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
533 # define strerror rpl_strerror |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
534 extern char *strerror (int); |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
535 # endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
536 #elif defined GNULIB_POSIXCHECK |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
537 # undef strerror |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
538 # define strerror(e) \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
539 (GL_LINK_WARNING ("strerror is unportable - " \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
540 "use gnulib module strerror to guarantee non-NULL result"), \ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
541 strerror (e)) |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
542 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
543 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
544 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
545 #ifdef __cplusplus |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
546 } |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
547 #endif |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
548 |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
549 #endif /* _GL_STRING_H */ |
a1355710e330
Rename string_.h to string.in.h.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
550 #endif /* _GL_STRING_H */ |