张富强 hai 5 meses
pai
achega
918741fecc
Modificáronse 3 ficheiros con 92 adicións e 104 borrados
  1. 78 85
      strings/to_windows.go
  2. 7 12
      strings/to_windows_test.go
  3. 7 7
      sync/map.go

+ 78 - 85
strings/to_windows.go

@@ -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}
+// }

+ 7 - 12
strings/to_windows_test.go

@@ -1,14 +1,9 @@
 package yu_strings
 
-import (
-	"fmt"
-	"testing"
-)
-
-func TestUtf8ToUnicode(t *testing.T) {
-	fmt.Println(UnicodeToGbk(Utf8ToUnicode("asd啊啊啊额额")))
-	fmt.Println(Utf8ToGbk("asd啊啊啊额额"))
-	fmt.Println(Utf8ToUnicode("asd啊啊啊额额"))
-	fmt.Println(GbkToUnicode(Utf8ToGbk("asd啊啊啊额额")))
-	fmt.Println(UnicodeToUtf8(Utf8ToUnicode("asd啊啊啊额额")))
-}
+// func TestUtf8ToUnicode(t *testing.T) {
+// 	fmt.Println(UnicodeToGbk(Utf8ToUnicode("asd啊啊啊额额")))
+// 	fmt.Println(Utf8ToGbk("asd啊啊啊额额"))
+// 	fmt.Println(Utf8ToUnicode("asd啊啊啊额额"))
+// 	fmt.Println(GbkToUnicode(Utf8ToGbk("asd啊啊啊额额")))
+// 	fmt.Println(UnicodeToUtf8(Utf8ToUnicode("asd啊啊啊额额")))
+// }

+ 7 - 7
sync/map.go

@@ -7,32 +7,32 @@ type Map[K comparable, V any] struct {
 	hash map[K]V
 }
 
-func (t *Map[K, V]) Set(key K, value V) {
+func (t *Map[K, V]) Set(key K, val V) {
 	t.lock.Lock()
 	defer t.lock.Unlock()
 	if t.hash == nil {
 		t.hash = make(map[K]V)
 	}
-	t.hash[key] = value
+	t.hash[key] = val
 }
 
-func (t *Map[K, V]) Get(key K) (value V, ok bool) {
+func (t *Map[K, V]) Get(key K) (val V, ok bool) {
 	t.lock.Lock()
 	defer t.lock.Unlock()
 	if t.hash == nil {
 		return
 	}
-	value, ok = t.hash[key]
+	val, ok = t.hash[key]
 	return
 }
 
-func (t *Map[K, V]) GetDelete(key K) (value V, ok bool) {
+func (t *Map[K, V]) GetDelete(key K) (val V, ok bool) {
 	t.lock.Lock()
 	defer t.lock.Unlock()
 	if t.hash == nil {
 		return
 	}
-	if value, ok = t.hash[key]; ok {
+	if val, ok = t.hash[key]; ok {
 		delete(t.hash, key)
 	}
 	return
@@ -74,7 +74,7 @@ func (t *Map[K, V]) Delete(key K) (ok bool) {
 	return
 }
 
-func (t *Map[K, V]) Clean() {
+func (t *Map[K, V]) Clear() {
 	t.lock.Lock()
 	defer t.lock.Unlock()
 	t.hash = make(map[K]V)