mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-23 13:52:26 +08:00
doc: format code in doc file
This commit is contained in:
@@ -652,45 +652,45 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Struct struct {
|
type Struct struct {
|
||||||
Str string
|
Str string
|
||||||
Int int
|
Int int
|
||||||
Float float64
|
Float float64
|
||||||
Bool bool
|
Bool bool
|
||||||
Nil interface{}
|
Nil interface{}
|
||||||
unexported string
|
unexported string
|
||||||
}
|
}
|
||||||
|
|
||||||
cases := []interface{}{
|
cases := []interface{}{
|
||||||
true,
|
true,
|
||||||
1,
|
1,
|
||||||
0.1,
|
0.1,
|
||||||
map[string]int{
|
map[string]int{
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"b": 2,
|
"b": 2,
|
||||||
},
|
},
|
||||||
&Struct{
|
&Struct{
|
||||||
Str: "test",
|
Str: "test",
|
||||||
Int: 1,
|
Int: 1,
|
||||||
Float: 0.1,
|
Float: 0.1,
|
||||||
Bool: true,
|
Bool: true,
|
||||||
Nil: nil,
|
Nil: nil,
|
||||||
// unexported: "can't be cloned",
|
// unexported: "can't be cloned",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range cases {
|
for _, item := range cases {
|
||||||
cloned := convertor.DeepClone(item)
|
cloned := convertor.DeepClone(item)
|
||||||
|
|
||||||
isPointerEqual := &cloned == &item
|
isPointerEqual := &cloned == &item
|
||||||
fmt.Println(cloned, isPointerEqual)
|
fmt.Println(cloned, isPointerEqual)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true false
|
// true false
|
||||||
// 1 false
|
// 1 false
|
||||||
// 0.1 false
|
// 0.1 false
|
||||||
// map[a:1 b:2] false
|
// map[a:1 b:2] false
|
||||||
// &{test 1 0.1 true <nil> } false
|
// &{test 1 0.1 true <nil> } false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -717,43 +717,43 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Address struct {
|
type Address struct {
|
||||||
Country string
|
Country string
|
||||||
ZipCode string
|
ZipCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
Role string
|
Role string
|
||||||
Addr Address
|
Addr Address
|
||||||
Hobbys []string
|
Hobbys []string
|
||||||
salary int
|
salary int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Employee struct {
|
type Employee struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
Role string
|
Role string
|
||||||
Addr Address
|
Addr Address
|
||||||
Hobbys []string
|
Hobbys []string
|
||||||
salary int
|
salary int
|
||||||
}
|
}
|
||||||
|
|
||||||
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
|
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
|
||||||
|
|
||||||
employee1 := Employee{}
|
employee1 := Employee{}
|
||||||
CopyProperties(&employee1, &user)
|
CopyProperties(&employee1, &user)
|
||||||
|
|
||||||
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
|
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
|
||||||
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
|
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
|
||||||
|
|
||||||
CopyProperties(&employee2, &user)
|
CopyProperties(&employee2, &user)
|
||||||
|
|
||||||
fmt.Println(employee1)
|
fmt.Println(employee1)
|
||||||
fmt.Println(employee2)
|
fmt.Println(employee2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// {user001 10 Admin {CN 001} [a b] 0}
|
// {user001 10 Admin {CN 001} [a b] 0}
|
||||||
// {user001 10 Admin {CN 001} [a b] 500}
|
// {user001 10 Admin {CN 001} [a b] 500}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -652,45 +652,45 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Struct struct {
|
type Struct struct {
|
||||||
Str string
|
Str string
|
||||||
Int int
|
Int int
|
||||||
Float float64
|
Float float64
|
||||||
Bool bool
|
Bool bool
|
||||||
Nil interface{}
|
Nil interface{}
|
||||||
unexported string
|
unexported string
|
||||||
}
|
}
|
||||||
|
|
||||||
cases := []interface{}{
|
cases := []interface{}{
|
||||||
true,
|
true,
|
||||||
1,
|
1,
|
||||||
0.1,
|
0.1,
|
||||||
map[string]int{
|
map[string]int{
|
||||||
"a": 1,
|
"a": 1,
|
||||||
"b": 2,
|
"b": 2,
|
||||||
},
|
},
|
||||||
&Struct{
|
&Struct{
|
||||||
Str: "test",
|
Str: "test",
|
||||||
Int: 1,
|
Int: 1,
|
||||||
Float: 0.1,
|
Float: 0.1,
|
||||||
Bool: true,
|
Bool: true,
|
||||||
Nil: nil,
|
Nil: nil,
|
||||||
// unexported: "can't be cloned",
|
// unexported: "can't be cloned",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, item := range cases {
|
for _, item := range cases {
|
||||||
cloned := convertor.DeepClone(item)
|
cloned := convertor.DeepClone(item)
|
||||||
|
|
||||||
isPointerEqual := &cloned == &item
|
isPointerEqual := &cloned == &item
|
||||||
fmt.Println(cloned, isPointerEqual)
|
fmt.Println(cloned, isPointerEqual)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// true false
|
// true false
|
||||||
// 1 false
|
// 1 false
|
||||||
// 0.1 false
|
// 0.1 false
|
||||||
// map[a:1 b:2] false
|
// map[a:1 b:2] false
|
||||||
// &{test 1 0.1 true <nil> } false
|
// &{test 1 0.1 true <nil> } false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -716,43 +716,43 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
type Address struct {
|
type Address struct {
|
||||||
Country string
|
Country string
|
||||||
ZipCode string
|
ZipCode string
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
Role string
|
Role string
|
||||||
Addr Address
|
Addr Address
|
||||||
Hobbys []string
|
Hobbys []string
|
||||||
salary int
|
salary int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Employee struct {
|
type Employee struct {
|
||||||
Name string
|
Name string
|
||||||
Age int
|
Age int
|
||||||
Role string
|
Role string
|
||||||
Addr Address
|
Addr Address
|
||||||
Hobbys []string
|
Hobbys []string
|
||||||
salary int
|
salary int
|
||||||
}
|
}
|
||||||
|
|
||||||
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
|
user := User{Name: "user001", Age: 10, Role: "Admin", Addr: Address{Country: "CN", ZipCode: "001"}, Hobbys: []string{"a", "b"}, salary: 1000}
|
||||||
|
|
||||||
employee1 := Employee{}
|
employee1 := Employee{}
|
||||||
CopyProperties(&employee1, &user)
|
CopyProperties(&employee1, &user)
|
||||||
|
|
||||||
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
|
employee2 := Employee{Name: "employee001", Age: 20, Role: "User",
|
||||||
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
|
Addr: Address{Country: "UK", ZipCode: "002"}, salary: 500}
|
||||||
|
|
||||||
CopyProperties(&employee2, &user)
|
CopyProperties(&employee2, &user)
|
||||||
|
|
||||||
fmt.Println(employee1)
|
fmt.Println(employee1)
|
||||||
fmt.Println(employee2)
|
fmt.Println(employee2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// {user001 10 Admin {CN 001} [a b] 0}
|
// {user001 10 Admin {CN 001} [a b] 0}
|
||||||
// {user001 10 Admin {CN 001} [a b] 500}
|
// {user001 10 Admin {CN 001} [a b] 500}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
114
docs/strutil.md
114
docs/strutil.md
@@ -472,28 +472,28 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.Pad("foo", 1, "bar")
|
result1 := strutil.Pad("foo", 1, "bar")
|
||||||
result2 := strutil.Pad("foo", 2, "bar")
|
result2 := strutil.Pad("foo", 2, "bar")
|
||||||
result3 := strutil.Pad("foo", 3, "bar")
|
result3 := strutil.Pad("foo", 3, "bar")
|
||||||
result4 := strutil.Pad("foo", 4, "bar")
|
result4 := strutil.Pad("foo", 4, "bar")
|
||||||
result5 := strutil.Pad("foo", 5, "bar")
|
result5 := strutil.Pad("foo", 5, "bar")
|
||||||
result6 := strutil.Pad("foo", 6, "bar")
|
result6 := strutil.Pad("foo", 6, "bar")
|
||||||
result7 := strutil.Pad("foo", 7, "bar")
|
result7 := strutil.Pad("foo", 7, "bar")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
fmt.Println(result7)
|
fmt.Println(result7)
|
||||||
// Output:
|
// Output:
|
||||||
// foo
|
// foo
|
||||||
// foo
|
// foo
|
||||||
// foo
|
// foo
|
||||||
// foob
|
// foob
|
||||||
// bfoob
|
// bfoob
|
||||||
// bfooba
|
// bfooba
|
||||||
// bafooba
|
// bafooba
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -872,26 +872,26 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.SplitWords("a word")
|
result1 := strutil.SplitWords("a word")
|
||||||
result2 := strutil.SplitWords("I'am a programmer")
|
result2 := strutil.SplitWords("I'am a programmer")
|
||||||
result3 := strutil.SplitWords("Bonjour, je suis programmeur")
|
result3 := strutil.SplitWords("Bonjour, je suis programmeur")
|
||||||
result4 := strutil.SplitWords("a -b-c' 'd'e")
|
result4 := strutil.SplitWords("a -b-c' 'd'e")
|
||||||
result5 := strutil.SplitWords("你好,我是一名码农")
|
result5 := strutil.SplitWords("你好,我是一名码农")
|
||||||
result6 := strutil.SplitWords("こんにちは,私はプログラマーです")
|
result6 := strutil.SplitWords("こんにちは,私はプログラマーです")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// [a word]
|
// [a word]
|
||||||
// [I'am a programmer]
|
// [I'am a programmer]
|
||||||
// [Bonjour je suis programmeur]
|
// [Bonjour je suis programmeur]
|
||||||
// [a b-c' d'e]
|
// [a b-c' d'e]
|
||||||
// []
|
// []
|
||||||
// []
|
// []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -916,25 +916,25 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.WordCount("a word")
|
result1 := strutil.WordCount("a word")
|
||||||
result2 := strutil.WordCount("I'am a programmer")
|
result2 := strutil.WordCount("I'am a programmer")
|
||||||
result3 := strutil.WordCount("Bonjour, je suis programmeur")
|
result3 := strutil.WordCount("Bonjour, je suis programmeur")
|
||||||
result4 := strutil.WordCount("a -b-c' 'd'e")
|
result4 := strutil.WordCount("a -b-c' 'd'e")
|
||||||
result5 := strutil.WordCount("你好,我是一名码农")
|
result5 := strutil.WordCount("你好,我是一名码农")
|
||||||
result6 := strutil.WordCount("こんにちは,私はプログラマーです")
|
result6 := strutil.WordCount("こんにちは,私はプログラマーです")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 2
|
||||||
// 3
|
// 3
|
||||||
// 4
|
// 4
|
||||||
// 3
|
// 3
|
||||||
// 0
|
// 0
|
||||||
// 0
|
// 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -471,28 +471,28 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.Pad("foo", 1, "bar")
|
result1 := strutil.Pad("foo", 1, "bar")
|
||||||
result2 := strutil.Pad("foo", 2, "bar")
|
result2 := strutil.Pad("foo", 2, "bar")
|
||||||
result3 := strutil.Pad("foo", 3, "bar")
|
result3 := strutil.Pad("foo", 3, "bar")
|
||||||
result4 := strutil.Pad("foo", 4, "bar")
|
result4 := strutil.Pad("foo", 4, "bar")
|
||||||
result5 := strutil.Pad("foo", 5, "bar")
|
result5 := strutil.Pad("foo", 5, "bar")
|
||||||
result6 := strutil.Pad("foo", 6, "bar")
|
result6 := strutil.Pad("foo", 6, "bar")
|
||||||
result7 := strutil.Pad("foo", 7, "bar")
|
result7 := strutil.Pad("foo", 7, "bar")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
fmt.Println(result7)
|
fmt.Println(result7)
|
||||||
// Output:
|
// Output:
|
||||||
// foo
|
// foo
|
||||||
// foo
|
// foo
|
||||||
// foo
|
// foo
|
||||||
// foob
|
// foob
|
||||||
// bfoob
|
// bfoob
|
||||||
// bfooba
|
// bfooba
|
||||||
// bafooba
|
// bafooba
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -870,26 +870,26 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.SplitWords("a word")
|
result1 := strutil.SplitWords("a word")
|
||||||
result2 := strutil.SplitWords("I'am a programmer")
|
result2 := strutil.SplitWords("I'am a programmer")
|
||||||
result3 := strutil.SplitWords("Bonjour, je suis programmeur")
|
result3 := strutil.SplitWords("Bonjour, je suis programmeur")
|
||||||
result4 := strutil.SplitWords("a -b-c' 'd'e")
|
result4 := strutil.SplitWords("a -b-c' 'd'e")
|
||||||
result5 := strutil.SplitWords("你好,我是一名码农")
|
result5 := strutil.SplitWords("你好,我是一名码农")
|
||||||
result6 := strutil.SplitWords("こんにちは,私はプログラマーです")
|
result6 := strutil.SplitWords("こんにちは,私はプログラマーです")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// [a word]
|
// [a word]
|
||||||
// [I'am a programmer]
|
// [I'am a programmer]
|
||||||
// [Bonjour je suis programmeur]
|
// [Bonjour je suis programmeur]
|
||||||
// [a b-c' d'e]
|
// [a b-c' d'e]
|
||||||
// []
|
// []
|
||||||
// []
|
// []
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -914,25 +914,25 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
result1 := strutil.WordCount("a word")
|
result1 := strutil.WordCount("a word")
|
||||||
result2 := strutil.WordCount("I'am a programmer")
|
result2 := strutil.WordCount("I'am a programmer")
|
||||||
result3 := strutil.WordCount("Bonjour, je suis programmeur")
|
result3 := strutil.WordCount("Bonjour, je suis programmeur")
|
||||||
result4 := strutil.WordCount("a -b-c' 'd'e")
|
result4 := strutil.WordCount("a -b-c' 'd'e")
|
||||||
result5 := strutil.WordCount("你好,我是一名码农")
|
result5 := strutil.WordCount("你好,我是一名码农")
|
||||||
result6 := strutil.WordCount("こんにちは,私はプログラマーです")
|
result6 := strutil.WordCount("こんにちは,私はプログラマーです")
|
||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
fmt.Println(result3)
|
fmt.Println(result3)
|
||||||
fmt.Println(result4)
|
fmt.Println(result4)
|
||||||
fmt.Println(result5)
|
fmt.Println(result5)
|
||||||
fmt.Println(result6)
|
fmt.Println(result6)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// 2
|
// 2
|
||||||
// 3
|
// 3
|
||||||
// 4
|
// 4
|
||||||
// 3
|
// 3
|
||||||
// 0
|
// 0
|
||||||
// 0
|
// 0
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
Reference in New Issue
Block a user