Skip to content

Commit eaa962e

Browse files
committed
Merge pull request #39 from myjian/master
Ensure removeModifier method turns off the flags
2 parents 822907f + c2f9b59 commit eaa962e

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

src/main/java/ru/lanwen/verbalregex/VerbalExpression.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -397,25 +397,25 @@ public Builder addModifier(final char pModifier) {
397397
public Builder removeModifier(final char pModifier) {
398398
switch (pModifier) {
399399
case 'd':
400-
modifiers ^= Pattern.UNIX_LINES;
400+
modifiers &= ~Pattern.UNIX_LINES;
401401
break;
402402
case 'i':
403-
modifiers ^= Pattern.CASE_INSENSITIVE;
403+
modifiers &= ~Pattern.CASE_INSENSITIVE;
404404
break;
405405
case 'x':
406-
modifiers ^= Pattern.COMMENTS;
406+
modifiers &= ~Pattern.COMMENTS;
407407
break;
408408
case 'm':
409-
modifiers ^= Pattern.MULTILINE;
409+
modifiers &= ~Pattern.MULTILINE;
410410
break;
411411
case 's':
412-
modifiers ^= Pattern.DOTALL;
412+
modifiers &= ~Pattern.DOTALL;
413413
break;
414414
case 'u':
415-
modifiers ^= Pattern.UNICODE_CASE;
415+
modifiers &= ~Pattern.UNICODE_CASE;
416416
break;
417417
case 'U':
418-
modifiers ^= Pattern.UNICODE_CHARACTER_CLASS;
418+
modifiers &= ~Pattern.UNICODE_CHARACTER_CLASS;
419419
break;
420420
default:
421421
break;

src/test/java/ru/lanwen/verbalregex/BasicFunctionalityUnitTest.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public void testWithAnyCase() {
300300
}
301301

302302
@Test
303-
public void testWithAnyCaseIsFalse() {
303+
public void testWithAnyCaseTurnOnThenTurnOff() {
304304
VerbalExpression testRegex = regex()
305305
.withAnyCase()
306306
.startOfLine()
@@ -311,6 +311,17 @@ public void testWithAnyCaseIsFalse() {
311311
assertThat(testRegex, not(matchesTo("A")));
312312
}
313313

314+
@Test
315+
public void testWithAnyCaseIsFalse() {
316+
VerbalExpression testRegex = regex()
317+
.startOfLine()
318+
.then("a")
319+
.withAnyCase(false)
320+
.build();
321+
322+
assertThat(testRegex, not(matchesTo("A")));
323+
}
324+
314325
@Test
315326
public void testSearchOneLine() {
316327
VerbalExpression testRegex = regex()
@@ -595,4 +606,4 @@ public void shouldAddMaybeWithOneOfFromAnotherBuilder() {
595606
assertThat("Is a name without prefix", name, matchesTo("James"));
596607

597608
}
598-
}
609+
}

0 commit comments

Comments
 (0)