@@ -328,6 +328,31 @@ bool apply_style(struct mako_style *target, const struct mako_style *style) {
328
328
return true;
329
329
}
330
330
331
+ // Find unique specifiers in the given format
332
+ void find_unique_specifiers (char * format , char * target_format , char * target_format_pos ) {
333
+ char * format_pos = format ;
334
+ char current_specifier [3 ] = {0 };
335
+ while (* format_pos ) {
336
+ format_pos = strstr (format_pos , "%" );
337
+ if (!format_pos ) {
338
+ break ;
339
+ }
340
+
341
+ // We only want to add the format specifier to the target if we
342
+ // haven't already seen it.
343
+ // Need to copy the specifier into its own string to use strstr
344
+ // here, because there's no way to limit how much of the string
345
+ // it uses in the comparison.
346
+ memcpy (& current_specifier , format_pos , 2 );
347
+ if (!strstr (target_format , current_specifier )) {
348
+ memcpy (target_format_pos , format_pos , 2 );
349
+ }
350
+
351
+ ++ format_pos ; // Enough to move to the next match.
352
+ target_format_pos += 2 ; // This needs to go to the next slot.
353
+ }
354
+ }
355
+
331
356
// Given a config and a style in which to store the information, this will
332
357
// calculate a style that has the maximum value of all the configured criteria
333
358
// styles (including the default as a base), for values where it makes sense to
@@ -398,51 +423,11 @@ bool apply_superset_style(
398
423
399
424
// We do need to be safe about these two though.
400
425
if (style -> spec .format ) {
401
- char * format_pos = style -> format ;
402
- char current_specifier [3 ] = {0 };
403
- while (* format_pos ) {
404
- format_pos = strstr (format_pos , "%" );
405
- if (!format_pos ) {
406
- break ;
407
- }
408
-
409
- // We only want to add the format specifier to the target if we
410
- // haven't already seen it.
411
- // Need to copy the specifier into its own string to use strstr
412
- // here, because there's no way to limit how much of the string
413
- // it uses in the comparison.
414
- memcpy (& current_specifier , format_pos , 2 );
415
- if (!strstr (target -> format , current_specifier )) {
416
- memcpy (target_format_pos , format_pos , 2 );
417
- }
418
-
419
- ++ format_pos ; // Enough to move to the next match.
420
- target_format_pos += 2 ; // This needs to go to the next slot.
421
- }
426
+ find_unique_specifiers (style -> format , target -> format , target_format_pos );
422
427
}
423
428
424
429
if (style -> spec .title_format ) {
425
- char * format_pos = style -> title_format ;
426
- char current_specifier [3 ] = {0 };
427
- while (* format_pos ) {
428
- format_pos = strstr (format_pos , "%" );
429
- if (!format_pos ) {
430
- break ;
431
- }
432
-
433
- // We only want to add the format specifier to the target if we
434
- // haven't already seen it.
435
- // Need to copy the specifier into its own string to use strstr
436
- // here, because there's no way to limit how much of the string
437
- // it uses in the comparison.
438
- memcpy (& current_specifier , format_pos , 2 );
439
- if (!strstr (target -> title_format , current_specifier )) {
440
- memcpy (target_format_pos_title , format_pos , 2 );
441
- }
442
-
443
- ++ format_pos ; // Enough to move to the next match.
444
- target_format_pos_title += 2 ; // This needs to go to the next slot.
445
- }
430
+ find_unique_specifiers (style -> title_format , target -> format , target_format_pos_title );
446
431
}
447
432
}
448
433
0 commit comments