common

package
v1.3.399 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 16 Imported by: 5

Documentation

Overview

Package common 公共函数.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtoUint32 added in v1.3.396

func AtoUint32(s string) uint32

AtoUint32 将 string 转换成 uint32.

func Atof added in v1.3.396

func Atof(s string) float32

Atof 将 string 转换到 float32.

func Atoi added in v1.3.396

func Atoi(s string) int32

Atoi 将 string 转换到 int32.

func BoolPtr

func BoolPtr(b bool) uintptr

BoolPtr 将 bool 转换到 uintptr.

b: bool.

func BoolToInt added in v1.3.395

func BoolToInt(input bool) int

BoolToInt 将 bool 类型转换为 int 类型.

  • true 返回 1, false 返回 0.

func BoolToString added in v1.3.395

func BoolToString(input bool) string

BoolToString 将 bool 类型转换为字符串 true 或 false.

func ByteSliceDataPtr

func ByteSliceDataPtr(b *[]byte) uintptr

ByteSliceDataPtr 将 byte[0] 的指针转换到 uintptr.

b: byte[0]的指针.

func Bytes2String added in v1.3.381

func Bytes2String(b []byte) string

Bytes2String 转换 []byte 到 string.

b: []byte.

func Choose added in v1.3.396

func Choose[T interface{}](b bool, value1, value2 T) T

Choose 根据条件选择返回两个值中的一个.

b: 选择条件.

value1: 当 b 为 true 时返回的值.

value2: 当 b 为 false 时返回的值.

func ChooseValue added in v1.3.396

func ChooseValue[T interface{}](i int, value ...T) T

ChooseValue 根据索引从参数列表中选择并返回一个值。

i: 索引. 如果小于 0 或者大于最大可选择项,将会 painc。

value: 参数列表。

func ErrorToErrno added in v1.3.395

func ErrorToErrno(err error) (syscall.Errno, bool)

ErrorToErrno 将错误转换为系统调用错误号.

err: 需要转换的错误对象

返回值:

  • syscall.Errno: 转换后的系统错误号
  • bool: 是否成功转换的标志

func Float32Ptr

func Float32Ptr(f float32) uintptr

Float32Ptr 将 float32 转换到 uintptr.

f: float32.

func Float64ToUint32Pair added in v1.3.397

func Float64ToUint32Pair(f float64) (low, high uint32)

Float64ToUint32Pair 将一个 64 位浮点数转换为两个 32 位整数。用于传递 float64 给 COM 方法。

func Ftoa added in v1.3.396

func Ftoa(f float32) string

Ftoa 将 float32 转换到 string.

func GetHighWord added in v1.3.399

func GetHighWord(dwValue uint32) uint16

GetHighWord 获取高 16 位.

func GetLowWord added in v1.3.399

func GetLowWord(dwValue uint32) uint16

GetLowWord 获取低 16 位.

func GetProcessName added in v1.3.395

func GetProcessName() string

GetProcessName 取当前进程名.

func GetProcessNameWithoutExt added in v1.3.395

func GetProcessNameWithoutExt() string

GetProcessNameWithoutExt 取当前进程名(不含扩展名).

func IntToBool added in v1.3.396

func IntToBool(input int) bool

IntToBool 将 int 类型转换为 bool 类型.

  • 0 返回 false, 其他值返回 true.

func Itoa added in v1.3.396

func Itoa(i32 int32) string

Itoa 将 int32 转换到 string.

func SliceIndexOf added in v1.3.396

func SliceIndexOf[T comparable](slice []T, target T) int

SliceIndexOf 获取元素在 slice 中第一个找到的索引, 找不到则返回 -1.

func StrPtr

func StrPtr(s string) uintptr

StrPtr 将 string 转换到 uintptr.

s: 文本.

func String2Bytes added in v1.3.381

func String2Bytes(s string) []byte

String2Bytes 转换 string 到 []byte.

s: 文本.

func StringToBool added in v1.3.395

func StringToBool(input string) bool

StringToBool 将字符串转换为 bool 类型.

  • true 和 1 字符串都会转换为 true, 'true'字符串不区分大小写, 其他值都转换为 false.

func StringToUint16Ptr

func StringToUint16Ptr(s string) *uint16

StringToUint16Ptr 返回指向 UTF-8 字符串 s 的 UTF-16 编码的指针,与 syscall.UTF16PtrFromString 不同的是末尾没有添加终止 NUL.

s: 文本.

func UTF16PtrToString added in v1.3.395

func UTF16PtrToString(p *uint16) string

UTF16PtrToString 接收一个指向 UTF-16 切片的指针,并返回对应的 UTF-8 编码字符串。

  • 如果指针为空,则返回空字符串。该函数假设 UTF-16 序列以零字符结尾;
  • 如果不存在零字符,程序可能会崩溃。

func Uint16SliceDataPtr

func Uint16SliceDataPtr(p *[]uint16) uintptr

Uint16SliceDataPtr 将 uint16[0] 指针转换到 uintptr.

p: uint16[0]的指针.

func Uint16SliceToStringSlice

func Uint16SliceToStringSlice(s []uint16) []string

Uint16SliceToStringSlice 按 null 字符分割, 把 []uint16 转换到 []string.

s: []uint16.

func Uint32ToA added in v1.3.396

func Uint32ToA(i uint32) string

Uint32ToA 将 uint32 转换成 string.

func UintPtrToFloat32

func UintPtrToFloat32(ptr uintptr) float32

UintPtrToFloat32 将 uintptr 转换到 float32.

ptr: uintptr.

func UintPtrToSlice added in v1.3.395

func UintPtrToSlice(ptr uintptr) []interface{}

UintPtrToSlice 将 uintptr 转换到 []interface{}.

ptr: uintptr.

func UintPtrToSliceWithCap added in v1.3.399

func UintPtrToSliceWithCap(ptr uintptr) []interface{}

UintPtrToSliceWithCap 将 uintptr 转换到 []interface{}.

  • 与 UintPtrToSlice 不同的是, 传进来的切片的第 0 个元素必须是切片长度

ptr: uintptr.

func UintPtrToString

func UintPtrToString(ptr uintptr) string

UintPtrToString 将 uintptr 转换到 string.

ptr: uintptr.

Types

type GifFrame added in v1.3.395

type GifFrame struct {
	ImageData []byte        // PNG 格式的二进制数据
	Delay     time.Duration // 帧延时
}

GifFrame 包含 Gif 每帧的二进制数据和延时信息.

func ExtractGifFrames added in v1.3.395

func ExtractGifFrames(gifReader io.Reader) ([]GifFrame, error)

ExtractGifFrames 提取 GIF 的所有帧.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL