Skip to content

Commit

Permalink
update revive patch
Browse files Browse the repository at this point in the history
Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
  • Loading branch information
hawkingrei committed Oct 8, 2022
1 parent 771ff00 commit 80a3c4a
Showing 1 changed file with 82 additions and 65 deletions.
147 changes: 82 additions & 65 deletions build/patches/com_github_rivo_uniseg.patch
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
From 5097c14ae5e40af636fc3bd353edd64ca1f91713 Mon Sep 17 00:00:00 2001
From 1492043a155839cb863210d4f564be3fa640c0d9 Mon Sep 17 00:00:00 2001
From: Weizhen Wang <wangweizhen@pingcap.com>
Date: Mon, 29 Aug 2022 18:15:12 +0800
Subject: [PATCH] *: update dep
Date: Sat, 8 Oct 2022 11:41:06 +0800
Subject: [PATCH] update

Signed-off-by: Weizhen Wang <wangweizhen@pingcap.com>
---
BUILD.bazel | 26 +++++
BUILD.bazel | 27 +++++
WORKSPACE | 2 +
gen_breaktest.go | 213 ----------------------------------------
gen_properties.go | 240 ----------------------------------------------
4 files changed, 28 insertions(+), 453 deletions(-)
gen_breaktest.go | 213 --------------------------------------
gen_properties.go | 256 ----------------------------------------------
4 files changed, 29 insertions(+), 469 deletions(-)
create mode 100644 BUILD.bazel
create mode 100644 WORKSPACE
delete mode 100644 gen_breaktest.go
delete mode 100644 gen_properties.go

diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..c6423e8
index 0000000..a1e5c89
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,26 @@
@@ -0,0 +1,27 @@
+load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+
+go_library(
+ name = "uniseg",
+ srcs = [
+ "doc.go",
+ "eastasianwidth.go",
+ "emojipresentation.go",
+ "grapheme.go",
+ "graphemeproperties.go",
+ "graphemerules.go",
Expand All @@ -39,14 +40,14 @@ index 0000000..c6423e8
+ "sentenceproperties.go",
+ "sentencerules.go",
+ "step.go",
+ "width.go",
+ "word.go",
+ "wordproperties.go",
+ "wordrules.go",
+ ],
+ importpath = "github.com/rivo/uniseg",
+ visibility = ["//visibility:public"],
+)
+
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..d596273
Expand Down Expand Up @@ -276,28 +277,31 @@ index e613c4c..0000000
-}
diff --git a/gen_properties.go b/gen_properties.go
deleted file mode 100644
index 6451270..0000000
index 999d5ef..0000000
--- a/gen_properties.go
+++ /dev/null
@@ -1,240 +0,0 @@
@@ -1,256 +0,0 @@
-//go:build generate
-
-// This program generates a property file in Go file from Unicode Character
-// Database auxiliary data files. The command line arguments are as follows:
-//
-// 1. The name of the Unicode data file (just the filename, without extension).
-// 2. The name of the locally generated Go file.
-// 3. The name of the slice mapping code points to properties.
-// 4. The name of the generator, for logging purposes.
-// 5. (Optional) Flags, comma-separated. The following flags are available:
-// - "emojis": include emoji properties (Extended Pictographic only).
-// - "gencat": include general category properties.
-// 1. The name of the Unicode data file (just the filename, without extension).
-// Can be "-" (to skip) if the emoji flag is included.
-// 2. The name of the locally generated Go file.
-// 3. The name of the slice mapping code points to properties.
-// 4. The name of the generator, for logging purposes.
-// 5. (Optional) Flags, comma-separated. The following flags are available:
-// - "emojis=<property>": include the specified emoji properties (e.g.
-// "Extended_Pictographic").
-// - "gencat": include general category properties.
-//
-//go:generate go run gen_properties.go auxiliary/GraphemeBreakProperty graphemeproperties.go graphemeCodePoints graphemes emojis
-//go:generate go run gen_properties.go auxiliary/WordBreakProperty wordproperties.go workBreakCodePoints words emojis
-//go:generate go run gen_properties.go auxiliary/GraphemeBreakProperty graphemeproperties.go graphemeCodePoints graphemes emojis=Extended_Pictographic
-//go:generate go run gen_properties.go auxiliary/WordBreakProperty wordproperties.go workBreakCodePoints words emojis=Extended_Pictographic
-//go:generate go run gen_properties.go auxiliary/SentenceBreakProperty sentenceproperties.go sentenceBreakCodePoints sentences
-//go:generate go run gen_properties.go LineBreak lineproperties.go lineBreakCodePoints lines gencat
-//go:generate go run gen_properties.go EastAsianWidth eastasianwidth.go eastAsianWidth eastasianwidth
-//go:generate go run gen_properties.go - emojipresentation.go emojiPresentation emojipresentation emojis=Emoji_Presentation
-package main
-
-import (
Expand All @@ -320,8 +324,8 @@ index 6451270..0000000
-// We want to test against a specific version rather than the latest. When the
-// package is upgraded to a new version, change these to generate new tests.
-const (
- gbpURL = `https://www.unicode.org/Public/14.0.0/ucd/%s.txt`
- emojiURL = `https://unicode.org/Public/14.0.0/ucd/emoji/emoji-data.txt`
- propertyURL = `https://www.unicode.org/Public/14.0.0/ucd/%s.txt`
- emojiURL = `https://unicode.org/Public/14.0.0/ucd/emoji/emoji-data.txt`
-)
-
-// The regular expression for a line containing a code point range property.
Expand All @@ -337,20 +341,25 @@ index 6451270..0000000
- log.SetFlags(0)
-
- // Parse flags.
- flags := make(map[string]struct{})
- flags := make(map[string]string)
- if len(os.Args) >= 6 {
- for _, flag := range strings.Split(os.Args[5], ",") {
- flags[flag] = struct{}{}
- flagFields := strings.Split(flag, "=")
- if len(flagFields) == 1 {
- flags[flagFields[0]] = "yes"
- } else {
- flags[flagFields[0]] = flagFields[1]
- }
- }
- }
-
- // Parse the text file and generate Go source code from it.
- var emojis string
- if _, ok := flags["emojis"]; ok {
- emojis = emojiURL
- }
- _, includeGeneralCategory := flags["gencat"]
- src, err := parse(fmt.Sprintf(gbpURL, os.Args[1]), emojis, includeGeneralCategory)
- var mainURL string
- if os.Args[1] != "-" {
- mainURL = fmt.Sprintf(propertyURL, os.Args[1])
- }
- src, err := parse(mainURL, flags["emojis"], includeGeneralCategory)
- if err != nil {
- log.Fatal(err)
- }
Expand All @@ -370,65 +379,73 @@ index 6451270..0000000
-
-// parse parses the Unicode Properties text files located at the given URLs and
-// returns their equivalent Go source code to be used in the uniseg package. If
-// "emojiURL" is an empty string, no emoji code points will be included. If
-// "emojiProperty" is not an empty string, emoji code points for that emoji
-// property (e.g. "Extended_Pictographic") will be included. In those cases, you
-// may pass an empty "propertyURL" to skip parsing the main properties file. If
-// "includeGeneralCategory" is true, the Unicode General Category property will
-// be extracted from the comments and included in the output.
-func parse(gbpURL, emojiURL string, includeGeneralCategory bool) (string, error) {
-func parse(propertyURL, emojiProperty string, includeGeneralCategory bool) (string, error) {
- if propertyURL == "" && emojiProperty == "" {
- return "", errors.New("no properties to parse")
- }
-
- // Temporary buffer to hold properties.
- var properties [][4]string
-
- // Open the first URL.
- log.Printf("Parsing %s", gbpURL)
- res, err := http.Get(gbpURL)
- if err != nil {
- return "", err
- }
- in1 := res.Body
- defer in1.Close()
- if propertyURL != "" {
- log.Printf("Parsing %s", propertyURL)
- res, err := http.Get(propertyURL)
- if err != nil {
- return "", err
- }
- in1 := res.Body
- defer in1.Close()
-
- // Parse it.
- scanner := bufio.NewScanner(in1)
- num := 0
- for scanner.Scan() {
- num++
- line := strings.TrimSpace(scanner.Text())
- // Parse it.
- scanner := bufio.NewScanner(in1)
- num := 0
- for scanner.Scan() {
- num++
- line := strings.TrimSpace(scanner.Text())
-
- // Skip comments and empty lines.
- if strings.HasPrefix(line, "#") || line == "" {
- continue
- }
- // Skip comments and empty lines.
- if strings.HasPrefix(line, "#") || line == "" {
- continue
- }
-
- // Everything else must be a code point range, a property and a comment.
- from, to, property, comment, err := parseProperty(line)
- if err != nil {
- return "", fmt.Errorf("%s line %d: %v", os.Args[4], num, err)
- // Everything else must be a code point range, a property and a comment.
- from, to, property, comment, err := parseProperty(line)
- if err != nil {
- return "", fmt.Errorf("%s line %d: %v", os.Args[4], num, err)
- }
- properties = append(properties, [4]string{from, to, property, comment})
- }
- if err := scanner.Err(); err != nil {
- return "", err
- }
- properties = append(properties, [4]string{from, to, property, comment})
- }
- if err := scanner.Err(); err != nil {
- return "", err
- }
-
- // Open the second URL.
- if emojiURL != "" {
- if emojiProperty != "" {
- log.Printf("Parsing %s", emojiURL)
- res, err = http.Get(emojiURL)
- res, err := http.Get(emojiURL)
- if err != nil {
- return "", err
- }
- in2 := res.Body
- defer in2.Close()
-
- // Parse it.
- scanner = bufio.NewScanner(in2)
- num = 0
- scanner := bufio.NewScanner(in2)
- num := 0
- for scanner.Scan() {
- num++
- line := scanner.Text()
-
- // Skip comments, empty lines, and everything not containing
- // "Extended_Pictographic".
- if strings.HasPrefix(line, "#") || line == "" || !strings.Contains(line, "Extended_Pictographic") {
- if strings.HasPrefix(line, "#") || line == "" || !strings.Contains(line, emojiProperty) {
- continue
- }
-
Expand Down Expand Up @@ -471,7 +488,7 @@ index 6451270..0000000
-// Code generated via go generate from gen_properties.go. DO NOT EDIT.
-
-// ` + os.Args[3] + ` are taken from
-// ` + gbpURL + emojiComment + `
-// ` + propertyURL + emojiComment + `
-// on ` + time.Now().Format("January 2, 2006") + `. See https://www.unicode.org/license.html for the Unicode
-// license agreement.
-var ` + os.Args[3] + ` = [][` + strconv.Itoa(columns) + `]int{
Expand Down Expand Up @@ -520,6 +537,6 @@ index 6451270..0000000
-func translateProperty(prefix, property string) string {
- return prefix + strings.ReplaceAll(property, "_", "")
-}
--
2.37.2
--
2.38.0

0 comments on commit 80a3c4a

Please sign in to comment.