@@ -54,8 +54,10 @@ private let asciiUpperE = UInt8(ascii: "E")
5454private let asciiLowerF = UInt8 ( ascii: " f " )
5555private let asciiUpperF = UInt8 ( ascii: " F " )
5656private let asciiLowerI = UInt8 ( ascii: " i " )
57+ private let asciiLowerL = UInt8 ( ascii: " l " )
5758private let asciiLowerN = UInt8 ( ascii: " n " )
5859private let asciiLowerR = UInt8 ( ascii: " r " )
60+ private let asciiLowerS = UInt8 ( ascii: " s " )
5961private let asciiLowerT = UInt8 ( ascii: " t " )
6062private let asciiUpperT = UInt8 ( ascii: " T " )
6163private let asciiLowerU = UInt8 ( ascii: " u " )
@@ -720,6 +722,20 @@ internal struct TextFormatScanner {
720722 return d
721723 }
722724
725+ // Skip specified characters if they all match
726+ private mutating func skipOptionalCharacters( bytes: [ UInt8 ] ) {
727+ let start = p
728+ for b in bytes {
729+ if p == end || p [ 0 ] != b {
730+ p = start
731+ return
732+ }
733+ p += 1
734+ }
735+ }
736+
737+ // Skip following keyword if it matches (case-insensitively)
738+ // the given keyword (specified as a series of bytes).
723739 private mutating func skipOptionalKeyword( bytes: [ UInt8 ] ) -> Bool {
724740 let start = p
725741 for b in bytes {
@@ -817,20 +833,47 @@ internal struct TextFormatScanner {
817833 throw TextFormatDecodingError . malformedText
818834 }
819835 let c = p [ 0 ]
836+ p += 1
837+ let result : Bool
820838 switch c {
821- case asciiZero, asciiOne, asciiLowerF, asciiUpperF, asciiLowerT, asciiUpperT:
822- switch parseIdentifier ( ) {
823- case " 0 " , " f " , " false " , " False " :
824- return false
825- case " 1 " , " t " , " true " , " True " :
826- return true
827- default :
828- break
839+ case asciiZero:
840+ result = false
841+ case asciiOne:
842+ result = true
843+ case asciiLowerF, asciiUpperF:
844+ if p != end {
845+ let alse = [ asciiLowerA, asciiLowerL, asciiLowerS, asciiLowerE]
846+ skipOptionalCharacters ( bytes: alse)
847+ }
848+ result = false
849+ case asciiLowerT, asciiUpperT:
850+ if p != end {
851+ let rue = [ asciiLowerR, asciiLowerU, asciiLowerE]
852+ skipOptionalCharacters ( bytes: rue)
829853 }
854+ result = true
830855 default :
831- break
856+ throw TextFormatDecodingError . malformedText
857+ }
858+ if p == end {
859+ return result
860+ }
861+ switch p [ 0 ] {
862+ case asciiSpace,
863+ asciiTab,
864+ asciiNewLine,
865+ asciiCarriageReturn,
866+ asciiHash,
867+ asciiComma,
868+ asciiSemicolon,
869+ asciiCloseSquareBracket,
870+ asciiCloseCurlyBracket,
871+ asciiCloseAngleBracket:
872+ skipWhitespace ( )
873+ return result
874+ default :
875+ throw TextFormatDecodingError . malformedText
832876 }
833- throw TextFormatDecodingError . malformedText
834877 }
835878
836879 internal mutating func nextOptionalEnumName( ) throws -> UnsafeBufferPointer < UInt8 > ? {
0 commit comments