Skip to content

Commit 5ca7bd3

Browse files
authored
Merge pull request #313 from seraku24/seraku24-fix-end-of-string-detection
LineCheckBase: Fix end-of-string detection.
2 parents 60dee9c + a1f778b commit 5ca7bd3

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/checkstyle/checks/whitespace/LineCheckBase.hx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class LineCheckBase extends Check {
1818
commentStartRE = ~/\/([\/*])/;
1919
commentBlockEndRE = ~/\*\//;
2020
stringStartRE = ~/['"]/;
21-
stringInterpolatedEndRE = ~/(?<!\\)'/;
22-
stringLiteralEndRE = ~/(?<!\\)"/;
21+
stringInterpolatedEndRE = ~/^(?:[^'\\]|\\\S)*'/;
22+
stringLiteralEndRE = ~/^(?:[^"\\]|\\\S)*"/;
2323
}
2424

2525
override public function run(checker:Checker):Array<CheckMessage> {
@@ -90,16 +90,11 @@ class LineCheckBase extends Check {
9090

9191
function handleStringState(line:String, ranges:Array<Range>, currentStart:Int, isInterpolated:Bool):Int {
9292
var adjustedStart = currentStart + (skipOverInitialQuote ? 1 : 0);
93-
skipOverInitialQuote = false;
94-
if (isInterpolated && stringInterpolatedEndRE.matchSub(line, adjustedStart)) {
95-
var stringEnd = stringInterpolatedEndRE.matchedPos().pos + 1;
96-
ranges.push({ type: currentState, start: currentStart, end: stringEnd });
97-
98-
currentState = TEXT;
99-
return stringEnd;
100-
}
101-
else if (!isInterpolated && stringLiteralEndRE.matchSub(line, adjustedStart)) {
102-
var stringEnd = stringLiteralEndRE.matchedPos().pos + 1;
93+
skipOverInitialQuote = false;
94+
var re = isInterpolated ? stringInterpolatedEndRE : stringLiteralEndRE;
95+
if (re.match(line.substring(adjustedStart))) {
96+
var matchedPos = re.matchedPos();
97+
var stringEnd = adjustedStart + matchedPos.pos + matchedPos.len;
10398
ranges.push({ type: currentState, start: currentStart, end: stringEnd });
10499

105100
currentState = TEXT;

test/checks/whitespace/EmptyLinesCheckTest.hx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ abstract EmptyLinesCheckTests(String) to String {
7575
7676
var a:Int;
7777
78+
var b:String = '\\\\' + \"\\\\\";
79+
7880
7981
}";
8082

0 commit comments

Comments
 (0)