File: valid.go

package info (click to toggle)
golang-github-segmentio-asm 1.2.0%2Bgit20231107.1cfacc8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 932 kB
  • sloc: asm: 6,093; makefile: 32
file content (31 lines) | stat: -rw-r--r-- 488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package utf8

import (
	"unicode/utf8"

	"github.com/segmentio/asm/ascii"
)

type Validation byte

const (
	Invalid = 0
	UTF8    = 0b01
	ASCII   = 0b10 | UTF8
)

func (v Validation) IsASCII() bool { return (v & ASCII) == ASCII }

func (v Validation) IsUTF8() bool { return (v & UTF8) == UTF8 }

func (v Validation) IsInvalid() bool { return v == Invalid }

func validate(p []byte) Validation {
	if ascii.Valid(p) {
		return ASCII
	}
	if utf8.Valid(p) {
		return UTF8
	}
	return Invalid
}