Code Monkey home page Code Monkey logo

go-str-utils's Introduction

Go 语言字符串相关实用工具库 go string related utils

本仓库只干一件事, 就是只做 go 语言中的字符串相关的实用函数或者方法, 当然是官方库 https://pkg.go.dev/strings 中未实现的,官方已有的实现我们不重复造轮子!

欢迎大家踊跃 PR,一起完善这个工具库!

如果你喜欢,请帮忙点亮免费小红星,您的小红星就是我们持续更新的动力!

目前已完成函数

  1. 各种命名转换函数 naming_convert.go 包括:
  • CamelStr 大驼峰 单词全部首字母大写 如: UserName

  • SmallCamelStr 小驼峰 第一个单词首字母小写,其他大写, 如: userName

  • SnakeStr 单词全部小写,使用下划线链接, 如: user_name

  • KebabStr 单词全部小写,使用 中划线链接 如: user-name

  1. 字符串过滤函数 filters.go
  • Html2str html 字符串过滤函数,过滤所有 script,style 内容, 其他所有<*>中的内容, 将 1 个以上的换行回车空格替换为 1 个空格
  1. 字符串操作函数 handle.go
  • Substr 截取指定长度的字符串,支持英文,中文和其他多字节字符串
  1. Regexp 编译缓存 cache_regexp.go
  1. 字符串条件判断相关函数 condition.go
  • StrIsChinese 判断字符串是否是中文
  • StrContainsChinese 是否包含中文
  • StrContainsContinuousNum 是否包含连续的数字 可自定义连续数字的长度,默认 2

更多的函数使用方法请参考PKG文档: https://pkg.go.dev/github.com/tekintian/go-str-utils#pkg-index

使用方法

go 版本环境, 最低 1.16, 我们建议你使用官方最新正式版, 这样就可以使用很多高级特性,比如 1.21 版本以上中的 slices 内置包等......

  • 安装最新版本依赖
go get -u github.com/tekintian/go-str-utils
  • 使用示例
import (
	"fmt"
	strutils "github.com/tekintian/go-str-utils"
)

func main() {
  camelStr := strutils.CamelStr("hello-world")
  fmt.Println(camelStr) // 输出: HelloWorld
}

其他使用示例可参考 *_test.go 中的测试用例, 我们的每个函数都有测试用例, 部分函数还使用了 Fuzz 模糊测试技术 来确保我们函数的可靠和高效! 同时也能帮助我们发现一些潜在的风险等......

也可参考 go pkg 文档,地址: https://pkg.go.dev/github.com/tekintian/go-str-utils

go 编码规范

每个函数需要有对应的测试函数,以确保函数的可靠性, 编码规范请参考 go 官方的 Effective Go

go 参考文档

Go 语言内置包 strings 文档 https://pkg.go.dev/strings

Go 程序设计语言规范 https://go.dev/ref/spec

Fuzzing 模糊测试官方使用文档 https://go.dev/security/fuzz

go-str-utils's People

Contributors

tekintian avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

51soft tekinvip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.