comparison gui/util/string.c @ 33982:d7527ee45784

Add doxygen comments to string.c.
author ib
date Tue, 06 Sep 2011 13:37:32 +0000
parents 0d3d8db05a59
children a345e7162d0a
comparison
equal deleted inserted replaced
33981:a59b359c20f7 33982:d7527ee45784
20 #include <stdlib.h> 20 #include <stdlib.h>
21 #include <string.h> 21 #include <string.h>
22 22
23 #include "string.h" 23 #include "string.h"
24 24
25 /**
26 * @brief Convert a string to lower case.
27 *
28 * @param string to be converted
29 *
30 * @return converted string
31 *
32 * @note Only characters from A to Z will be converted and this is an in-place conversion.
33 */
25 char *strlower(char *in) 34 char *strlower(char *in)
26 { 35 {
27 char *p = in; 36 char *p = in;
28 37
29 while (*p) { 38 while (*p) {
34 } 43 }
35 44
36 return in; 45 return in;
37 } 46 }
38 47
48 /**
49 * @brief Swap characters in a string.
50 *
51 * @param in string to be processed
52 * @param from character to be swapped
53 * @param to character to swap in
54 *
55 * @return processed string
56 *
57 * @note All occurrences will be swapped and this is an in-place processing.
58 */
39 char *strswap(char *in, char from, char to) 59 char *strswap(char *in, char from, char to)
40 { 60 {
41 char *p = in; 61 char *p = in;
42 62
43 while (*p) { 63 while (*p) {
48 } 68 }
49 69
50 return in; 70 return in;
51 } 71 }
52 72
73 /**
74 * @brief Remove all space characters from a string,
75 * but leave text enclosed in quotation marks untouched.
76 *
77 * @param in string to be processed
78 *
79 * @return processed string
80 *
81 * @note This is an in-place processing.
82 */
53 char *trim(char *in) 83 char *trim(char *in)
54 { 84 {
55 char *src, *dest; 85 char *src, *dest;
56 int freeze = 0; 86 int freeze = 0;
57 87
70 *dest = 0; 100 *dest = 0;
71 101
72 return in; 102 return in;
73 } 103 }
74 104
105 /**
106 * @brief Remove a comment from a string,
107 * but leave text enclosed in quotation marks untouched.
108 *
109 * A comment starts either with a semicolon anywhere in the string
110 * or with a number sign character at the very beginning.
111 *
112 * @param in string to be processed
113 *
114 * @return string without comment
115 *
116 * @note This is an in-place processing, i.e. @a in will be shortened.
117 */
75 char *decomment(char *in) 118 char *decomment(char *in)
76 { 119 {
77 char *p; 120 char *p;
78 int nap = 0; 121 int nap = 0;
79 122
133 return -1; 176 return -1;
134 177
135 return strncmp(a, b, n); 178 return strncmp(a, b, n);
136 } 179 }
137 180
181 /**
182 * @brief Duplicate a string.
183 *
184 * If @a str is NULL, it returns NULL.
185 * The string is duplicated by calling strdup().
186 *
187 * @param str string to be duplicated
188 *
189 * @return duplicated string (newly allocated)
190 */
138 char *gstrdup(const char *str) 191 char *gstrdup(const char *str)
139 { 192 {
140 if (!str) 193 if (!str)
141 return NULL; 194 return NULL;
142 195
143 return strdup(str); 196 return strdup(str);
144 } 197 }
145 198
199 /**
200 * @brief Assign a duplicated string.
201 *
202 * The string is duplicated by calling #gstrdup().
203 *
204 * @note @a *old is freed prior to the assignment.
205 *
206 * @param old pointer to a variable suitable to store the new pointer
207 * @param str string to be duplicated
208 */
146 void setdup(char **old, const char *str) 209 void setdup(char **old, const char *str)
147 { 210 {
148 free(*old); 211 free(*old);
149 *old = gstrdup(str); 212 *old = gstrdup(str);
150 } 213 }
151 214
215 /**
216 * @brief Assign a newly allocated string
217 * containing the path created from a directory and a filename.
218 *
219 * @note @a *old is freed prior to the assignment.
220 *
221 * @param old pointer to a variable suitable to store the new pointer
222 * @param dir directory
223 * @param name filename
224 */
152 void setddup(char **old, const char *dir, const char *name) 225 void setddup(char **old, const char *dir, const char *name)
153 { 226 {
154 free(*old); 227 free(*old);
155 *old = malloc(strlen(dir) + strlen(name) + 2); 228 *old = malloc(strlen(dir) + strlen(name) + 2);
156 if (*old) 229 if (*old)