//go:build windows package yu_strings import ( yu_math "gogs.qqck.cn/s/tools/math" yu_sys "gogs.qqck.cn/s/tools/sys" ) // 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 string(j_unicode[:yu_sys.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_sys.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 string(j_utf8[:yu_sys.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 string(j_unicode[:yu_sys.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 string(j_gbk[:yu_sys.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 Utf8ToGbkBytes(utf8 string) []byte { j_utf8_len := uintptr(len(utf8)) j_unicode_len := j_utf8_len * 2 j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0} yu_sys.MultiByteToWideChar.Call(65001, 0, utf8, j_utf8_len, j_unicode, j_unicode_len) j_gbk := make([]byte, j_unicode_len+2) // 结尾 {0,0} yu_sys.WideCharToMultiByte.Call(936, 0, j_unicode, uint(yu_math.MaxUint), j_gbk, j_unicode_len, 0, 0) return j_gbk } // func GbkToUtf8(utf8 string) string { // return UnicodeToUtf8(GbkToUnicode(utf8)) // } func GbkPtrToUtf8(ptr uintptr) string { j_unicode_len := yu_sys.MultiByteToWideChar.CallUintptr(936, 0, ptr, uint(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 uintptr) string { if len < 1 { return "" } j_unicode_len := len * 2 j_unicode := make([]byte, j_unicode_len+2) // 结尾 {0,0} yu_sys.MultiByteToWideChar.Call(936, 0, ptr, len, j_unicode, j_unicode_len) j_utf8 := make([]byte, len*3+2) // 结尾 {0,0} return string(j_utf8[:yu_sys.WideCharToMultiByte.CallInt(65001, 0, j_unicode, uint(yu_math.MaxUint), j_utf8, len*3, 0, 0)-1]) // 结尾 {0} }