Skip to content

Commit a3028b1

Browse files
authored
Merge pull request #768 from devlights/add-result-in-example
2 parents 37d6136 + cc5a805 commit a3028b1

File tree

10 files changed

+186
-10
lines changed

10 files changed

+186
-10
lines changed

examples/basic/strs/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
このディレクトリには以下のサンプルがあります。
44

5-
| file | example name | note |
6-
|--------------------------------|-------------------------------------|--------------------------------------------------------------|
7-
| rune\_rawstring.go | string\_rune\_rawstring | Go言語における 文字と文字列とRaw文字列についてのサンプルです. |
8-
| to\_runeslice.go | string\_to\_runeslice | 文字列とルーンスライスの遷移を表示するサンプルです. |
9-
| rune\_byte\_convert.go | string\_rune\_byte\_convert | 文字列とルーンとバイト列の変換のサンプルです. |
10-
| chop\_newline.go | string\_chop\_newline | 文字列末尾の改行を削除するサンプルです. |
11-
| using\_builder.go | string\_using\_builder | strings.Builder を利用したサンプルです. |
12-
| rune\_count.go | string\_rune\_count | utf8.RuneCountInString() のサンプルです. |
13-
| diff\_trimright\_trimsuffix.go | string\_diff\_trimright\_trimsuffix | strings.TrimRight と strings.TrimSuffix のちょっとした違いについてのサンプルです. |
14-
| using\_string\_clone.go | string\_using\_clone | Go 1.18 で追加された strings.Clone() のサンプルです |
5+
| file | example name | note |
6+
| ---------------------------- | -------------------------------- | --------------------------------------------------------------------------------- |
7+
| rune_rawstring.go | string_rune_rawstring | Go言語における 文字と文字列とRaw文字列についてのサンプルです. |
8+
| to_runeslice.go | string_to_runeslice | 文字列とルーンスライスの遷移を表示するサンプルです. |
9+
| rune_byte_convert.go | string_rune_byte_convert | 文字列とルーンとバイト列の変換のサンプルです. |
10+
| chop_newline.go | string_chop_newline | 文字列末尾の改行を削除するサンプルです. |
11+
| using_builder.go | string_using_builder | strings.Builder を利用したサンプルです. |
12+
| rune_count.go | string_rune_count | utf8.RuneCountInString() のサンプルです. |
13+
| diff_trimright_trimsuffix.go | string_diff_trimright_trimsuffix | strings.TrimRight と strings.TrimSuffix のちょっとした違いについてのサンプルです. |
14+
| using_string_clone.go | string_using_clone | Go 1.18 で追加された strings.Clone() のサンプルです |

examples/basic/strs/chop_newline.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,33 @@ func ChopNewLine() error {
3535
output.Stdoutl("[without ]", []byte(withoutNewLine))
3636

3737
return nil
38+
39+
/*
40+
$ task
41+
task: [build] go build .
42+
task: [run] ./try-golang -onetime
43+
44+
ENTER EXAMPLE NAME: string_chop_newline
45+
46+
[Name] "string_chop_newline"
47+
[has newline? (withLF) ] true
48+
[has newline? (withCRLF) ] true
49+
[has newline? (withoutNewLine) ] false
50+
[has newline? (chopped)(LF) ] false
51+
[equal? (chopped==withoutNewLine)] true
52+
[has newline? (chopped)(CRLF) ] false
53+
[equal? (chopped==withoutNewLine)] true
54+
--------------------------------------------------
55+
[LF ] [104 101 108 108 111 119 111 114 108 100 10]
56+
[CRLF ] [104 101 108 108 111 119 111 114 108 100 13 10]
57+
[chopLF ] [104 101 108 108 111 119 111 114 108 100]
58+
[chopCRLF] [104 101 108 108 111 119 111 114 108 100]
59+
[without ] [104 101 108 108 111 119 111 114 108 100]
60+
61+
62+
[Elapsed] 77.92µs
63+
*/
64+
3865
}
3966

4067
func chop(s string) string {

examples/basic/strs/cut_prefix_suffix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,20 @@ func CutPrefixSuffix() error {
3737
output.Stdoutl("[CutSuffix]", cut2)
3838

3939
return nil
40+
41+
/*
42+
$ task
43+
task: [build] go build .
44+
task: [run] ./try-golang -onetime
45+
46+
ENTER EXAMPLE NAME: string_cut_prefix_suffix
47+
48+
[Name] "string_cut_prefix_suffix"
49+
[CutPrefix] 12345world
50+
[CutSuffix] hello12345
51+
52+
53+
[Elapsed] 18.22µs
54+
*/
55+
4056
}

examples/basic/strs/diff_trimright_trimsuffix.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,20 @@ func DiffTrimRightAndTrimSuffix() error {
2626
output.Stdoutl("[TrimSuffix]", strings.TrimSuffix(str, "xo"))
2727

2828
return nil
29+
30+
/*
31+
$ task
32+
task: [build] go build .
33+
task: [run] ./try-golang -onetime
34+
35+
ENTER EXAMPLE NAME: string_diff_trimright_trimsuffix
36+
37+
[Name] "string_diff_trimright_trimsuffix"
38+
[TrimRight ] こんにちわ世界
39+
[TrimSuffix] こんにちわ世界xox
40+
41+
42+
[Elapsed] 11.53µs
43+
*/
44+
2945
}

examples/basic/strs/rune_byte_convert.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,31 @@ func RuneByteConvert() error {
7373
fmt.Printf("%s(%v)\n", buf, buf)
7474

7575
return nil
76+
77+
/*
78+
$ task
79+
task: [build] go build .
80+
task: [run] ./try-golang -onetime
81+
82+
ENTER EXAMPLE NAME: string_rune_byte_convert
83+
84+
[Name] "string_rune_byte_convert"
85+
len(s) == 20
86+
len(r) == 10
87+
rune[0] 3 byte(s)
88+
rune[1] 3 byte(s)
89+
rune[2] 3 byte(s)
90+
rune[3] 3 byte(s)
91+
rune[4] 3 byte(s)
92+
rune[5] 1 byte(s)
93+
rune[6] 1 byte(s)
94+
rune[7] 1 byte(s)
95+
rune[8] 1 byte(s)
96+
rune[9] 1 byte(s)
97+
こんにちわworld([227 129 147 227 130 147 227 129 171 227 129 161 227 130 143 119 111 114 108 100])
98+
99+
100+
[Elapsed] 88.64µs
101+
*/
102+
76103
}

examples/basic/strs/rune_count.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,23 @@ func RuneCount() error {
3535
output.Stdoutf("[5]", "%q\t%d rune(s)\t%d byte(s)\n", s5, c5, len(s5))
3636

3737
return nil
38+
39+
/*
40+
$ task
41+
task: [build] go build .
42+
task: [run] ./try-golang -onetime
43+
44+
ENTER EXAMPLE NAME: string_rune_count
45+
46+
[Name] "string_rune_count"
47+
[1] "h" 1 rune(s) 1 byte(s)
48+
[2] "あ" 1 rune(s) 3 byte(s)
49+
[3] "😺" 1 rune(s) 4 byte(s)
50+
[4] "🧑\u200d🤝\u200d🧑" 5 rune(s) 18 byte(s)
51+
[5] "👨\u200d👩\u200d👧\u200d👦" 7 rune(s) 25 byte(s)
52+
53+
54+
[Elapsed] 59.39µs
55+
*/
56+
3857
}

examples/basic/strs/rune_rawstring.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,25 @@ func RuneRawString() error {
3737
fmt.Printf("%s, %s\n", string2, string4)
3838

3939
return nil
40+
41+
/*
42+
$ task
43+
task: Task "build" is up to date
44+
task: [run] ./try-golang -onetime
45+
46+
ENTER EXAMPLE NAME: string_rune_rawstring
47+
48+
[Name] "string_rune_rawstring"
49+
[]int32, string, string
50+
[U+3053 'こ' U+3093 'ん' U+306B 'に' U+3061 'ち' U+306F 'は'], こんにちは, aaaa \nbbbb
51+
[12354 12356 12358]
52+
[227 129 130 227 129 132 227 129 134]
53+
len(rune2): 3, len(bytes1): 9
54+
あいう, あいう
55+
あいう, あいう
56+
57+
58+
[Elapsed] 58.851µs
59+
*/
60+
4061
}

examples/basic/strs/to_runeslice.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,19 @@ func ToRuneSlice() error {
2222
fmt.Printf("Before:\t%q\tAfter:\t%q\tRune:%v\n", s, s2, r)
2323

2424
return nil
25+
26+
/*
27+
$ task
28+
task: [build] go build .
29+
task: [run] ./try-golang -onetime
30+
31+
ENTER EXAMPLE NAME: string_to_runeslice
32+
33+
[Name] "string_to_runeslice"
34+
Before: "hello world" After: "Hello world" Rune:[72 101 108 108 111 32 119 111 114 108 100]
35+
36+
37+
[Elapsed] 22.48µs
38+
*/
39+
2540
}

examples/basic/strs/using_builder.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,19 @@ func UsingBuilder() error {
1919
output.Stdoutl("builder", builder.String())
2020

2121
return nil
22+
23+
/*
24+
$ task
25+
task: [build] go build .
26+
task: [run] ./try-golang -onetime
27+
28+
ENTER EXAMPLE NAME: string_using_builder
29+
30+
[Name] "string_using_builder"
31+
builder hello world
32+
33+
34+
[Elapsed] 12.27µs
35+
*/
36+
2237
}

examples/basic/strs/using_strings_clone.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,24 @@ func UsingStringsClone() error {
7373
}
7474

7575
return nil
76+
77+
/*
78+
$ task
79+
task: [build] go build .
80+
task: [run] ./try-golang -onetime
81+
82+
ENTER EXAMPLE NAME: string_using_clone
83+
84+
[Name] "string_using_clone"
85+
[store1] 0: rq0Py
86+
[store2] 0: rq0Py
87+
[store1] 1: VtRco
88+
[store2] 1: VtRco
89+
[store1] 2: MSL1F
90+
[store2] 2: MSL1F
91+
92+
93+
[Elapsed] 540.617051ms
94+
*/
95+
7696
}

0 commit comments

Comments
 (0)