ku

package module
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: MIT Imports: 14 Imported by: 1 module, 4 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Golang 实用函数库

based on Go 1.18+ Generics

go get -u github.com/nopdan/ku
import "https://github.com/nopdan/ku"

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LineBreak string

不同操作系统的换行符

Functions

func BytesToInt

func BytesToInt(b []byte) int

字节(小端)转为整数

func Decode

func Decode(b []byte, e string) (string, error)

[]byte, encoding -> string

func Encode

func Encode(s, e string) ([]byte, error)

string, encoding -> []byte

func GetFileName

func GetFileName(fp string) string

获取文件名,不含路径和后缀

func IsHan

func IsHan(word string) bool

判断字符串中是否全是汉字

func NewReader

func NewReader(input io.Reader) io.Reader

将字节流转换为 utf-8

func Product

func Product[T any](sli [][]T) [][]T

求笛卡尔积

[[a,b],[c],[d,e]]->[[a,c,d],[a,c,e],[b,c,d],[b,c,e]]

func Read

func Read(path string) (io.Reader, error)

读取文件

func ReadUint16

func ReadUint16(r io.Reader) uint16

读 2 个字节,按小端序转为 uint16

func ReadUint32

func ReadUint32(r io.Reader) uint32

读 4 个字节,按小端序转为 uint32

func RemoveEmptyItems added in v0.3.3

func RemoveEmptyItems[T []any | string | map[any]any](slice []T) []T

去除切片中的空元素

func To2Bytes

func To2Bytes[T integer](i T) []byte

转换为长度为 2 的字节切片

func To4Bytes

func To4Bytes[T integer](i T) []byte

转换为长度为 4 的字节切片

func TrimSpace

func TrimSpace(s string) string

去除字符串中的所有空白字符

func Unique

func Unique[T comparable](slice []T) []T

切片去重,保留顺序

Types

This section is empty.

Jump to

Keyboard shortcuts

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