|
@@ -2,88 +2,81 @@
|
|
|
|
|
|
package yu_strings
|
|
|
|
|
|
-import (
|
|
|
- yu_fast "gogs.qqck.cn/s/go-tools/fast"
|
|
|
- yu_math "gogs.qqck.cn/s/go-tools/math"
|
|
|
- yu_win "gogs.qqck.cn/s/go-tools/win"
|
|
|
- "unsafe"
|
|
|
-)
|
|
|
-
|
|
|
-func Utf8ToUnicode(utf8 string) string {
|
|
|
- j_utf8_len := uintptr(len(utf8))
|
|
|
- j_unicode_len := j_utf8_len * 2
|
|
|
- j_unicode := make([]byte, j_unicode_len)
|
|
|
- return yu_fast.B2S(j_unicode[:yu_win.MultiByteToWideChar.CallInt(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)*2])
|
|
|
-}
|
|
|
-
|
|
|
-func Utf8ToUnicodePtr(utf8 string) uintptr {
|
|
|
- j_utf8_len := uintptr(len(utf8))
|
|
|
- j_unicode_len := j_utf8_len * 2
|
|
|
- j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
- yu_win.MultiByteToWideChar.CallInt(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
|
|
|
- return uintptr(unsafe.Pointer(&j_unicode[0]))
|
|
|
-}
|
|
|
-
|
|
|
-func UnicodeToUtf8(unicode string) string {
|
|
|
- j_unicode_len := uintptr(len(unicode))
|
|
|
- j_utf8_size := j_unicode_len * 3
|
|
|
- j_utf8 := make([]byte, j_utf8_size)
|
|
|
- return yu_fast.B2S(j_utf8[:yu_win.WideCharToMultiByte.CallInt(65001, 0, unicode, j_unicode_len/2, j_utf8, j_utf8_size, 0, 0)])
|
|
|
-}
|
|
|
-
|
|
|
-func GbkToUnicode(gbk string) string {
|
|
|
- j_gbk_len := uintptr(len(gbk))
|
|
|
- j_unicode_len := j_gbk_len * 2
|
|
|
- j_unicode := make([]byte, j_unicode_len)
|
|
|
- return yu_fast.B2S(j_unicode[:yu_win.MultiByteToWideChar.CallInt(936, 0, gbk, j_gbk_len, j_unicode, j_unicode_len)*2])
|
|
|
-}
|
|
|
-
|
|
|
-func UnicodeToGbk(unicode string) string {
|
|
|
- j_unicode_len := uintptr(len(unicode))
|
|
|
- j_gbk_size := j_unicode_len * 3
|
|
|
- j_gbk := make([]byte, j_gbk_size)
|
|
|
- return yu_fast.B2S(j_gbk[:yu_win.WideCharToMultiByte.CallInt(936, 0, unicode, j_unicode_len/2, j_gbk, j_gbk_size, 0, 0)])
|
|
|
-}
|
|
|
-
|
|
|
-func Utf8ToGbk(utf8 string) string {
|
|
|
- return UnicodeToGbk(Utf8ToUnicode(utf8))
|
|
|
-}
|
|
|
-
|
|
|
-func Utf8ToGbkPtr(utf8 string) uintptr {
|
|
|
- j_utf8_len := uintptr(len(utf8))
|
|
|
-
|
|
|
- j_unicode_len := j_utf8_len * 2
|
|
|
- j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
- yu_win.MultiByteToWideChar.Call(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
|
|
|
-
|
|
|
- j_gbk := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
- yu_win.WideCharToMultiByte.Call(936, 0, j_unicode, yu_math.MaxUint, j_gbk, j_unicode_len, 0, 0)
|
|
|
-
|
|
|
- return uintptr(unsafe.Pointer(&j_gbk[0]))
|
|
|
-}
|
|
|
-
|
|
|
-func GbkToUtf8(utf8 string) string {
|
|
|
- return UnicodeToUtf8(GbkToUnicode(utf8))
|
|
|
-}
|
|
|
-
|
|
|
-func GbkPtrToUtf8(ptr uintptr) string {
|
|
|
- j_unicode_len := yu_win.MultiByteToWideChar.CallInt(936, 0, ptr, yu_math.MaxUint, 0, 0)
|
|
|
- if j_unicode_len < 2 {
|
|
|
- return ""
|
|
|
- } // 结尾 {0,0} 也占一个字符
|
|
|
- return GbkPtrLenToUtf8(ptr, (j_unicode_len-1)*2)
|
|
|
-}
|
|
|
-
|
|
|
-func GbkPtrLenToUtf8(ptr uintptr, len int) string {
|
|
|
- if len < 1 {
|
|
|
- return ""
|
|
|
- }
|
|
|
-
|
|
|
- j_unicode_len := len * 2
|
|
|
- j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
- yu_win.MultiByteToWideChar.Call(936, 0, ptr, len, j_unicode, j_unicode_len)
|
|
|
-
|
|
|
- j_utf8 := make([]byte, len*3+2) // 结尾 {0,0}
|
|
|
-
|
|
|
- return yu_fast.B2S(j_utf8[:yu_win.WideCharToMultiByte.CallInt(65001, 0, j_unicode, yu_math.MaxUint, j_utf8, len*3, 0, 0)-1]) // 结尾 {0}
|
|
|
-}
|
|
|
+// func Utf8ToUnicode(utf8 string) string {
|
|
|
+// j_utf8_len := uintptr(len(utf8))
|
|
|
+// j_unicode_len := j_utf8_len * 2
|
|
|
+// j_unicode := make([]byte, j_unicode_len)
|
|
|
+// return yu_fast.B2S(j_unicode[:yu_win.MultiByteToWideChar.CallInt(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)*2])
|
|
|
+// }
|
|
|
+//
|
|
|
+// func Utf8ToUnicodePtr(utf8 string) uintptr {
|
|
|
+// j_utf8_len := uintptr(len(utf8))
|
|
|
+// j_unicode_len := j_utf8_len * 2
|
|
|
+// j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
+// yu_win.MultiByteToWideChar.CallInt(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
|
|
|
+// return uintptr(unsafe.Pointer(&j_unicode[0]))
|
|
|
+// }
|
|
|
+//
|
|
|
+// func UnicodeToUtf8(unicode string) string {
|
|
|
+// j_unicode_len := uintptr(len(unicode))
|
|
|
+// j_utf8_size := j_unicode_len * 3
|
|
|
+// j_utf8 := make([]byte, j_utf8_size)
|
|
|
+// return yu_fast.B2S(j_utf8[:yu_win.WideCharToMultiByte.CallInt(65001, 0, unicode, j_unicode_len/2, j_utf8, j_utf8_size, 0, 0)])
|
|
|
+// }
|
|
|
+//
|
|
|
+// func GbkToUnicode(gbk string) string {
|
|
|
+// j_gbk_len := uintptr(len(gbk))
|
|
|
+// j_unicode_len := j_gbk_len * 2
|
|
|
+// j_unicode := make([]byte, j_unicode_len)
|
|
|
+// return yu_fast.B2S(j_unicode[:yu_win.MultiByteToWideChar.CallInt(936, 0, gbk, j_gbk_len, j_unicode, j_unicode_len)*2])
|
|
|
+// }
|
|
|
+//
|
|
|
+// func UnicodeToGbk(unicode string) string {
|
|
|
+// j_unicode_len := uintptr(len(unicode))
|
|
|
+// j_gbk_size := j_unicode_len * 3
|
|
|
+// j_gbk := make([]byte, j_gbk_size)
|
|
|
+// return yu_fast.B2S(j_gbk[:yu_win.WideCharToMultiByte.CallInt(936, 0, unicode, j_unicode_len/2, j_gbk, j_gbk_size, 0, 0)])
|
|
|
+// }
|
|
|
+//
|
|
|
+// func Utf8ToGbk(utf8 string) string {
|
|
|
+// return UnicodeToGbk(Utf8ToUnicode(utf8))
|
|
|
+// }
|
|
|
+//
|
|
|
+// func Utf8ToGbkPtr(utf8 string) uintptr {
|
|
|
+// j_utf8_len := uintptr(len(utf8))
|
|
|
+//
|
|
|
+// j_unicode_len := j_utf8_len * 2
|
|
|
+// j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
+// yu_win.MultiByteToWideChar.Call(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len)
|
|
|
+//
|
|
|
+// j_gbk := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
+// yu_win.WideCharToMultiByte.Call(936, 0, j_unicode, yu_math.MaxUint, j_gbk, j_unicode_len, 0, 0)
|
|
|
+//
|
|
|
+// return uintptr(unsafe.Pointer(&j_gbk[0]))
|
|
|
+// }
|
|
|
+//
|
|
|
+// func GbkToUtf8(utf8 string) string {
|
|
|
+// return UnicodeToUtf8(GbkToUnicode(utf8))
|
|
|
+// }
|
|
|
+//
|
|
|
+// func GbkPtrToUtf8(ptr uintptr) string {
|
|
|
+// j_unicode_len := yu_win.MultiByteToWideChar.CallInt(936, 0, ptr, yu_math.MaxUint, 0, 0)
|
|
|
+// if j_unicode_len < 2 {
|
|
|
+// return ""
|
|
|
+// } // 结尾 {0,0} 也占一个字符
|
|
|
+// return GbkPtrLenToUtf8(ptr, (j_unicode_len-1)*2)
|
|
|
+// }
|
|
|
+//
|
|
|
+// func GbkPtrLenToUtf8(ptr uintptr, len int) string {
|
|
|
+// if len < 1 {
|
|
|
+// return ""
|
|
|
+// }
|
|
|
+//
|
|
|
+// j_unicode_len := len * 2
|
|
|
+// j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0}
|
|
|
+// yu_win.MultiByteToWideChar.Call(936, 0, ptr, len, j_unicode, j_unicode_len)
|
|
|
+//
|
|
|
+// j_utf8 := make([]byte, len*3+2) // 结尾 {0,0}
|
|
|
+//
|
|
|
+// return yu_fast.B2S(j_utf8[:yu_win.WideCharToMultiByte.CallInt(65001, 0, j_unicode, yu_math.MaxUint, j_utf8, len*3, 0, 0)-1]) // 结尾 {0}
|
|
|
+// }
|