Mercurial > geeqie
comparison src/misc.c @ 1327:15208b140481
quoted_value is no longer needed
author | nadvornik |
---|---|
date | Thu, 26 Feb 2009 08:04:52 +0000 |
parents | 8b89e3ff286b |
children | 956aab097ea7 |
comparison
equal
deleted
inserted
replaced
1326:2b78c7198fbf | 1327:15208b140481 |
---|---|
112 else | 112 else |
113 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); | 113 return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); |
114 #endif | 114 #endif |
115 } | 115 } |
116 | 116 |
117 /* | |
118 returns text without quotes or NULL for empty or broken string | |
119 any text up to first '"' is skipped | |
120 tail is set to point at the char after the second '"' | |
121 or at the ending \0 | |
122 | |
123 */ | |
124 | |
125 gchar *quoted_value(const gchar *text, const gchar **tail) | |
126 { | |
127 const gchar *ptr; | |
128 gint c = 0; | |
129 gint l = strlen(text); | |
130 gchar *retval = NULL; | |
131 | |
132 if (tail) *tail = text; | |
133 | |
134 if (l == 0) return retval; | |
135 | |
136 while (c < l && text[c] != '"') c++; | |
137 if (text[c] == '"') | |
138 { | |
139 gint e; | |
140 c++; | |
141 ptr = text + c; | |
142 e = c; | |
143 while (e < l) | |
144 { | |
145 if (text[e-1] != '\\' && text[e] == '"') break; | |
146 e++; | |
147 } | |
148 if (text[e] == '"') | |
149 { | |
150 if (e - c > 0) | |
151 { | |
152 gchar *substring = g_strndup(ptr, e - c); | |
153 | |
154 if (substring) | |
155 { | |
156 retval = g_strcompress(substring); | |
157 g_free(substring); | |
158 } | |
159 } | |
160 } | |
161 if (tail) *tail = text + e + 1; | |
162 } | |
163 else | |
164 /* for compatibility with older formats (<0.3.7) | |
165 * read a line without quotes too */ | |
166 { | |
167 c = 0; | |
168 while (c < l && text[c] != '\n' && !g_ascii_isspace(text[c])) c++; | |
169 if (c != 0) | |
170 { | |
171 retval = g_strndup(text, c); | |
172 } | |
173 if (tail) *tail = text + c; | |
174 } | |
175 | |
176 return retval; | |
177 } | |
178 | |
179 gchar *escquote_value(const gchar *text) | |
180 { | |
181 gchar *e; | |
182 | |
183 if (!text) return g_strdup("\"\""); | |
184 | |
185 e = g_strescape(text, ""); | |
186 if (e) | |
187 { | |
188 gchar *retval = g_strdup_printf("\"%s\"", e); | |
189 g_free(e); | |
190 return retval; | |
191 } | |
192 return g_strdup("\"\""); | |
193 } | |
194 | 117 |
195 /* Run a command like system() but may output debug messages. */ | 118 /* Run a command like system() but may output debug messages. */ |
196 int runcmd(gchar *cmd) | 119 int runcmd(gchar *cmd) |
197 { | 120 { |
198 #if 1 | 121 #if 1 |