From 3d1bd08434bea8fd7407d43ef5331b53d7a399f5 Mon Sep 17 00:00:00 2001 From: dudaodong Date: Fri, 1 Mar 2024 22:38:57 +0800 Subject: [PATCH] doc: update doc for new functions --- README.md | 12 ++++++++++++ README_zh-CN.md | 14 ++++++++++++++ docs/api/packages/convertor.md | 2 +- docs/api/packages/slice.md | 32 +++++++++++++++++++++++++++++++ docs/en/api/packages/convertor.md | 2 +- docs/en/api/packages/slice.md | 31 ++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8af26e5..7d69023 100644 --- a/README.md +++ b/README.md @@ -318,6 +318,14 @@ import "github.com/duke-git/lancet/v2/convertor" - **GbkToUtf8** : converts GBK encoding data to utf8 encoding data. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#GbkToUtf8)] [[play](https://go.dev/play/p/OphmHCN_9u8)] +- **ToStdBase64** : converts a value to a string encoded in standard Base64. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToStdBase64)] +- **ToUrlBase64** : converts a value to a string encoded in url Base64. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToUrlBase64)] +- **ToRawStdBase64** : converts a value to a string encoded in raw standard Base64. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawStdBase64)] +- **ToRawUrlBase64** : converts a value to a string encoded in raw url Base64. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/convertor.md#ToRawUrlBase64)]

6. Cryptor package is for data encryption and decryption.       index

@@ -1364,6 +1372,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Random** : get a random item of slice, return its index, when slice is empty, return -1. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#Random)] [[play](https://go.dev/play/p/UzpGQptWppw)] +- **SetToDefaultIf** : set elements to their default value if they match the given predicate. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/slice.md#SetToDefaultIf)]

19. Stream package implements a sequence of elements supporting sequential and operations. this package is an experiment to explore if stream in go can work as the way java does. its function is very limited.        index

@@ -1609,6 +1619,8 @@ import "github.com/duke-git/lancet/v2/strutil" - **RemoveWhiteSpace** : remove whitespace characters from a string. [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#RemoveWhiteSpace)] [[play](https://go.dev/play/p/HzLC9vsTwkf)] +- **SubInBetween** : return substring between the start and end position(excluded) of source string. + [[doc](https://github.com/duke-git/lancet/blob/main/docs/en/api/packages/strutil.md#SubInBetween)]

22. System package contain some functions about os, runtime, shell command.        index

diff --git a/README_zh-CN.md b/README_zh-CN.md index 8c17213..03513b6 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -317,6 +317,15 @@ import "github.com/duke-git/lancet/v2/convertor" - **GbkToUtf8** : GBK 编码转 utf8 编码。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#GbkToUtf8)] [[play](https://go.dev/play/p/OphmHCN_9u8)] +- **ToStdBase64** : 将值转换为StdBase64编码的字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToStdBase64)] +- **ToUrlBase64** : 将值转换为url Base64编码的字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToUrlBase64)] +- **ToRawStdBase64** : 将值转换为RawStdBase64编码的字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawStdBase64)] +- **ToRawUrlBase64** : 将值转换为RawUrlBase64编码的字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/convertor.md#ToRawUrlBase64)] +

6. cryptor 加密包支持数据加密和解密,获取 md5,hash 值。支持 base64, md5, hmac, aes, des, rsa。       回到目录

@@ -1358,6 +1367,8 @@ import "github.com/duke-git/lancet/v2/slice" - **Random** : 随机返回切片中元素以及下标, 当切片长度为0时返回下标-1。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#Random)] [[play](https://go.dev/play/p/UzpGQptWppw)] +- **SetToDefaultIf** : 根据给定给定的predicate判定函数来修改切片中的元素。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/slice.md#SetToDefaultIf)] @@ -1607,6 +1618,9 @@ import "github.com/duke-git/lancet/v2/strutil" - **RemoveWhiteSpace** : 删除字符串中的空格。 [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#RemoveWhiteSpace)] [[play](https://go.dev/play/p/HzLC9vsTwkf)] +- **SubInBetween** : 获取字符串中指定的起始字符串start和终止字符串end直接的子字符串。 + [[doc](https://github.com/duke-git/lancet/blob/main/docs/api/packages/strutil.md#SubInBetween)] +

22. system 包含 os, runtime, shell command 的相关函数。       回到目录

diff --git a/docs/api/packages/convertor.md b/docs/api/packages/convertor.md index 71642e8..966bf01 100644 --- a/docs/api/packages/convertor.md +++ b/docs/api/packages/convertor.md @@ -883,7 +883,7 @@ func main() { ### ToStdBase64 -

值转换为 StdBase64 编码的字符串。error 类型的数据也会把 error 的原因进行编码,复杂的结构会转为 JSON 格式的字符串

+

将值转换为StdBase64编码的字符串。error类型的数据也会把error的原因进行编码,复杂的结构会转为JSON格式的字符串

函数签名: diff --git a/docs/api/packages/slice.md b/docs/api/packages/slice.md index dab680f..2b41f7a 100644 --- a/docs/api/packages/slice.md +++ b/docs/api/packages/slice.md @@ -93,6 +93,7 @@ import ( - [KeyBy](#KeyBy) - [Join](#Join) - [Partition](#Partition) +- [SetToDefaultIf](#SetToDefaultIf)
@@ -2568,4 +2569,35 @@ func main() { // Output: // okk } +``` + +### SetToDefaultIf + +

根据给定给定的predicate判定函数来修改切片中的元素。对于满足的元素,将其替换为指定的默认值,同时保持元素在切片中的位置不变。函数返回修改后的切片以及被修改的元素个数。

+ +函数签名: + +```go +func SetToDefaultIf[T any](slice []T, predicate func(T) bool) ([]T, int) +``` + +示例: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/slice" +) + +func main() { + strs := []string{"a", "b", "a", "c", "d", "a"} + modifiedStrs, count := slice.SetToDefaultIf(strs, func(s string) bool { return "a" == s }) + + fmt.Println(modifiedStrs) + fmt.Println(count) + + // Output: + // [ b c d ] + // 3 +} ``` \ No newline at end of file diff --git a/docs/en/api/packages/convertor.md b/docs/en/api/packages/convertor.md index c1ed5ea..e437f0e 100644 --- a/docs/en/api/packages/convertor.md +++ b/docs/en/api/packages/convertor.md @@ -955,7 +955,7 @@ func main() { ### ToUrlBase64 -

Convert a value to a string encoded in Url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.

+

Convert a value to a string encoded in url Base64. Error data of type "error" will also be encoded, and complex structures will be converted to a JSON-formatted string.

Signature: diff --git a/docs/en/api/packages/slice.md b/docs/en/api/packages/slice.md index e113471..9c46ce5 100644 --- a/docs/en/api/packages/slice.md +++ b/docs/en/api/packages/slice.md @@ -2565,4 +2565,35 @@ func main() { // Output: // okk } +``` + +### SetToDefaultIf + +

Sets elements to their default value if they match the given predicate. It retains the positions of the elements in the slice. It returns slice of T and the count of modified slice items

+ +Signature: + +```go +func SetToDefaultIf[T any](slice []T, predicate func(T) bool) ([]T, int) +``` + +Example: + +```go +import ( + "fmt" + "github.com/duke-git/lancet/v2/slice" +) + +func main() { + strs := []string{"a", "b", "a", "c", "d", "a"} + modifiedStrs, count := slice.SetToDefaultIf(strs, func(s string) bool { return "a" == s }) + + fmt.Println(modifiedStrs) + fmt.Println(count) + + // Output: + // [ b c d ] + // 3 +} ``` \ No newline at end of file