33import static java .lang .String .valueOf ;
44
55import java .util .ArrayList ;
6+ import java .util .HashMap ;
67import java .util .List ;
8+ import java .util .Map ;
79import java .util .regex .Matcher ;
810import java .util .regex .Pattern ;
911
@@ -18,6 +20,16 @@ public static class Builder {
1820 private StringBuilder suffixes = new StringBuilder ();
1921 private int modifiers = Pattern .MULTILINE ;
2022
23+ private static final Map <Character , Integer > SYMBOL_MAP = new HashMap <Character , Integer >() {{
24+ put ('d' , Pattern .UNIX_LINES );
25+ put ('i' , Pattern .CASE_INSENSITIVE );
26+ put ('x' , Pattern .COMMENTS );
27+ put ('m' , Pattern .MULTILINE );
28+ put ('s' , Pattern .DOTALL );
29+ put ('u' , Pattern .UNICODE_CASE );
30+ put ('U' , Pattern .UNICODE_CHARACTER_CLASS );
31+ }};
32+
2133 /**
2234 * Package private. Use {@link #regex()} to build a new one
2335 *
@@ -172,7 +184,7 @@ public Builder find(final String value) {
172184 public Builder maybe (final String pValue ) {
173185 return this .then (pValue ).add ("?" );
174186 }
175-
187+
176188 /**
177189 * Add a regex to the expression that might appear once (or not)
178190 * Example:
@@ -367,60 +379,16 @@ public Builder range(final String... pArgs) {
367379 }
368380
369381 public Builder addModifier (final char pModifier ) {
370- switch (pModifier ) {
371- case 'd' :
372- modifiers |= Pattern .UNIX_LINES ;
373- break ;
374- case 'i' :
375- modifiers |= Pattern .CASE_INSENSITIVE ;
376- break ;
377- case 'x' :
378- modifiers |= Pattern .COMMENTS ;
379- break ;
380- case 'm' :
381- modifiers |= Pattern .MULTILINE ;
382- break ;
383- case 's' :
384- modifiers |= Pattern .DOTALL ;
385- break ;
386- case 'u' :
387- modifiers |= Pattern .UNICODE_CASE ;
388- break ;
389- case 'U' :
390- modifiers |= Pattern .UNICODE_CHARACTER_CLASS ;
391- break ;
392- default :
393- break ;
382+ if (SYMBOL_MAP .containsKey (pModifier )) {
383+ modifiers |= SYMBOL_MAP .get (pModifier );
394384 }
395385
396386 return this ;
397387 }
398388
399389 public Builder removeModifier (final char pModifier ) {
400- switch (pModifier ) {
401- case 'd' :
402- modifiers &= ~Pattern .UNIX_LINES ;
403- break ;
404- case 'i' :
405- modifiers &= ~Pattern .CASE_INSENSITIVE ;
406- break ;
407- case 'x' :
408- modifiers &= ~Pattern .COMMENTS ;
409- break ;
410- case 'm' :
411- modifiers &= ~Pattern .MULTILINE ;
412- break ;
413- case 's' :
414- modifiers &= ~Pattern .DOTALL ;
415- break ;
416- case 'u' :
417- modifiers &= ~Pattern .UNICODE_CASE ;
418- break ;
419- case 'U' :
420- modifiers &= ~Pattern .UNICODE_CHARACTER_CLASS ;
421- break ;
422- default :
423- break ;
390+ if (SYMBOL_MAP .containsKey (pModifier )) {
391+ modifiers &= ~SYMBOL_MAP .get (pModifier );
424392 }
425393
426394 return this ;
@@ -578,7 +546,7 @@ public Builder or(final String pValue) {
578546 }
579547 return this ;
580548 }
581-
549+
582550 /**
583551 * Adds an alternative expression to be matched
584552 * based on an array of values
@@ -750,7 +718,7 @@ public String getText(final String toTest, final int group) {
750718
751719 /**
752720 * Extract exact group from string and add it to list
753- *
721+ *
754722 * Example:
755723 * String text = "SampleHelloWorldString";
756724 * VerbalExpression regex = regex().capt().oneOf("Hello", "World").endCapt().maybe("String").build();
0 commit comments