Debian Codegraph @

internal/export/idna/gen_common.go

raw
1 // Copyright 2016 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 //go:build ignore
6
7 package main
8
9 // This file contains code that is common between the generation code and the
10 // package's test code.
11
12 import (
13 "log"
14
15 "golang.org/x/text/internal/ucd"
16 )
17
18 func catFromEntry(p *ucd.Parser) (cat category) {
19 // Note: As of Unicode 16, IdnaMappingTable.txt no longer includes
20 // disallowed_STD3_valid and disallowed_STD3_mapped.
21 // It is up to us to bring them back with our definition of disallowedSTD3,
22 // which is exactly the runes from Unicode 15.
23 r := p.Rune(0)
24 idna2008status := p.String(3)
25 switch s := p.String(1); s {
26 case "valid":
27 cat = valid
28 case "disallowed":
29 cat = disallowed
30 case "disallowed_STD3_valid":
31 cat = disallowedSTD3Valid
32 case "disallowed_STD3_mapped":
33 cat = disallowedSTD3Mapped
34 case "mapped":
35 cat = mapped
36 case "deviation":
37 cat = deviation
38 case "ignored":
39 cat = ignored
40 default:
41 log.Fatalf("%U: Unknown category %q", r, s)
42 }
43 if s := idna2008status; s != "" {
44 if cat != valid {
45 log.Fatalf(`%U: %s defined for %q/%v; want "valid"`, r, s, p.String(1), cat)
46 }
47 switch s {
48 case "NV8":
49 cat = validNV8
50 case "XV8":
51 cat = validXV8
52 default:
53 log.Fatalf("%U: Unexpected exception %q", r, s)
54 }
55 }
56 return cat
57 }
58
59 var joinType = map[string]info{
60 "L": joiningL,
61 "D": joiningD,
62 "T": joiningT,
63 "R": joiningR,
64 }