diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-12-17 22:38:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 14:38:54 +0000 |
commit | 20929edc9962281e35a81756d76dd1caa5741ff8 (patch) | |
tree | 138bbb9c97e609136fe83cf6e5524949218d1e72 /modules/util | |
parent | 408a4842240e7dd906e682196bd4254d6c76fcb9 (diff) | |
download | gitea-20929edc9962281e35a81756d76dd1caa5741ff8.tar.gz gitea-20929edc9962281e35a81756d76dd1caa5741ff8.zip |
Add option to disable ambiguous unicode characters detection (#28454)
* Close #24483
* Close #28123
* Close #23682
* Close #23149
(maybe more)
Diffstat (limited to 'modules/util')
-rw-r--r-- | modules/util/string.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/util/string.go b/modules/util/string.go index f2def7b0ec..2cf44d29b1 100644 --- a/modules/util/string.go +++ b/modules/util/string.go @@ -3,7 +3,7 @@ package util -import "github.com/yuin/goldmark/util" +import "unsafe" func isSnakeCaseUpper(c byte) bool { return 'A' <= c && c <= 'Z' @@ -83,5 +83,15 @@ func ToSnakeCase(input string) string { } } } - return util.BytesToReadOnlyString(res) + return UnsafeBytesToString(res) +} + +// UnsafeBytesToString uses Go's unsafe package to convert a byte slice to a string. +// TODO: replace all "goldmark/util.BytesToReadOnlyString" with this official approach +func UnsafeBytesToString(b []byte) string { + return unsafe.String(unsafe.SliceData(b), len(b)) +} + +func UnsafeStringToBytes(s string) []byte { + return unsafe.Slice(unsafe.StringData(s), len(s)) } |