| 1 |
From: Mathias Gibbens <[email protected]> |
| 2 |
Description: Adjust import paths and expected Unicode data file locations so codegen works properly during a Debian package build. |
| 3 |
Forwarded: not-needed |
| 4 |
diff --git a/internal/gen/triegen/triegen.go b/internal/gen/triegen/triegen.go |
| 5 |
index e87b3d5..964f80c 100644 |
| 6 |
--- a/internal/gen/triegen/triegen.go |
| 7 |
+++ b/internal/gen/triegen/triegen.go |
| 8 |
@@ -56,7 +56,7 @@ |
| 9 |
// It is recommended that users test the generated trie by checking the returned |
| 10 |
// value for every rune. Such exhaustive tests are possible as the number of |
| 11 |
// runes in Unicode is limited. |
| 12 |
|
| 13 |
+package triegen // import "github.com/clipperhouse/displaywidth/internal/gen/triegen" |
| 14 |
|
| 15 |
// TODO: Arguably, the internally optimized data types would not have to be |
| 16 |
// exposed in the generated API. We could also investigate not generating the |
| 17 |
diff --git a/internal/gen/unicode.go b/internal/gen/unicode.go |
| 18 |
index 59d1e32..ec8f5f3 100644 |
| 19 |
--- a/internal/gen/unicode.go |
| 20 |
+++ b/internal/gen/unicode.go |
| 21 |
@@ -5,7 +5,6 @@ import ( |
| 22 |
"bufio" |
| 23 |
"fmt" |
| 24 |
"io" |
| 25 |
|
| 26 |
"os" |
| 27 |
"path/filepath" |
| 28 |
"strconv" |
| 29 |
@@ -64,16 +63,14 @@ func ParseUnicodeData() (*UnicodeData, error) { |
| 30 |
ZeroWidthChars: make(map[rune]bool), |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
// Create data directory |
| 36 |
|
| 37 |
+ dataDir := "data" |
| 38 |
if err := os.MkdirAll(dataDir, 0755); err != nil { |
| 39 |
return nil, fmt.Errorf("failed to create data directory: %v", err) |
| 40 |
} |
| 41 |
|
| 42 |
eawFile := filepath.Join(dataDir, "EastAsianWidth.txt") |
| 43 |
|
| 44 |
+ if err := downloadFile("/usr/share/unicode/EastAsianWidth.txt", eawFile); err != nil { |
| 45 |
return nil, fmt.Errorf("failed to download EastAsianWidth.txt: %v", err) |
| 46 |
} |
| 47 |
if err := parseEastAsianWidth(eawFile, data); err != nil { |
| 48 |
@@ -81,7 +78,7 @@ func ParseUnicodeData() (*UnicodeData, error) { |
| 49 |
} |
| 50 |
|
| 51 |
emojiFile := filepath.Join(dataDir, "emoji-data.txt") |
| 52 |
|
| 53 |
+ if err := downloadFile("/usr/share/unicode/emoji/emoji-data.txt", emojiFile); err != nil { |
| 54 |
fmt.Printf("Warning: failed to download emoji-data.txt: %v\n", err) |
| 55 |
fmt.Println("Continuing with basic emoji detection from Go stdlib...") |
| 56 |
} else { |
| 57 |
@@ -105,15 +102,11 @@ func downloadFile(url, filepath string) error { |
| 58 |
} |
| 59 |
|
| 60 |
fmt.Printf("Downloading %s...\n", url) |
| 61 |
|
| 62 |
+ file, err := os.Open(url) |
| 63 |
if err != nil { |
| 64 |
return err |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
+ defer file.Close() |
| 72 |
|
| 73 |
out, err := os.Create(filepath) |
| 74 |
if err != nil { |
| 75 |
@@ -121,7 +114,7 @@ func downloadFile(url, filepath string) error { |
| 76 |
} |
| 77 |
defer out.Close() |
| 78 |
|
| 79 |
|
| 80 |
+ _, err = io.Copy(out, file) |
| 81 |
if err != nil { |
| 82 |
return err |
| 83 |
} |