From 20929edc9962281e35a81756d76dd1caa5741ff8 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 17 Dec 2023 22:38:54 +0800 Subject: Add option to disable ambiguous unicode characters detection (#28454) * Close #24483 * Close #28123 * Close #23682 * Close #23149 (maybe more) --- modules/util/string.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'modules/util') 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)) } -- cgit v1.2.3