@@ -270,8 +270,12 @@ static int will_convert_lf_to_crlf(struct text_stat *stats,
270
270
static int validate_encoding (const char * path , const char * enc ,
271
271
const char * data , size_t len , int die_on_error )
272
272
{
273
+ const char * stripped ;
274
+
273
275
/* We only check for UTF here as UTF?? can be an alias for UTF-?? */
274
- if (istarts_with (enc , "UTF" )) {
276
+ if (skip_iprefix (enc , "UTF" , & stripped )) {
277
+ skip_prefix (stripped , "-" , & stripped );
278
+
275
279
/*
276
280
* Check for detectable errors in UTF encodings
277
281
*/
@@ -285,15 +289,10 @@ static int validate_encoding(const char *path, const char *enc,
285
289
*/
286
290
const char * advise_msg = _ (
287
291
"The file '%s' contains a byte order "
288
- "mark (BOM). Please use UTF-%s as "
292
+ "mark (BOM). Please use UTF-%.* s as "
289
293
"working-tree-encoding." );
290
- const char * stripped = NULL ;
291
- char * upper = xstrdup_toupper (enc );
292
- upper [strlen (upper )- 2 ] = '\0' ;
293
- if (skip_prefix (upper , "UTF" , & stripped ))
294
- skip_prefix (stripped , "-" , & stripped );
295
- advise (advise_msg , path , stripped );
296
- free (upper );
294
+ int stripped_len = strlen (stripped ) - strlen ("BE" );
295
+ advise (advise_msg , path , stripped_len , stripped );
297
296
if (die_on_error )
298
297
die (error_msg , path , enc );
299
298
else {
@@ -308,12 +307,7 @@ static int validate_encoding(const char *path, const char *enc,
308
307
"mark (BOM). Please use UTF-%sBE or UTF-%sLE "
309
308
"(depending on the byte order) as "
310
309
"working-tree-encoding." );
311
- const char * stripped = NULL ;
312
- char * upper = xstrdup_toupper (enc );
313
- if (skip_prefix (upper , "UTF" , & stripped ))
314
- skip_prefix (stripped , "-" , & stripped );
315
310
advise (advise_msg , path , stripped , stripped );
316
- free (upper );
317
311
if (die_on_error )
318
312
die (error_msg , path , enc );
319
313
else {
0 commit comments