@@ -105,36 +105,6 @@ func ExampleCompare_search() {
105
105
}
106
106
}
107
107
108
- func ExampleTrimSuffix () {
109
- var b = []byte ("Hello, goodbye, etc!" )
110
- b = bytes .TrimSuffix (b , []byte ("goodbye, etc!" ))
111
- b = bytes .TrimSuffix (b , []byte ("gopher" ))
112
- b = append (b , bytes .TrimSuffix ([]byte ("world!" ), []byte ("x!" ))... )
113
- os .Stdout .Write (b )
114
- // Output: Hello, world!
115
- }
116
-
117
- func ExampleTrimPrefix () {
118
- var b = []byte ("Goodbye,, world!" )
119
- b = bytes .TrimPrefix (b , []byte ("Goodbye," ))
120
- b = bytes .TrimPrefix (b , []byte ("See ya," ))
121
- fmt .Printf ("Hello%s" , b )
122
- // Output: Hello, world!
123
- }
124
-
125
- func ExampleFields () {
126
- fmt .Printf ("Fields are: %q" , bytes .Fields ([]byte (" foo bar baz " )))
127
- // Output: Fields are: ["foo" "bar" "baz"]
128
- }
129
-
130
- func ExampleFieldsFunc () {
131
- f := func (c rune ) bool {
132
- return ! unicode .IsLetter (c ) && ! unicode .IsNumber (c )
133
- }
134
- fmt .Printf ("Fields are: %q" , bytes .FieldsFunc ([]byte (" foo1;bar2,baz3..." ), f ))
135
- // Output: Fields are: ["foo1" "bar2" "baz3"]
136
- }
137
-
138
108
func ExampleContains () {
139
109
fmt .Println (bytes .Contains ([]byte ("seafood" ), []byte ("foo" )))
140
110
fmt .Println (bytes .Contains ([]byte ("seafood" ), []byte ("bar" )))
@@ -181,6 +151,22 @@ func ExampleCount() {
181
151
// 5
182
152
}
183
153
154
+ func ExampleCut () {
155
+ show := func (s , sep string ) {
156
+ before , after , found := bytes .Cut ([]byte (s ), []byte (sep ))
157
+ fmt .Printf ("Cut(%q, %q) = %q, %q, %v\n " , s , sep , before , after , found )
158
+ }
159
+ show ("Gopher" , "Go" )
160
+ show ("Gopher" , "ph" )
161
+ show ("Gopher" , "er" )
162
+ show ("Gopher" , "Badger" )
163
+ // Output:
164
+ // Cut("Gopher", "Go") = "", "pher", true
165
+ // Cut("Gopher", "ph") = "Go", "er", true
166
+ // Cut("Gopher", "er") = "Goph", "", true
167
+ // Cut("Gopher", "Badger") = "Gopher", "", false
168
+ }
169
+
184
170
func ExampleEqual () {
185
171
fmt .Println (bytes .Equal ([]byte ("Go" ), []byte ("Go" )))
186
172
fmt .Println (bytes .Equal ([]byte ("Go" ), []byte ("C++" )))
@@ -194,6 +180,19 @@ func ExampleEqualFold() {
194
180
// Output: true
195
181
}
196
182
183
+ func ExampleFields () {
184
+ fmt .Printf ("Fields are: %q" , bytes .Fields ([]byte (" foo bar baz " )))
185
+ // Output: Fields are: ["foo" "bar" "baz"]
186
+ }
187
+
188
+ func ExampleFieldsFunc () {
189
+ f := func (c rune ) bool {
190
+ return ! unicode .IsLetter (c ) && ! unicode .IsNumber (c )
191
+ }
192
+ fmt .Printf ("Fields are: %q" , bytes .FieldsFunc ([]byte (" foo1;bar2,baz3..." ), f ))
193
+ // Output: Fields are: ["foo1" "bar2" "baz3"]
194
+ }
195
+
197
196
func ExampleHasPrefix () {
198
197
fmt .Println (bytes .HasPrefix ([]byte ("Gopher" ), []byte ("Go" )))
199
198
fmt .Println (bytes .HasPrefix ([]byte ("Gopher" ), []byte ("C" )))
@@ -259,6 +258,12 @@ func ExampleIndexRune() {
259
258
// -1
260
259
}
261
260
261
+ func ExampleJoin () {
262
+ s := [][]byte {[]byte ("foo" ), []byte ("bar" ), []byte ("baz" )}
263
+ fmt .Printf ("%s" , bytes .Join (s , []byte (", " )))
264
+ // Output: foo, bar, baz
265
+ }
266
+
262
267
func ExampleLastIndex () {
263
268
fmt .Println (bytes .Index ([]byte ("go gopher" ), []byte ("go" )))
264
269
fmt .Println (bytes .LastIndex ([]byte ("go gopher" ), []byte ("go" )))
@@ -299,10 +304,12 @@ func ExampleLastIndexFunc() {
299
304
// -1
300
305
}
301
306
302
- func ExampleJoin () {
303
- s := [][]byte {[]byte ("foo" ), []byte ("bar" ), []byte ("baz" )}
304
- fmt .Printf ("%s" , bytes .Join (s , []byte (", " )))
305
- // Output: foo, bar, baz
307
+ func ExampleReader_Len () {
308
+ fmt .Println (bytes .NewReader ([]byte ("Hi!" )).Len ())
309
+ fmt .Println (bytes .NewReader ([]byte ("こんにちは!" )).Len ())
310
+ // Output:
311
+ // 3
312
+ // 16
306
313
}
307
314
308
315
func ExampleRepeat () {
@@ -412,20 +419,6 @@ func ExampleTrimFunc() {
412
419
// go-gopher!
413
420
}
414
421
415
- func ExampleMap () {
416
- rot13 := func (r rune ) rune {
417
- switch {
418
- case r >= 'A' && r <= 'Z' :
419
- return 'A' + (r - 'A' + 13 )% 26
420
- case r >= 'a' && r <= 'z' :
421
- return 'a' + (r - 'a' + 13 )% 26
422
- }
423
- return r
424
- }
425
- fmt .Printf ("%s" , bytes .Map (rot13 , []byte ("'Twas brillig and the slithy gopher..." )))
426
- // Output: 'Gjnf oevyyvt naq gur fyvgul tbcure...
427
- }
428
-
429
422
func ExampleTrimLeft () {
430
423
fmt .Print (string (bytes .TrimLeft ([]byte ("453gopher8257" ), "0123456789" )))
431
424
// Output:
@@ -442,11 +435,28 @@ func ExampleTrimLeftFunc() {
442
435
// go-gopher!567
443
436
}
444
437
438
+ func ExampleTrimPrefix () {
439
+ var b = []byte ("Goodbye,, world!" )
440
+ b = bytes .TrimPrefix (b , []byte ("Goodbye," ))
441
+ b = bytes .TrimPrefix (b , []byte ("See ya," ))
442
+ fmt .Printf ("Hello%s" , b )
443
+ // Output: Hello, world!
444
+ }
445
+
445
446
func ExampleTrimSpace () {
446
447
fmt .Printf ("%s" , bytes .TrimSpace ([]byte (" \t \n a lone gopher \n \t \r \n " )))
447
448
// Output: a lone gopher
448
449
}
449
450
451
+ func ExampleTrimSuffix () {
452
+ var b = []byte ("Hello, goodbye, etc!" )
453
+ b = bytes .TrimSuffix (b , []byte ("goodbye, etc!" ))
454
+ b = bytes .TrimSuffix (b , []byte ("gopher" ))
455
+ b = append (b , bytes .TrimSuffix ([]byte ("world!" ), []byte ("x!" ))... )
456
+ os .Stdout .Write (b )
457
+ // Output: Hello, world!
458
+ }
459
+
450
460
func ExampleTrimRight () {
451
461
fmt .Print (string (bytes .TrimRight ([]byte ("453gopher8257" ), "0123456789" )))
452
462
// Output:
@@ -463,21 +473,6 @@ func ExampleTrimRightFunc() {
463
473
// 1234go-gopher!
464
474
}
465
475
466
- func ExampleToUpper () {
467
- fmt .Printf ("%s" , bytes .ToUpper ([]byte ("Gopher" )))
468
- // Output: GOPHER
469
- }
470
-
471
- func ExampleToUpperSpecial () {
472
- str := []byte ("ahoj vývojári golang" )
473
- totitle := bytes .ToUpperSpecial (unicode .AzeriCase , str )
474
- fmt .Println ("Original : " + string (str ))
475
- fmt .Println ("ToUpper : " + string (totitle ))
476
- // Output:
477
- // Original : ahoj vývojári golang
478
- // ToUpper : AHOJ VÝVOJÁRİ GOLANG
479
- }
480
-
481
476
func ExampleToLower () {
482
477
fmt .Printf ("%s" , bytes .ToLower ([]byte ("Gopher" )))
483
478
// Output: gopher
@@ -493,10 +488,17 @@ func ExampleToLowerSpecial() {
493
488
// ToLower : ahoj vývojári golang
494
489
}
495
490
496
- func ExampleReader_Len () {
497
- fmt .Println (bytes .NewReader ([]byte ("Hi!" )).Len ())
498
- fmt .Println (bytes .NewReader ([]byte ("こんにちは!" )).Len ())
491
+ func ExampleToUpper () {
492
+ fmt .Printf ("%s" , bytes .ToUpper ([]byte ("Gopher" )))
493
+ // Output: GOPHER
494
+ }
495
+
496
+ func ExampleToUpperSpecial () {
497
+ str := []byte ("ahoj vývojári golang" )
498
+ totitle := bytes .ToUpperSpecial (unicode .AzeriCase , str )
499
+ fmt .Println ("Original : " + string (str ))
500
+ fmt .Println ("ToUpper : " + string (totitle ))
499
501
// Output:
500
- // 3
501
- // 16
502
+ // Original : ahoj vývojári golang
503
+ // ToUpper : AHOJ VÝVOJÁRİ GOLANG
502
504
}
0 commit comments