Help us shape the future of Go! Take the 2026 Go Developer Survey

strutil

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package strutil 收敛 core 内字符串小工具,消除 executor/service 重复实现。

本包只保留 oekit/pkg 无等价物的路径安全与 CSV 能力(Truncate 按字节截断、 CSVEscape、SanitizeFileToken、SanitizePathToken),其余通用能力已委托给 github.com/oekit/pkg(convert / stringx)。函数签名保持不变,供跨仓直接引用。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolFact added in v0.9.0

func BoolFact(b bool) string

BoolFact bool → "true"/"false"(健康评分 facts 用)。

func CSVEscape

func CSVEscape(s string) string

CSVEscape 转义 CSV 单元格。

func Itoa

func Itoa(n int) string

Itoa int → 字符串。

func Itoa64

func Itoa64(n int64) string

Itoa64 int64 → 字符串。

func SanitizeFileToken

func SanitizeFileToken(s string) string

SanitizeFileToken 文件名安全化(防路径穿越)。

func SanitizePathToken added in v0.9.0

func SanitizePathToken(s string) string

SanitizePathToken 路径段安全化:去掉 / \ .. 与空格,防路径穿越。

func Truncate

func Truncate(s string, n int) string

Truncate 按字节截断并追加省略号。保证结果是合法 UTF-8(回退到码点边界), 输入本身含非法字节时同样回退,避免截出乱码。

func TruncateRunes added in v0.9.0

func TruncateRunes(s string, n int) string

TruncateRunes 按字符(rune)截断。

委托 oekit/pkg/stringx.FirstN(按 rune 计数,与本包原实现一致)。 差异兜底:FirstN 在 n<=0 时会返回省略号,而本包原语义是空串,故先短路返回 ""。

Types

This section is empty.

Jump to

Keyboard shortcuts

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