Documentation
¶
Index ¶
- func ByteToFloat64(bytes []byte) float64
- func ConvertBig5ToUTF8(s string) string
- func Float64ToByte(f float64) []byte
- func FromPtr[T any](ptr *T) T
- func MD5Hash(text string) string
- func MapToPtrMap[T any](src map[string]T) map[string]*T
- func PtrMapToMap[T any](src map[string]*T) map[string]T
- func PtrSliceToSlice[T any](src []*T) []T
- func SliceToPtrSlice[T any](src []T) []*T
- func SnakeCasedName(name string) string
- func TitleCasedName(name string) string
- func ToBool(value interface{}) bool
- func ToFloat(value interface{}) interface{}
- func ToInt(value interface{}) interface{}
- func ToPtr[T any](value T) *T
- func ToString(value interface{}) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ByteToFloat64 ¶ added in v0.1.0
ByteToFloat64 converts an 8-byte slice in BigEndian order back to a float64 value. - Panics if the input length is not 8. - Useful for binary deserialization and network data parsing.
func ConvertBig5ToUTF8 ¶ added in v0.2.1
ConvertBig5ToUTF8 converts a string encoded in Big5 to a UTF-8 encoded string. The input parameter s must be a string encoded in Big5, and the function returns the corresponding UTF-8 string. This function uses the Go standard library's transform package for conversion, which results in a string allocation. If the conversion fails (e.g., if the input is not valid Big5), the original string is returned and no panic occurs.
Usage Example:
big5Str := "\xa4\xa4\xa4\xe5" // "中文" in Big5 encoding utf8Str := ConvertBig5ToUTF8(big5Str) fmt.Println(utf8Str) // Output: 中文
func Float64ToByte ¶ added in v0.1.0
Float64ToByte converts a float64 value to an 8-byte slice in BigEndian order. - Useful for binary serialization and network transmission. - Reference: https://stackoverflow.com/questions/43693360/convert-float64-to-byte-array
func FromPtr ¶ added in v0.3.0
func FromPtr[T any](ptr *T) T
FromPtr takes a pointer to a value and returns the value itself. If the pointer is nil, it returns the zero value of the type.
T: The type of the value being dereferenced. ptr: The pointer to the value.
Returns the value pointed to by the pointer, or the zero value if the pointer is nil.
func MD5Hash ¶ added in v0.0.3
MD5Hash computes the MD5 hash of the input string and returns a 32-character hexadecimal string. - Useful for data validation, generating unique identifiers, etc. - Warning: MD5 is not recommended for password hashing or security-sensitive use cases.
func MapToPtrMap ¶ added in v1.0.0
MapToPtrMap converts a map of values (map[string]T) to a map of pointers (map[string]*T). Each value in the result points to a copy of the corresponding value in the input map.
func PtrMapToMap ¶ added in v1.0.0
PtrMapToMap converts a map of pointers (map[string]*T) to a map of values (map[string]T). If a value in the input map is nil, the key is omitted in the result.
func PtrSliceToSlice ¶ added in v1.0.0
func PtrSliceToSlice[T any](src []*T) []T
PtrSliceToSlice converts a slice of pointers ([]*T) to a slice of values ([]T). If an element in the input slice is nil, the zero value of T is used.
func SliceToPtrSlice ¶ added in v1.0.0
func SliceToPtrSlice[T any](src []T) []*T
SliceToPtrSlice converts a slice of values ([]T) to a slice of pointers ([]*T). Each element in the result points to the corresponding element in the input slice. Note: The pointers are valid only as long as the input slice is not modified.
func SnakeCasedName ¶ added in v0.0.9
SnakeCasedName converts a string to snake_case format and supports Unicode characters. - Each uppercase English letter (A-Z) is converted to lowercase and prefixed with an underscore if not at the start. - Only English letters are affected; other Unicode characters (e.g., Chinese) are preserved as-is. - Example: FooBar -> foo_bar, 你好World -> 你好_world
func TitleCasedName ¶ added in v0.0.9
TitleCasedName converts a snake_case string to TitleCase format and supports Unicode characters. - Each English letter following an underscore is capitalized, and underscores are removed. - Only English letters are affected; other Unicode characters (e.g., Chinese) are preserved as-is. - Example: foo_bar -> FooBar, hello_世界 -> Hello世界
func ToPtr ¶ added in v0.2.0
func ToPtr[T any](value T) *T
ToPtr takes a value of any type and returns a pointer to that value. This is useful for converting a value to a pointer in a generic way.
T: The type of the value being converted. value: The value to be converted to a pointer.
Returns a pointer to the provided value.
Types ¶
This section is empty.