@@ -181,6 +181,18 @@ extension Processor {
181181 currentPosition = idx
182182 return true
183183 }
184+
185+ // Advances in unicode scalar view
186+ mutating func consumeScalar( _ n: Distance ) -> Bool {
187+ guard let idx = input. unicodeScalars. index (
188+ currentPosition, offsetBy: n. rawValue, limitedBy: end
189+ ) else {
190+ signalFailure ( )
191+ return false
192+ }
193+ currentPosition = idx
194+ return true
195+ }
184196
185197 /// Continue matching at the specified index.
186198 ///
@@ -329,6 +341,26 @@ extension Processor {
329341 return true
330342 }
331343
344+ // Matches the next character if it is not a newline
345+ mutating func matchAnyNonNewline( ) -> Bool {
346+ guard let c = load ( ) , !c. isNewline else {
347+ signalFailure ( )
348+ return false
349+ }
350+ _uncheckedForcedConsumeOne ( )
351+ return true
352+ }
353+
354+ // Matches the next scalar if it is not a newline
355+ mutating func matchAnyNonNewlineScalar( ) -> Bool {
356+ guard let s = loadScalar ( ) , !s. isNewline else {
357+ signalFailure ( )
358+ return false
359+ }
360+ input. unicodeScalars. formIndex ( after: & currentPosition)
361+ return true
362+ }
363+
332364 mutating func signalFailure( ) {
333365 guard !savePoints. isEmpty else {
334366 state = . fail
@@ -477,10 +509,26 @@ extension Processor {
477509 signalFailure ( )
478510
479511 case . advance:
480- if consume ( payload. distance) {
481- controller. step ( )
512+ let ( isScalar, distance) = payload. distance
513+ if isScalar {
514+ if consumeScalar ( distance) {
515+ controller. step ( )
516+ }
517+ } else {
518+ if consume ( distance) {
519+ controller. step ( )
520+ }
521+ }
522+ case . matchAnyNonNewline:
523+ if payload. isScalar {
524+ if matchAnyNonNewlineScalar ( ) {
525+ controller. step ( )
526+ }
527+ } else {
528+ if matchAnyNonNewline ( ) {
529+ controller. step ( )
530+ }
482531 }
483-
484532 case . match:
485533 let ( isCaseInsensitive, reg) = payload. elementPayload
486534 if isCaseInsensitive {
0 commit comments