JSONEncodingDetector

public struct JSONEncodingDetector

Struct for attempting to detect the Unicode encoding used with the data supplied to the JSONParser

  • / The Unicode encodings looked for during detection

    See more

    Declaration

    Swift

    public enum Encoding
  • / The Unicode encodings supported by JSONParser.swift

    Declaration

    Swift

    public static let supportedEncodings: [Encoding] = [.utf8]
  • / Attempts to detect the Unicode encoding used for a given set of data. / / This function initially looks for a Byte Order Mark in the following form: / / Bytes | Encoding Form / ————–|—————- / 00 00 FE FF | UTF-32, big-endian / FF FE 00 00 | UTF-32, little-endian / FE FF | UTF-16, big-endian / FF FE | UTF-16, little-endian / EF BB BF | UTF-8 / / If a BOM is not found then we detect using the following approach described in / the JSON RFC http://www.ietf.org/rfc/rfc4627.txt: / / Since the first two characters of a JSON text will always be ASCII / characters [RFC0020], it is possible to determine whether an octet / stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking / at the pattern of nulls in the first four octets. / / 00 00 00 xx UTF-32BE / 00 xx 00 xx UTF-16BE / xx 00 00 00 UTF-32LE / xx 00 xx 00 UTF-16LE / xx xx xx xx UTF-8 / / - parameter header: The front Slice of data being read and evaluated. / - returns: A tuple containing the detected Unicode encoding and the lenght of the byte order mark.

    Declaration

    Swift

    static func detectEncoding(_ header: RandomAccessSlice<UnsafeBufferPointer<UInt8>>) -> ByteStreamPrefixInformation