@@ -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 ///
@@ -321,6 +333,26 @@ extension Processor {
321333 return true
322334 }
323335
336+ // Matches the next character if it is not a newline
337+ mutating func matchAnyNonNewline( ) -> Bool {
338+ guard let c = load ( ) , !c. isNewline else {
339+ signalFailure ( )
340+ return false
341+ }
342+ _uncheckedForcedConsumeOne ( )
343+ return true
344+ }
345+
346+ // Matches the next scalar if it is not a newline
347+ mutating func matchAnyNonNewlineScalar( ) -> Bool {
348+ guard let s = loadScalar ( ) , !s. isNewline else {
349+ signalFailure ( )
350+ return false
351+ }
352+ input. unicodeScalars. formIndex ( after: & currentPosition)
353+ return true
354+ }
355+
324356 mutating func signalFailure( ) {
325357 guard !savePoints. isEmpty else {
326358 state = . fail
@@ -469,10 +501,26 @@ extension Processor {
469501 signalFailure ( )
470502
471503 case . advance:
472- if consume ( payload. distance) {
473- controller. step ( )
504+ let ( isScalar, distance) = payload. distance
505+ if isScalar {
506+ if consumeScalar ( distance) {
507+ controller. step ( )
508+ }
509+ } else {
510+ if consume ( distance) {
511+ controller. step ( )
512+ }
513+ }
514+ case . matchAnyNonNewline:
515+ if payload. isScalar {
516+ if matchAnyNonNewlineScalar ( ) {
517+ controller. step ( )
518+ }
519+ } else {
520+ if matchAnyNonNewline ( ) {
521+ controller. step ( )
522+ }
474523 }
475-
476524 case . match:
477525 let ( isCaseInsensitive, reg) = payload. elementPayload
478526 if isCaseInsensitive {
0 commit comments