Skip to content

Commit

Permalink
all: prepare for Unicode 15.0.0
Browse files Browse the repository at this point in the history
internal/gen has never been updated for Go 1.17's //go:build tags.
Do that, and add the entry for Unicode 15.0.0.

Unicode 15.0.0 will change 9fff to be a CJK ideograph, which will
break the unicode/runenames example test.
Delete that part of the example.

For golang/go#55079.

Change-Id: I12b0c6d031d6d6e1970c8fe6eb5453fa64c9f365
Reviewed-on: https://go-review.googlesource.com/c/text/+/503035
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
  • Loading branch information
rsc authored and gopherbot committed Jun 13, 2023
1 parent 3a7a255 commit e3c038a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 12 additions & 4 deletions internal/gen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ var tags = []struct{ version, buildTags string }{
{"10.0.0", "go1.10,!go1.13"},
{"11.0.0", "go1.13,!go1.14"},
{"12.0.0", "go1.14,!go1.16"},
{"13.0.0", "go1.16"},
{"13.0.0", "go1.16,!go1.21"},
{"15.0.0", "go1.21"},
}

// buildTags reports the build tags used for the current Unicode version.
Expand Down Expand Up @@ -276,15 +277,21 @@ func fileToPattern(filename string) string {
return fmt.Sprint(prefix, "%s", suffix)
}

// tagLines returns the //go:build and // +build lines to add to the file.
func tagLines(tags string) string {
newTags := strings.ReplaceAll(tags, ",", " && ")
return "//go:build " + newTags + "\n" +
"// +build " + tags + "\n"
}

func updateBuildTags(pattern string) {
for _, t := range tags {
oldFile := fmt.Sprintf(pattern, t.version)
b, err := os.ReadFile(oldFile)
if err != nil {
continue
}
build := fmt.Sprintf("// +build %s", t.buildTags)
b = regexp.MustCompile(`// \+build .*`).ReplaceAll(b, []byte(build))
b = regexp.MustCompile(`((//go:build|// \+build).*\n)+`).ReplaceAll(b, []byte(tagLines(t.buildTags)))
err = os.WriteFile(oldFile, b, 0644)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -316,7 +323,8 @@ func WriteVersionedGoFile(filename, pkg string, b []byte) {
func WriteGo(w io.Writer, pkg, tags string, b []byte) (n int, err error) {
src := []byte(header)
if tags != "" {
src = append(src, fmt.Sprintf("// +build %s\n\n", tags)...)
src = append(src, tagLines(tags)...)
src = append(src, '\n')
}
src = append(src, fmt.Sprintf("package %s\n\n", pkg)...)
src = append(src, b...)
Expand Down
2 changes: 0 additions & 2 deletions unicode/runenames/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func Example() {
'\U00004dc0',

'\U00009fd5',
'\U00009fff',
'\U0000a000',
0xdc00, // '\U0000dc00' (Low Surrogate) is an invalid Go literal.
'\U0000f800',
Expand Down Expand Up @@ -94,7 +93,6 @@ func Example() {
// 00003402 "<CJK Ideograph Extension A>"
// 00004dc0 "HEXAGRAM FOR THE CREATIVE HEAVEN"
// 00009fd5 "<CJK Ideograph>"
// 00009fff ""
// 0000a000 "YI SYLLABLE IT"
// 0000dc00 "<Low Surrogate>"
// 0000f800 "<Private Use>"
Expand Down

0 comments on commit e3c038a

Please sign in to comment.