Mercurial > audlegacy
annotate src/audacious/strings.c @ 4180:bf6092a180f6
Remove --session. It is legacy from before Audacious used DBus. (Bugzilla #97)
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Fri, 11 Jan 2008 11:46:07 -0600 |
parents | 9e24c8746d99 |
children | 5f92bee6cd5b |
rev | line source |
---|---|
2313 | 1 /* Audacious |
2 * Copyright (C) 2005-2007 Audacious development team. | |
3 * | |
4 * BMP - Cross-platform multimedia player | |
5 * Copyright (C) 2003-2004 BMP development team. | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3116
diff
changeset
|
12 * the Free Software Foundation; under version 3 of the License. |
2313 | 13 * |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3116
diff
changeset
|
20 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
21 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
22 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
23 * Audacious or using our public API to be a derived work. |
2313 | 24 */ |
25 | |
2375
063374a51105
[svn] - config.h is necessary to conditional compilation of chardet.
yaz
parents:
2373
diff
changeset
|
26 #ifdef HAVE_CONFIG_H |
063374a51105
[svn] - config.h is necessary to conditional compilation of chardet.
yaz
parents:
2373
diff
changeset
|
27 # include "config.h" |
063374a51105
[svn] - config.h is necessary to conditional compilation of chardet.
yaz
parents:
2373
diff
changeset
|
28 #endif |
063374a51105
[svn] - config.h is necessary to conditional compilation of chardet.
yaz
parents:
2373
diff
changeset
|
29 |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2332
diff
changeset
|
30 #include "strings.h" |
2313 | 31 |
32 #include <glib/gi18n.h> | |
33 #include <string.h> | |
34 #include <ctype.h> | |
35 | |
36 #include "main.h" | |
37 | |
2559 | 38 #include "../libguess/libguess.h" |
2313 | 39 #ifdef HAVE_UDET |
40 #include <libudet_c.h> | |
41 #endif | |
42 | |
43 /* | |
44 * escape_shell_chars() | |
45 * | |
46 * Escapes characters that are special to the shell inside double quotes. | |
47 */ | |
48 | |
49 gchar * | |
50 escape_shell_chars(const gchar * string) | |
51 { | |
52 const gchar *special = "$`\"\\"; /* Characters to escape */ | |
53 const gchar *in = string; | |
54 gchar *out, *escaped; | |
55 gint num = 0; | |
56 | |
57 while (*in != '\0') | |
58 if (strchr(special, *in++)) | |
59 num++; | |
60 | |
61 escaped = g_malloc(strlen(string) + num + 1); | |
62 | |
63 in = string; | |
64 out = escaped; | |
65 | |
66 while (*in != '\0') { | |
67 if (strchr(special, *in)) | |
68 *out++ = '\\'; | |
69 *out++ = *in++; | |
70 } | |
71 *out = '\0'; | |
72 | |
73 return escaped; | |
74 } | |
75 | |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
76 /* replace %20 with ' ' in place */ |
2313 | 77 static gchar * |
78 str_twenty_to_space(gchar * str) | |
79 { | |
80 gchar *match, *match_end; | |
81 | |
82 g_return_val_if_fail(str != NULL, NULL); | |
83 | |
84 while ((match = strstr(str, "%20"))) { | |
85 match_end = match + 3; | |
86 *match++ = ' '; | |
87 while (*match_end) | |
88 *match++ = *match_end++; | |
89 *match = 0; | |
90 } | |
91 | |
92 return str; | |
93 } | |
94 | |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
95 /* replace drive letter with '/' in place */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
96 static gchar * |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
97 str_replace_drive_letter(gchar * str) |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
98 { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
99 gchar *match, *match_end; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
100 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
101 g_return_val_if_fail(str != NULL, NULL); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
102 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
103 while ((match = strstr(str, ":\\"))) { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
104 match--; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
105 match_end = match + 3; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
106 *match++ = '/'; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
107 while (*match_end) |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
108 *match++ = *match_end++; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
109 *match = 0; /* the end of line */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
110 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
111 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
112 return str; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
113 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
114 |
2313 | 115 static gchar * |
116 str_replace_char(gchar * str, gchar old, gchar new) | |
117 { | |
118 gchar *match; | |
119 | |
120 g_return_val_if_fail(str != NULL, NULL); | |
121 | |
122 match = str; | |
123 while ((match = strchr(match, old))) | |
124 *match = new; | |
125 | |
126 return str; | |
127 } | |
128 | |
129 gchar * | |
130 str_append(gchar * str, const gchar * add_str) | |
131 { | |
132 return str_replace(str, g_strconcat(str, add_str, NULL)); | |
133 } | |
134 | |
135 gchar * | |
136 str_replace(gchar * str, gchar * new_str) | |
137 { | |
138 g_free(str); | |
139 return new_str; | |
140 } | |
141 | |
142 void | |
143 str_replace_in(gchar ** str, gchar * new_str) | |
144 { | |
145 *str = str_replace(*str, new_str); | |
146 } | |
147 | |
148 | |
149 gboolean | |
150 str_has_prefix_nocase(const gchar * str, const gchar * prefix) | |
151 { | |
152 return (strncasecmp(str, prefix, strlen(prefix)) == 0); | |
153 } | |
154 | |
155 gboolean | |
156 str_has_suffix_nocase(const gchar * str, const gchar * suffix) | |
157 { | |
158 return (strcasecmp(str + strlen(str) - strlen(suffix), suffix) == 0); | |
159 } | |
160 | |
161 gboolean | |
162 str_has_suffixes_nocase(const gchar * str, gchar * const *suffixes) | |
163 { | |
164 gchar *const *suffix; | |
165 | |
166 g_return_val_if_fail(str != NULL, FALSE); | |
167 g_return_val_if_fail(suffixes != NULL, FALSE); | |
168 | |
169 for (suffix = suffixes; *suffix; suffix++) | |
170 if (str_has_suffix_nocase(str, *suffix)) | |
171 return TRUE; | |
172 | |
173 return FALSE; | |
174 } | |
175 | |
176 gchar * | |
177 str_to_utf8_fallback(const gchar * str) | |
178 { | |
179 gchar *out_str, *convert_str, *chr; | |
180 | |
181 /* NULL in NULL out */ | |
182 if (!str) | |
183 return NULL; | |
184 | |
185 convert_str = g_strdup(str); | |
186 for (chr = convert_str; *chr; chr++) { | |
187 if (*chr & 0x80) | |
188 *chr = '?'; | |
189 } | |
190 | |
191 out_str = g_strconcat(convert_str, _(" (invalid UTF-8)"), NULL); | |
192 g_free(convert_str); | |
193 | |
194 return out_str; | |
195 } | |
196 | |
4089
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
197 /* convert name of absolute path in local file system encoding into utf8 string */ |
2313 | 198 gchar * |
199 filename_to_utf8(const gchar * filename) | |
200 { | |
201 gchar *out_str; | |
202 | |
203 /* NULL in NULL out */ | |
204 if (!filename) | |
205 return NULL; | |
206 | |
207 if ((out_str = g_filename_to_utf8(filename, -1, NULL, NULL, NULL))) | |
208 return out_str; | |
209 | |
210 return str_to_utf8_fallback(filename); | |
211 } | |
212 | |
4089
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
213 /* derives basename from uri. basename is in utf8 */ |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
214 gchar * |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
215 uri_to_display_basename(const gchar * uri) |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
216 { |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
217 gchar *realfn, *utf8fn, *basename; |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
218 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
219 g_return_val_if_fail(uri, NULL); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
220 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
221 realfn = g_filename_from_uri(uri, NULL, NULL); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
222 utf8fn = g_filename_display_name(realfn ? realfn : uri); // guaranteed to be non-NULL |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
223 basename = g_path_get_basename(utf8fn); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
224 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
225 g_free(realfn); g_free(utf8fn); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
226 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
227 return basename; |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
228 } |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
229 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
230 /* derives dirname from uri. dirname is in utf8 */ |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
231 gchar * |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
232 uri_to_display_dirname(const gchar * uri) |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
233 { |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
234 gchar *realfn, *utf8fn, *dirname; |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
235 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
236 g_return_val_if_fail(uri, NULL); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
237 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
238 realfn = g_filename_from_uri(uri, NULL, NULL); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
239 utf8fn = g_filename_display_name(realfn ? realfn : uri); // guaranteed to be non-NULL |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
240 dirname = g_path_get_dirname(utf8fn); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
241 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
242 g_free(realfn); g_free(utf8fn); |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
243 |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
244 return dirname; |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
245 } |
9e24c8746d99
- introduce new API functions uri_to_display_basename() and uri_to_display_dirname(). each function derives utf8 encoded basename or dirname from given uri respectively.
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
4070
diff
changeset
|
246 |
2313 | 247 gchar * |
248 str_to_utf8(const gchar * str) | |
249 { | |
250 gchar *out_str; | |
251 | |
252 /* NULL in NULL out */ | |
3116
a2d234851527
Switching from g_return_val_if_fail() to a more quiet return NULL
Christian Birchinger <joker@netswarm.net>
parents:
2787
diff
changeset
|
253 /* g_return_val_if_fail(str != NULL, NULL); */ |
a2d234851527
Switching from g_return_val_if_fail() to a more quiet return NULL
Christian Birchinger <joker@netswarm.net>
parents:
2787
diff
changeset
|
254 if (!str) |
a2d234851527
Switching from g_return_val_if_fail() to a more quiet return NULL
Christian Birchinger <joker@netswarm.net>
parents:
2787
diff
changeset
|
255 return NULL; |
2313 | 256 |
257 /* Note: Currently, playlist calls this function repeatedly, even | |
258 * if the string is already converted into utf-8. | |
259 * chardet_to_utf8() would convert a valid utf-8 string into a | |
260 * different utf-8 string, if fallback encodings were supplied and | |
2559 | 261 * the given string could be treated as a string in one of |
262 * fallback encodings. To avoid this, g_utf8_validate() had been | |
263 * used at the top of evaluation. | |
264 */ | |
265 | |
266 /* Note 2: g_utf8_validate() has so called encapsulated utf-8 | |
267 * problem, thus chardet_to_utf8() took the place of that. | |
2313 | 268 */ |
2559 | 269 |
270 /* Note 3: As introducing madplug, the problem of conversion from | |
271 * ISO-8859-1 to UTF-8 arose. This may be coped with g_convert() | |
272 * located near the end of chardet_to_utf8(), but it requires utf8 | |
273 * validation guard where g_utf8_validate() was. New | |
274 * dfa_validate_utf8() employs libguess' DFA engine to validate | |
275 * utf-8 and can properly distinguish examples of encapsulated | |
276 * utf-8. It is considered to be safe to use as a guard. | |
277 */ | |
278 | |
279 /* already UTF-8? */ | |
280 if (dfa_validate_utf8(str, strlen(str))) | |
281 return g_strdup(str); | |
282 | |
2313 | 283 /* chardet encoding detector */ |
284 if ((out_str = chardet_to_utf8(str, strlen(str), NULL, NULL, NULL))) | |
285 return out_str; | |
286 | |
287 /* assume encoding associated with locale */ | |
288 if ((out_str = g_locale_to_utf8(str, -1, NULL, NULL, NULL))) | |
289 return out_str; | |
290 | |
291 /* all else fails, we mask off character codes >= 128, | |
292 replace with '?' */ | |
293 return str_to_utf8_fallback(str); | |
294 } | |
295 | |
296 | |
297 const gchar * | |
298 str_skip_chars(const gchar * str, const gchar * chars) | |
299 { | |
300 while (strchr(chars, *str)) | |
301 str++; | |
302 return str; | |
303 } | |
304 | |
305 gchar * | |
306 convert_title_text(gchar * title) | |
307 { | |
308 g_return_val_if_fail(title != NULL, NULL); | |
309 | |
310 if (cfg.convert_slash) | |
311 str_replace_char(title, '\\', '/'); | |
312 | |
313 if (cfg.convert_underscore) | |
314 str_replace_char(title, '_', ' '); | |
315 | |
316 if (cfg.convert_twenty) | |
317 str_twenty_to_space(title); | |
318 | |
319 return title; | |
320 } | |
321 | |
4070
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
322 gchar * |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
323 convert_dos_path(gchar * path) |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
324 { |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
325 g_return_val_if_fail(path != NULL, NULL); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
326 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
327 /* replace drive letter with '/' */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
328 str_replace_drive_letter(path); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
329 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
330 /* replace '\' with '/' */ |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
331 str_replace_char(path, '\\', '/'); |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
332 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
333 return path; |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
334 } |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
335 |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
336 gchar * |
040243a50bd3
- modified playlist_load_ins_file() and playlist_load_ins_file_tuple(). path builder and ext_hash checker
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
3209
diff
changeset
|
337 chardet_to_utf8(const gchar *str, gssize len, |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2332
diff
changeset
|
338 gsize *arg_bytes_read, gsize *arg_bytes_write, |
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2332
diff
changeset
|
339 GError **arg_error) |
2313 | 340 { |
341 #ifdef USE_CHARDET | |
342 char *det = NULL, *encoding = NULL; | |
343 #endif | |
344 gchar *ret = NULL; | |
345 gsize *bytes_read, *bytes_write; | |
346 GError **error; | |
347 gsize my_bytes_read, my_bytes_write; | |
348 | |
349 bytes_read = arg_bytes_read ? arg_bytes_read : &my_bytes_read; | |
350 bytes_write = arg_bytes_write ? arg_bytes_write : &my_bytes_write; | |
351 error = arg_error ? arg_error : NULL; | |
352 | |
2787
e35538325145
[svn] - add some assertions to chardet_to_utf8() to try to trace bad g_convert() calls
nenolod
parents:
2559
diff
changeset
|
353 g_return_val_if_fail(str != NULL, NULL); |
e35538325145
[svn] - add some assertions to chardet_to_utf8() to try to trace bad g_convert() calls
nenolod
parents:
2559
diff
changeset
|
354 |
2313 | 355 #ifdef USE_CHARDET |
356 if(cfg.chardet_detector) | |
357 det = cfg.chardet_detector; | |
358 | |
3209
41a91ed36bfa
Use new combined libguess interface.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
359 guess_init(); |
41a91ed36bfa
Use new combined libguess interface.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
360 |
2313 | 361 if(det){ |
3209
41a91ed36bfa
Use new combined libguess interface.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
362 encoding = (char *) guess_encoding(str, strlen(str), det); |
41a91ed36bfa
Use new combined libguess interface.
William Pitcock <nenolod@atheme-project.org>
parents:
3123
diff
changeset
|
363 if (!encoding) |
2313 | 364 goto fallback; |
365 | |
366 ret = g_convert(str, len, "UTF-8", encoding, bytes_read, bytes_write, error); | |
367 } | |
368 | |
369 fallback: | |
370 #endif | |
371 if(!ret && cfg.chardet_fallback){ | |
372 gchar **encs=NULL, **enc=NULL; | |
373 encs = g_strsplit_set(cfg.chardet_fallback, " ,:;|/", 0); | |
374 | |
375 if(encs){ | |
376 enc = encs; | |
377 for(enc=encs; *enc ; enc++){ | |
378 ret = g_convert(str, len, "UTF-8", *enc, bytes_read, bytes_write, error); | |
379 if(len == *bytes_read){ | |
380 break; | |
381 } | |
382 } | |
383 g_strfreev(encs); | |
384 } | |
385 } | |
386 | |
387 if(!ret){ | |
388 ret = g_convert(str, len, "UTF-8", "ISO-8859-1", bytes_read, bytes_write, error); | |
389 } | |
390 | |
391 if(ret){ | |
392 if(g_utf8_validate(ret, -1, NULL)) | |
393 return ret; | |
394 else { | |
395 g_free(ret); | |
396 ret = NULL; | |
397 } | |
398 } | |
399 | |
400 return NULL; /* if I have no idea, return NULL. */ | |
401 } |