Skip to content

Commit e3c038a

Browse files
rscgopherbot
authored andcommitted
all: prepare for Unicode 15.0.0
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 <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]> Auto-Submit: Russ Cox <[email protected]>
1 parent 3a7a255 commit e3c038a

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

internal/gen/gen.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ var tags = []struct{ version, buildTags string }{
8787
{"10.0.0", "go1.10,!go1.13"},
8888
{"11.0.0", "go1.13,!go1.14"},
8989
{"12.0.0", "go1.14,!go1.16"},
90-
{"13.0.0", "go1.16"},
90+
{"13.0.0", "go1.16,!go1.21"},
91+
{"15.0.0", "go1.21"},
9192
}
9293

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

280+
// tagLines returns the //go:build and // +build lines to add to the file.
281+
func tagLines(tags string) string {
282+
newTags := strings.ReplaceAll(tags, ",", " && ")
283+
return "//go:build " + newTags + "\n" +
284+
"// +build " + tags + "\n"
285+
}
286+
279287
func updateBuildTags(pattern string) {
280288
for _, t := range tags {
281289
oldFile := fmt.Sprintf(pattern, t.version)
282290
b, err := os.ReadFile(oldFile)
283291
if err != nil {
284292
continue
285293
}
286-
build := fmt.Sprintf("// +build %s", t.buildTags)
287-
b = regexp.MustCompile(`// \+build .*`).ReplaceAll(b, []byte(build))
294+
b = regexp.MustCompile(`((//go:build|// \+build).*\n)+`).ReplaceAll(b, []byte(tagLines(t.buildTags)))
288295
err = os.WriteFile(oldFile, b, 0644)
289296
if err != nil {
290297
log.Fatal(err)
@@ -316,7 +323,8 @@ func WriteVersionedGoFile(filename, pkg string, b []byte) {
316323
func WriteGo(w io.Writer, pkg, tags string, b []byte) (n int, err error) {
317324
src := []byte(header)
318325
if tags != "" {
319-
src = append(src, fmt.Sprintf("// +build %s\n\n", tags)...)
326+
src = append(src, tagLines(tags)...)
327+
src = append(src, '\n')
320328
}
321329
src = append(src, fmt.Sprintf("package %s\n\n", pkg)...)
322330
src = append(src, b...)

unicode/runenames/example_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func Example() {
4141
'\U00004dc0',
4242

4343
'\U00009fd5',
44-
'\U00009fff',
4544
'\U0000a000',
4645
0xdc00, // '\U0000dc00' (Low Surrogate) is an invalid Go literal.
4746
'\U0000f800',
@@ -94,7 +93,6 @@ func Example() {
9493
// 00003402 "<CJK Ideograph Extension A>"
9594
// 00004dc0 "HEXAGRAM FOR THE CREATIVE HEAVEN"
9695
// 00009fd5 "<CJK Ideograph>"
97-
// 00009fff ""
9896
// 0000a000 "YI SYLLABLE IT"
9997
// 0000dc00 "<Low Surrogate>"
10098
// 0000f800 "<Private Use>"

0 commit comments

Comments
 (0)