Skip to content

Commit cf8fd52

Browse files
committed
fix for scalar semantic cr-lf
1 parent 9aca045 commit cf8fd52

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Sources/_StringProcessing/StringExtras.swift

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,29 +97,32 @@ extension String {
9797

9898
case .horizontalWhitespace:
9999
switch asciiValue {
100-
case _space, _tab: return (next, true)
101-
default: return (next, false)
100+
case _space, _tab: return (next, true)
101+
default: return (next, false)
102102
}
103103

104104
case .verticalWhitespace, .newlineSequence:
105105
switch asciiValue {
106-
case _lineFeed, _carriageReturn, _lineTab, _formFeed:
106+
case _lineFeed, _carriageReturn, _lineTab, _formFeed:
107107
// Scalar semantics: For `\v`, only advance past the CR instead of CR-LF
108108
if isScalarSemantics && isCRLF && cc == .verticalWhitespace {
109109
return (utf8.index(before: next), true)
110110
}
111111
return (next, true)
112112

113-
default:
114-
return (next, false)
113+
default:
114+
return (next, false)
115115
}
116116

117117
case .whitespace:
118118
switch asciiValue {
119-
case _space, _tab, _lineFeed, _lineTab, _formFeed, _carriageReturn:
120-
return (next, true)
121-
default:
122-
return (next, false)
119+
case _space, _tab, _lineFeed, _lineTab, _formFeed, _carriageReturn:
120+
if isScalarSemantics && isCRLF {
121+
return (utf8.index(before: next), true)
122+
}
123+
return (next, true)
124+
default:
125+
return (next, false)
123126
}
124127

125128
case .word:

0 commit comments

Comments
 (0)