1
0
mirror of https://github.com/duke-git/lancet.git synced 2026-02-04 12:52:28 +08:00

feat: add IsPrintable

This commit is contained in:
dudaodong
2023-03-31 12:00:32 +08:00
parent 217350042b
commit bc25e7a037
5 changed files with 132 additions and 3 deletions

View File

@@ -51,6 +51,7 @@ import (
- [IsWeakPassword](#IsWeakPassword)
- [IsZeroValue](#IsZeroValue)
- [IsGBK](#IsGBK)
- [IsPrintable](#IsPrintable)
<div STYLE="page-break-after: always;"></div>
@@ -296,7 +297,7 @@ func main() {
### <span id="IsASCII">IsASCII</span>
<p>Checks if string is ASCII char.</p>
<p>Checks if string is all ASCII char.</p>
<b>Signature:</b>
@@ -1031,3 +1032,44 @@ func main() {
// true
}
```
### <span id="IsPrintable">IsPrintable</span>
<p>Checks if string is all printable chars.</p>
<b>Signature:</b>
```go
func IsPrintable(str string) bool
```
<b>Example:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/validator"
)
func main() {
result1 := validator.IsPrintable("ABC")
result2 := validator.IsPrintable("{id: 123}")
result3 := validator.IsPrintable("")
result4 := validator.IsPrintable("😄")
result5 := validator.IsPrintable("\u0000")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
// Output:
// true
// true
// true
// true
// false
}
```

View File

@@ -51,6 +51,7 @@ import (
- [IsWeakPassword](#IsWeakPassword)
- [IsZeroValue](#IsZeroValue)
- [IsGBK](#IsGBK)
- [IsPrintable](#IsPrintable)
<div STYLE="page-break-after: always;"></div>
@@ -1031,3 +1032,44 @@ func main() {
// true
}
```
### <span id="IsPrintable">IsPrintable</span>
<p>检查字符串是否全部为可打印字符。</p>
<b>函数签名:</b>
```go
func IsPrintable(str string) bool
```
<b>示例:</b>
```go
import (
"fmt"
"github.com/duke-git/lancet/v2/validator"
)
func main() {
result1 := validator.IsPrintable("ABC")
result2 := validator.IsPrintable("{id: 123}")
result3 := validator.IsPrintable("")
result4 := validator.IsPrintable("😄")
result5 := validator.IsPrintable("\u0000")
fmt.Println(result1)
fmt.Println(result2)
fmt.Println(result3)
fmt.Println(result4)
fmt.Println(result5)
// Output:
// true
// true
// true
// true
// false
}
```