annotate gui/util/string.c @ 37195:ac6c37d85d65 default tip

configure: Fix initialization of variable def_local_aligned_32 It contiained the #define of HAVE_LOCAL_ALIGNED_16 instead of HAVE_LOCAL_ALIGNED_32.
author al
date Sun, 28 Sep 2014 18:38:41 +0000
parents b28b632efeef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
1 /*
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
2 * This file is part of MPlayer.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
3 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
7 * (at your option) any later version.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
8 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
12 * GNU General Public License for more details.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
13 *
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
17 */
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
18
35479
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
19 /**
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
20 * @file
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
21 * @brief String utilities
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
22 */
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
23
37024
0790f864cea2 Add a file for miscellaneous auxiliary functions.
ib
parents: 36991
diff changeset
24 #include <stdio.h>
33740
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
25 #include <stdlib.h>
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
26 #include <string.h>
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
27
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
28 #include "string.h"
35525
e27855a45128 Rebuild GUI directory structure.
ib
parents: 35493
diff changeset
29 #include "gui/app/gui.h"
34175
a345e7162d0a Move TranslateFilename() to util/string.c.
ib
parents: 33982
diff changeset
30
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
31 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
32 * @brief Convert a string to lower case.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
33 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
34 * @param string to be converted
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
35 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
36 * @return converted string
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
37 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
38 * @note Only characters from A to Z will be converted and this is an in-place conversion.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
39 */
33052
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
40 char *strlower(char *in)
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
41 {
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
42 char *p = in;
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
43
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
44 while (*p) {
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
45 if (*p >= 'A' && *p <= 'Z')
36986
575e1612c53a Simplify the expression.
ib
parents: 36984
diff changeset
46 *p += 0x20;
33052
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
47
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
48 p++;
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
49 }
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
50
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
51 return in;
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
52 }
956c67bb5198 Move strlower() into auxiliary string function file.
ib
parents: 33051
diff changeset
53
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
54 /**
36987
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
55 * @brief Convert a string to upper case.
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
56 *
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
57 * @param string to be converted
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
58 *
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
59 * @return converted string
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
60 *
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
61 * @note Only characters from a to z will be converted and this is an in-place conversion.
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
62 */
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
63 char *strupper(char *in)
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
64 {
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
65 char *p = in;
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
66
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
67 while (*p) {
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
68 if (*p >= 'a' && *p <= 'z')
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
69 *p -= 0x20;
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
70
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
71 p++;
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
72 }
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
73
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
74 return in;
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
75 }
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
76
b33ff300128e Add new string function strupper().
ib
parents: 36986
diff changeset
77 /**
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
78 * @brief Swap characters in a string.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
79 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
80 * @param in string to be processed
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
81 * @param from character to be swapped
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
82 * @param to character to swap in
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
83 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
84 * @return processed string
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
85 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
86 * @note All occurrences will be swapped and this is an in-place processing.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
87 */
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
88 char *strswap(char *in, char from, char to)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
89 {
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
90 char *p = in;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
91
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
92 while (*p) {
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
93 if (*p == from)
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
94 *p = to;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
95
33049
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
96 p++;
fc7a3f9f74f8 Simplify strswap().
ib
parents: 33048
diff changeset
97 }
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
98
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
99 return in;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
100 }
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
101
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
102 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
103 * @brief Remove all space characters from a string,
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
104 * but leave text enclosed in quotation marks untouched.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
105 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
106 * @param in string to be processed
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
107 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
108 * @return processed string
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
109 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
110 * @note This is an in-place processing.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
111 */
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
112 char *trim(char *in)
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
113 {
33051
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
114 char *src, *dest;
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35482
diff changeset
115 int freeze = False;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
116
33051
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
117 src = dest = in;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
118
33051
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
119 while (*src) {
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
120 if (*src == '"')
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
121 freeze = !freeze;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
122
33051
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
123 if (freeze || (*src != ' '))
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
124 *dest++ = *src;
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
125
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
126 src++;
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
127 }
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
128
33051
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
129 *dest = 0;
cec61c9f27f4 Simplify trim().
ib
parents: 33049
diff changeset
130
33048
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
131 return in;
c6d0adf896ea Move auxiliary string functions into separate file.
ib
parents:
diff changeset
132 }
33073
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
133
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
134 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
135 * @brief Remove a comment from a string,
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
136 * but leave text enclosed in quotation marks untouched.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
137 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
138 * A comment starts either with a semicolon anywhere in the string
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
139 * or with a number sign character at the very beginning.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
140 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
141 * @param in string to be processed
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
142 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
143 * @return string without comment
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
144 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
145 * @note This is an in-place processing, i.e. @a in will be shortened.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
146 */
33073
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
147 char *decomment(char *in)
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
148 {
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
149 char *p;
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35482
diff changeset
150 int nap = False;
33073
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
151
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
152 p = in;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
153
33080
60b2e408bd78 Allow number sign as comment character.
ib
parents: 33073
diff changeset
154 if (*p == '#')
60b2e408bd78 Allow number sign as comment character.
ib
parents: 33073
diff changeset
155 *p = 0;
60b2e408bd78 Allow number sign as comment character.
ib
parents: 33073
diff changeset
156
33073
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
157 while (*p) {
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
158 if (*p == '"')
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
159 nap = !nap;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
160
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
161 if ((*p == ';') && !nap) {
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
162 *p = 0;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
163 break;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
164 }
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
165
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
166 p++;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
167 }
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
168
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
169 return in;
334e19411421 Improve handling of the comment character.
ib
parents: 33052
diff changeset
170 }
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
171
35479
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
172 /**
36989
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
173 * @brief Extract a part of a string delimited by a separator character.
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
174 *
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
175 * @param in string to be analyzed
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
176 * @param out memory location of a buffer suitable to store the extracted part
36989
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
177 * @param sep separator character
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
178 * @param num number of separator characters to be skipped before extraction starts
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
179 * @param maxout maximum length of extracted part (including the trailing null byte)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
180 */
36991
fa8b6892b0bf Cosmetic: Rename cut functions.
ib
parents: 36989
diff changeset
181 void cutString(char *in, char *out, char sep, int num, size_t maxout)
36989
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
182 {
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
183 int n;
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
184 unsigned int i, c;
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
185
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
186 for (c = 0, n = 0, i = 0; in[i]; i++) {
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
187 if (in[i] == sep)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
188 n++;
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
189 if (n >= num && in[i] != sep && c + 1 < maxout)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
190 out[c++] = in[i];
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
191 if (n >= num && in[i + 1] == sep)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
192 break;
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
193 }
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
194
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
195 if (c < maxout)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
196 out[c] = 0;
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
197 }
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
198
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
199 /**
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
200 * @brief Extract a numeric part of a string delimited by a separator character.
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
201 *
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
202 * @param in string to be analyzed
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
203 * @param sep separator character
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
204 * @param num number of separator characters to be skipped before extraction starts
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
205 *
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
206 * @return extracted number (numeric part)
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
207 */
36991
fa8b6892b0bf Cosmetic: Rename cut functions.
ib
parents: 36989
diff changeset
208 int cutInt(char *in, char sep, int num)
36989
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
209 {
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
210 char tmp[64];
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
211
36991
fa8b6892b0bf Cosmetic: Rename cut functions.
ib
parents: 36989
diff changeset
212 cutStr(in, tmp, sep, num);
36989
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
213
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
214 return atoi(tmp);
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
215 }
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
216
0b80003f6542 Relocate the cut functions.
ib
parents: 36987
diff changeset
217 /**
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
218 * @brief A strchr() that can handle NULL pointer arguments.
35479
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
219 *
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
220 * @param str string to examine
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
221 * @param c character to find
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
222 *
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
223 * @return return value of strchr() or NULL, if @a str is NULL
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
224 */
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
225 char *gstrchr(const char *str, int c)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
226 {
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
227 if (!str)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
228 return NULL;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
229
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
230 return strchr(str, c);
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
231 }
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
232
35459
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
233 /**
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
234 * @brief A strcmp() that can handle NULL pointer arguments.
35459
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
235 *
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
236 * @param a string to be compared
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
237 * @param b string which is compared
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
238 *
35479
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
239 * @return return value of strcmp() or -1, if @a a or @a b are NULL
35459
1edb306bc754 Add doxygen comment.
ib
parents: 34685
diff changeset
240 */
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
241 int gstrcmp(const char *a, const char *b)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
242 {
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
243 if (!a && !b)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
244 return 0;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
245 if (!a || !b)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
246 return -1;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
247
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
248 return strcmp(a, b);
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
249 }
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
250
34628
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
251 /**
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
252 * @brief A strncmp() that can handle NULL pointer arguments.
34628
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
253 *
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
254 * @param a string to be compared
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
255 * @param b string which is compared
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
256 * @param n number of characters compared at the most
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
257 *
35479
ab09ed2d181b Add doxygen comments to string.c.
ib
parents: 35475
diff changeset
258 * @return return value of strncmp() or -1, if @a a or @a b are NULL
34628
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
259 */
ee78c9c66508 Add doxgen comment to gstrncmp().
ib
parents: 34560
diff changeset
260 int gstrncmp(const char *a, const char *b, size_t n)
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
261 {
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
262 if (!a && !b)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
263 return 0;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
264 if (!a || !b)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
265 return -1;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
266
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
267 return strncmp(a, b, n);
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
268 }
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
269
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
270 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
271 * @brief Duplicate a string.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
272 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
273 * If @a str is NULL, it returns NULL.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
274 * The string is duplicated by calling strdup().
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
275 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
276 * @param str string to be duplicated
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
277 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
278 * @return duplicated string (newly allocated)
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
279 */
33737
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
280 char *gstrdup(const char *str)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
281 {
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
282 if (!str)
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
283 return NULL;
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
284
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
285 return strdup(str);
71c29e8ec68f Move string functions from interface.c to string.c.
ib
parents: 33080
diff changeset
286 }
33740
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
287
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
288 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
289 * @brief Assign a duplicated string.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
290 *
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
291 * The string is duplicated by calling #gstrdup().
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
292 *
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
293 * @param old memory location to store the new pointer
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
294 * @param str string to be duplicated
35475
49f29de2ff10 Cosmetic: Place doxygen note at the end of the comment.
ib
parents: 35459
diff changeset
295 *
49f29de2ff10 Cosmetic: Place doxygen note at the end of the comment.
ib
parents: 35459
diff changeset
296 * @note @a *old is freed prior to the assignment.
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
297 */
33740
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
298 void setdup(char **old, const char *str)
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
299 {
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
300 free(*old);
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
301 *old = gstrdup(str);
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
302 }
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
303
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
304 /**
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
305 * @brief Assign a newly allocated string
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
306 * containing the path created from a directory and a filename.
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
307 *
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 37024
diff changeset
308 * @param old memory location to store the new pointer
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
309 * @param dir directory
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
310 * @param name filename
35475
49f29de2ff10 Cosmetic: Place doxygen note at the end of the comment.
ib
parents: 35459
diff changeset
311 *
49f29de2ff10 Cosmetic: Place doxygen note at the end of the comment.
ib
parents: 35459
diff changeset
312 * @note @a *old is freed prior to the assignment.
33982
d7527ee45784 Add doxygen comments to string.c.
ib
parents: 33786
diff changeset
313 */
33740
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
314 void setddup(char **old, const char *dir, const char *name)
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
315 {
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
316 free(*old);
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
317 *old = malloc(strlen(dir) + strlen(name) + 2);
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
318 if (*old)
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
319 sprintf(*old, "%s/%s", dir, name);
2c02269701bd Remove macros guiSetFilename() and guiSetDF() from interface.h.
ib
parents: 33737
diff changeset
320 }