Path: blob/main/vendor/golang.org/x/text/internal/utf8internal/utf8internal.go
2893 views
// Copyright 2015 The Go Authors. All rights reserved.1// Use of this source code is governed by a BSD-style2// license that can be found in the LICENSE file.34// Package utf8internal contains low-level utf8-related constants, tables, etc.5// that are used internally by the text package.6package utf8internal78// The default lowest and highest continuation byte.9const (10LoCB = 0x80 // 1000 000011HiCB = 0xBF // 1011 111112)1314// Constants related to getting information of first bytes of UTF-8 sequences.15const (16// ASCII identifies a UTF-8 byte as ASCII.17ASCII = as1819// FirstInvalid indicates a byte is invalid as a first byte of a UTF-820// sequence.21FirstInvalid = xx2223// SizeMask is a mask for the size bits. Use use x&SizeMask to get the size.24SizeMask = 72526// AcceptShift is the right-shift count for the first byte info byte to get27// the index into the AcceptRanges table. See AcceptRanges.28AcceptShift = 42930// The names of these constants are chosen to give nice alignment in the31// table below. The first nibble is an index into acceptRanges or F for32// special one-byte cases. The second nibble is the Rune length or the33// Status for the special one-byte case.34xx = 0xF1 // invalid: size 135as = 0xF0 // ASCII: size 136s1 = 0x02 // accept 0, size 237s2 = 0x13 // accept 1, size 338s3 = 0x03 // accept 0, size 339s4 = 0x23 // accept 2, size 340s5 = 0x34 // accept 3, size 441s6 = 0x04 // accept 0, size 442s7 = 0x44 // accept 4, size 443)4445// First is information about the first byte in a UTF-8 sequence.46var First = [256]uint8{47// 1 2 3 4 5 6 7 8 9 A B C D E F48as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x00-0x0F49as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x10-0x1F50as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x20-0x2F51as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x30-0x3F52as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x40-0x4F53as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x50-0x5F54as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x60-0x6F55as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, as, // 0x70-0x7F56// 1 2 3 4 5 6 7 8 9 A B C D E F57xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x80-0x8F58xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0x90-0x9F59xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xA0-0xAF60xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xB0-0xBF61xx, xx, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xC0-0xCF62s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, s1, // 0xD0-0xDF63s2, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s3, s4, s3, s3, // 0xE0-0xEF64s5, s6, s6, s6, s7, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, xx, // 0xF0-0xFF65}6667// AcceptRange gives the range of valid values for the second byte in a UTF-868// sequence for any value for First that is not ASCII or FirstInvalid.69type AcceptRange struct {70Lo uint8 // lowest value for second byte.71Hi uint8 // highest value for second byte.72}7374// AcceptRanges is a slice of AcceptRange values. For a given byte sequence b75//76// AcceptRanges[First[b[0]]>>AcceptShift]77//78// will give the value of AcceptRange for the multi-byte UTF-8 sequence starting79// at b[0].80var AcceptRanges = [...]AcceptRange{810: {LoCB, HiCB},821: {0xA0, HiCB},832: {LoCB, 0x9F},843: {0x90, HiCB},854: {LoCB, 0x8F},86}878889