annotate lib/mbssep.c @ 17476:6057744acd2c default tip master

autoupdate
author Karl Berry <karl@freefriends.org>
date Fri, 16 Aug 2013 06:32:22 -0700
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Tokenizing a string.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2007-2013 Free Software Foundation, Inc.
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2007.
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8112
diff changeset
5 This program is free software: you can redistribute it and/or modify
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8112
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8112
diff changeset
8 (at your option) any later version.
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 8112
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #include <config.h>
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 /* Specification. */
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <string.h>
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
10954
a0bbe1a6f787 Remove HAVE_MBRTOWC conditionals. Use mbrtowc unconditionally.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
23 #include "mbuiter.h"
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 char *
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 mbssep (char **stringp, const char *delim)
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 if (MB_CUR_MAX > 1)
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 {
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 char *start = *stringp;
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 char *ptr;
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 if (start == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
34 return NULL;
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 /* No need to optimize the cases of 0 or 1 delimiters specially,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
37 since mbspbrk already optimizes them. */
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 ptr = mbspbrk (start, delim);
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 if (ptr == NULL)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
42 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
43 *stringp = NULL;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
44 return start;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
45 }
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 else
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
47 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
48 mbui_iterator_t iter;
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
50 mbui_init (iter, ptr);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
51 if (!mbui_avail (iter))
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
52 abort ();
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
53 mbui_advance (iter);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
54 *ptr = '\0';
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
55 *stringp = (char *) mbui_cur_ptr (iter);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
56 return start;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 10954
diff changeset
57 }
8112
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 }
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 else
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 return strsep (stringp, delim);
c4c7688aa9bd New module 'mbssep'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 }