@@ -584,32 +584,8 @@ public static boolean isADateFormatUncached(Short formatIndex, String formatStri
584584 if (StringUtils .isEmpty (formatString )) {
585585 return false ;
586586 }
587- String fs = formatString ;
588- final int length = fs .length ();
589- StringBuilder sb = new StringBuilder (length );
590- for (int i = 0 ; i < length ; i ++) {
591- char c = fs .charAt (i );
592- if (i < length - 1 ) {
593- char nc = fs .charAt (i + 1 );
594- if (c == '\\' ) {
595- switch (nc ) {
596- case '-' :
597- case ',' :
598- case '.' :
599- case ' ' :
600- case '\\' :
601- // skip current '\' and continue to the next char
602- continue ;
603- }
604- } else if (c == ';' && nc == '@' ) {
605- i ++;
606- // skip ";@" duplets
607- continue ;
608- }
609- }
610- sb .append (c );
611- }
612- fs = sb .toString ();
587+
588+ String fs = sanitizeString (formatString );
613589
614590 // short-circuit if it indicates elapsed time: [h], [m] or [s]
615591 if (date_ptrn4 .matcher (fs ).matches ()) {
@@ -649,6 +625,30 @@ public static boolean isADateFormatUncached(Short formatIndex, String formatStri
649625 return result ;
650626 }
651627
628+ private static String sanitizeString (String fs ) {
629+ final int length = fs .length ();
630+ StringBuilder sb = new StringBuilder (length );
631+ for (int i = 0 ; i < length ; i ++) {
632+ char c = fs .charAt (i );
633+ if (i < length - 1 ) {
634+ char nc = fs .charAt (i + 1 );
635+ if (c == '\\' && isEscapableChar (nc )) {
636+ continue ;
637+ } else if (c == ';' && nc == '@' ) {
638+ i ++;
639+ // skip ";@" duplets
640+ continue ;
641+ }
642+ }
643+ sb .append (c );
644+ }
645+ return sb .toString ();
646+ }
647+
648+ private static boolean isEscapableChar (char c ) {
649+ return c == '-' || c == ',' || c == '.' || c == ' ' || c == '\\' ;
650+ }
651+
652652 /**
653653 * Given a format ID this will check whether the format represents an internal excel date format or not.
654654 *
0 commit comments