@@ -111,18 +111,43 @@ iterate_thru_levels (GString *collective,
111
111
}
112
112
}
113
113
114
+ gchar *
115
+ run_regex_replace (const gchar * pattern ,
116
+ gchar * input ,
117
+ const gchar * replacement ,
118
+ GError * * error )
119
+ {
120
+ GRegex * re ;
121
+ gchar * out ;
122
+
123
+ out = NULL ;
124
+
125
+ re = g_regex_new (pattern ,
126
+ G_REGEX_OPTIMIZE ,
127
+ 0 ,
128
+ error );
129
+
130
+ if (re == NULL ) {
131
+ return NULL ;
132
+ }
133
+
134
+ out = g_regex_replace_literal (re , input , -1 , 0 , replacement , 0 , error );
135
+ g_free (input );
136
+ g_regex_unref (re );
137
+
138
+ return out ;
139
+ }
140
+
114
141
int
115
142
main (int argc , char * argv [])
116
143
{
117
144
GsfInput * input ;
118
145
GsfInfile * toplevel ;
119
146
GString * collective ;
120
- GRegex * re ;
121
147
GError * error ;
122
148
GFile * file ;
123
149
gchar * filename ;
124
- gchar * xml_strip_out ;
125
- gchar * space_strip_out ;
150
+ gchar * content ;
126
151
127
152
if (argc < 2 ) {
128
153
g_printerr ("Need a filename\n" );
@@ -149,6 +174,7 @@ main (int argc, char *argv[])
149
174
if (error != NULL )
150
175
{
151
176
g_critical ("Could not load mso file: %s" , error -> message );
177
+ g_object_unref (input );
152
178
g_error_free (error );
153
179
return 1 ;
154
180
}
@@ -160,33 +186,40 @@ main (int argc, char *argv[])
160
186
g_object_unref (toplevel );
161
187
g_object_unref (input );
162
188
163
- re = g_regex_new ("<[^>]+>" ,
164
- G_REGEX_OPTIMIZE ,
165
- 0 ,
166
- & error );
189
+ content = g_string_free (collective , FALSE);
167
190
168
- xml_strip_out = g_regex_replace_literal ( re , collective -> str , -1 , 0 , " " , 0 , & error );
169
- g_string_free ( collective , TRUE) ;
170
- g_regex_unref ( re );
191
+ if ( content == NULL ) {
192
+ goto out ;
193
+ }
171
194
172
- re = g_regex_new ("\\s+ " ,
173
- G_REGEX_OPTIMIZE ,
174
- 0 ,
175
- & error );
195
+ content = run_regex_replace ("<[^>]+> " ,
196
+ content ,
197
+ "" ,
198
+ & error );
176
199
177
- space_strip_out = g_regex_replace_literal (re , xml_strip_out , -1 , 0 , " " , 0 , & error );
178
- g_free (xml_strip_out );
179
- g_regex_unref (re );
200
+ if (content == NULL ) {
201
+ goto out ;
202
+ }
203
+
204
+ content = run_regex_replace ("\\s+" ,
205
+ content ,
206
+ " " ,
207
+ & error );
208
+
209
+ if (content == NULL ) {
210
+ goto out ;
211
+ }
212
+
213
+ g_printf ("%s" , content );
214
+ g_free (content );
180
215
216
+ out :
181
217
if (error != NULL )
182
218
{
183
- g_critical ("Could extract strings from mso file: %s" , error -> message );
219
+ g_critical ("Could not extract strings from mso 2003+ file: %s" , error -> message );
184
220
g_error_free (error );
185
221
return 1 ;
186
222
}
187
223
188
- g_printf ("%s" , space_strip_out );
189
- g_free (space_strip_out );
190
-
191
224
return 0 ;
192
225
}
0 commit comments