annotate lib/wcscspn-impl.h @ 16201:8250f2777afc

maint: update all copyright year number ranges Run "make update-copyright".
author Jim Meyering <meyering@redhat.com>
date Sun, 01 Jan 2012 10:04:58 +0100 (2012-01-01)
parents f0c82d0c08e6
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14298
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Search a wide string for any of a set of wide characters.
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14298
diff changeset
2 Copyright (C) 1999, 2011-2012 Free Software Foundation, Inc.
14298
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 1999.
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 (at your option) any later version.
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 size_t
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 wcscspn (const wchar_t *wcs, const wchar_t *reject)
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 {
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 /* Optimize two cases. */
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 if (reject[0] == (wchar_t)'\0')
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 return wcslen (wcs);
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 if (reject[1] == (wchar_t)'\0')
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 {
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 wchar_t wc = reject[0];
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 const wchar_t *ptr = wcs;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 for (; *ptr != (wchar_t)'\0'; ptr++)
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 {
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 if (*ptr == wc)
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 break;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 }
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 return ptr - wcs;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 }
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* General case. */
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 {
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 const wchar_t *ptr = wcs;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 for (; *ptr != (wchar_t)'\0'; ptr++)
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 {
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 if (wcschr (reject, *ptr))
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 break;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 }
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 return ptr - wcs;
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 }
f0c82d0c08e6 New module 'wcscspn'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 }