summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorclsr <clsr@clsr.net>2021-02-05 07:53:32 +0000
committerclsr <clsr@clsr.net>2021-02-05 07:53:32 +0000
commit690a7183d7eca35b59e23e556b0c6492df08ffa5 (patch)
tree6d9267e8d92c2298a0e4be931157d311d9ba9d44
parent94a4db6923203695aeac7350eb798d3c549e1005 (diff)
downloadcnm-go-690a7183d7eca35b59e23e556b0c6492df08ffa5.tar.gz
cnm-go-690a7183d7eca35b59e23e556b0c6492df08ffa5.zip
Fix string(rune) warningv0.4.1
-rw-r--r--go.mod3
-rw-r--r--simpletext.go6
-rw-r--r--simpletext_test.go150
3 files changed, 81 insertions, 78 deletions
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..f351ad8
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,3 @@
+module contnet.org/lib/cnm-go
+
+go 1.12
diff --git a/simpletext.go b/simpletext.go
index 78e089e..4d86d6d 100644
--- a/simpletext.go
+++ b/simpletext.go
@@ -159,13 +159,13 @@ func Unescape(s string) string {
return "\\"
case 'x':
n, _ := strconv.ParseUint(match[2:], 16, 8)
- return string(n)
+ return string(rune(n))
case 'u':
n, _ := strconv.ParseUint(match[2:], 16, 16)
- return string(n)
+ return string(rune(n))
case 'U':
n, _ := strconv.ParseUint(match[2:], 16, 32)
- return string(n)
+ return string(rune(n))
}
return match // this shouldn't happen
})
diff --git a/simpletext_test.go b/simpletext_test.go
index 8fdf754..c5b4cf9 100644
--- a/simpletext_test.go
+++ b/simpletext_test.go
@@ -3,21 +3,21 @@ package cnm
import "testing"
var simpleEscapes = map[string]string{
- "": ``,
- "ContNet": `ContNet`,
- "\t": `\t`,
- "\n": `\n`,
- "\f": `\f`,
- "\r": `\r`,
- " ": `\ `,
- "\\": `\\`,
- "\x00": `\x00`,
- " ": `\ \ \ \ `,
- " ": `\ \ \ \ `,
- " ": `\ \ \ `,
- " ": `\ \ \ `,
- " ": `\ \ `,
- " ": `\ \ `,
+ "": ``,
+ "ContNet": `ContNet`,
+ "\t": `\t`,
+ "\n": `\n`,
+ "\f": `\f`,
+ "\r": `\r`,
+ " ": `\ `,
+ "\\": `\\`,
+ "\x00": `\x00`,
+ " ": `\ \ \ \ `,
+ " ": `\ \ \ \ `,
+ " ": `\ \ \ `,
+ " ": `\ \ \ `,
+ " ": `\ \ `,
+ " ": `\ \ `,
"\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\\\\x00\xff\u00ff\\\\xff",
}
@@ -33,21 +33,21 @@ func TestEscape(t *testing.T) {
}
var nonspaceEscapes = map[string]string{
- "": ``,
- "ContNet": `ContNet`,
- "\t": "\t",
- "\n": "\n",
- "\f": `\f`,
- "\r": `\r`,
- " ": ` `,
- "\\": `\\`,
- "\x00": `\x00`,
- " ": ` `,
- " ": ` `,
- " ": ` `,
- " ": ` `,
- " ": ` `,
- " ": ` `,
+ "": ``,
+ "ContNet": `ContNet`,
+ "\t": "\t",
+ "\n": "\n",
+ "\f": `\f`,
+ "\r": `\r`,
+ " ": ` `,
+ "\\": `\\`,
+ "\x00": `\x00`,
+ " ": ` `,
+ " ": ` `,
+ " ": ` `,
+ " ": ` `,
+ " ": ` `,
+ " ": ` `,
"\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\\\\x00\xff\u00ff\\\\xff",
}
@@ -63,21 +63,21 @@ func TestEscapeNonspace(t *testing.T) {
}
var spaceEscapes = map[string]string{
- "": ``,
- "ContNet": `ContNet`,
- "\t": `\t`,
- "\n": `\n`,
- "\f": "\f",
- "\r": "\r",
- " ": `\ `,
- "\\": `\`,
- "\x00": "\x00",
- " ": `\ \ \ \ `,
- " ": `\ \ \ \ `,
- " ": `\ \ \ `,
- " ": `\ \ \ `,
- " ": `\ \ `,
- " ": `\ \ `,
+ "": ``,
+ "ContNet": `ContNet`,
+ "\t": `\t`,
+ "\n": `\n`,
+ "\f": "\f",
+ "\r": "\r",
+ " ": `\ `,
+ "\\": `\`,
+ "\x00": "\x00",
+ " ": `\ \ \ \ `,
+ " ": `\ \ \ \ `,
+ " ": `\ \ \ `,
+ " ": `\ \ \ `,
+ " ": `\ \ `,
+ " ": `\ \ `,
"\b\v\\\x00\xff\u00ff\\xff": "\b\v\\\x00\xff\u00ff\\xff",
}
@@ -93,36 +93,36 @@ func TestEscapeSpace(t *testing.T) {
}
var simpleUnescapes = map[string]string{
- ``: "",
- `ContNet`: "ContNet",
- `\b`: "\b",
- `\t`: "\t",
- `\n`: "\n",
- `\v`: "\v",
- `\f`: "\f",
- `\r`: "\r",
- `\ `: " ",
- `\\`: "\\",
- `\`: "\\",
- `\x00`: "\x00",
- `a\nb\ c\rd\be\\f`: "a\nb c\rd\be\\f",
- `\n\n\n`: "\n\n\n",
- `\x00\xff\n\x123`: "\x00\u00ff\n\x123",
- " \b\\b\t\n\v\f\r\\x00\x00\\\\xff": " \b\b\t\n\v\f\r\x00\x00\\xff",
- `\xAA\xAa\xaA\xaa`: "\u00aa\u00aa\u00aa\u00aa",
- `\x00\xfg`: "\x00\\xfg",
- `\\\\\\`: "\\\\\\",
- "\b5Ὂg̀9!\\n℃ᾭG": "\b5Ὂg̀9!\n℃ᾭG",
- "\xff\\x00\xee\xaa\xee": "\xff\x00\xee\xaa\xee",
- "\\x00\x10\\ \x30\x40": "\x00\x10\x20\x30\x40",
- "\x10\x50\x90\xe0": "\x10\x50\x90\xe0",
- `Hello,\ 世界`: "Hello, 世界",
- "\xed\x9f\xbf": "\xed\x9f\xbf",
- "\xee\x80\x80": "\xee\x80\x80",
- "\xef\xbf\xbd": "\xef\xbf\xbd",
- "\x80\x80\x80\x80": "\x80\x80\x80\x80",
- `\ \ \ `: " ",
- `\uffff\u0000\u0123\ufedc\ufffe`: "\uffff\u0000\u0123\ufedc\ufffe",
+ ``: "",
+ `ContNet`: "ContNet",
+ `\b`: "\b",
+ `\t`: "\t",
+ `\n`: "\n",
+ `\v`: "\v",
+ `\f`: "\f",
+ `\r`: "\r",
+ `\ `: " ",
+ `\\`: "\\",
+ `\`: "\\",
+ `\x00`: "\x00",
+ `a\nb\ c\rd\be\\f`: "a\nb c\rd\be\\f",
+ `\n\n\n`: "\n\n\n",
+ `\x00\xff\n\x123`: "\x00\u00ff\n\x123",
+ " \b\\b\t\n\v\f\r\\x00\x00\\\\xff": " \b\b\t\n\v\f\r\x00\x00\\xff",
+ `\xAA\xAa\xaA\xaa`: "\u00aa\u00aa\u00aa\u00aa",
+ `\x00\xfg`: "\x00\\xfg",
+ `\\\\\\`: "\\\\\\",
+ "\b5Ὂg̀9!\\n℃ᾭG": "\b5Ὂg̀9!\n℃ᾭG",
+ "\xff\\x00\xee\xaa\xee": "\xff\x00\xee\xaa\xee",
+ "\\x00\x10\\ \x30\x40": "\x00\x10\x20\x30\x40",
+ "\x10\x50\x90\xe0": "\x10\x50\x90\xe0",
+ `Hello,\ 世界`: "Hello, 世界",
+ "\xed\x9f\xbf": "\xed\x9f\xbf",
+ "\xee\x80\x80": "\xee\x80\x80",
+ "\xef\xbf\xbd": "\xef\xbf\xbd",
+ "\x80\x80\x80\x80": "\x80\x80\x80\x80",
+ `\ \ \ `: " ",
+ `\uffff\u0000\u0123\ufedc\ufffe`: "\uffff\u0000\u0123\ufedc\ufffe",
`\Uffff0000\U0003fedc\U0010ffff\U00110000`: "\ufffd\U0003fedc\U0010ffff\ufffd",
`\x0x\u012x\U0123456x`: "\\x0x\\u012x\\U0123456x",
`\U0123456`: "\\U0123456",