diff options
| author | Shulhan <ms@kilabit.info> | 2018-09-16 05:37:37 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-09-17 22:51:20 +0700 |
| commit | cdcee0eb01305a18b330d2e3c811091fe5164c11 (patch) | |
| tree | 9f6acffa5fb9d29ff041d0c137e39908638af789 /lib/strings/string_example_test.go | |
| parent | e914833fa2b0a99fc726c313d594f31ab6b132ba (diff) | |
| download | pakakeh.go-cdcee0eb01305a18b330d2e3c811091fe5164c11.tar.xz | |
Merge package "github.com/shuLhan/tekstus", part 2/3
Diffstat (limited to 'lib/strings/string_example_test.go')
| -rw-r--r-- | lib/strings/string_example_test.go | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/lib/strings/string_example_test.go b/lib/strings/string_example_test.go new file mode 100644 index 00000000..6c91c4d8 --- /dev/null +++ b/lib/strings/string_example_test.go @@ -0,0 +1,87 @@ +// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package strings + +import ( + "fmt" +) + +func ExampleCleanURI() { + text := `You can visit ftp://hostname or https://hostname/link%202 for more information` + + fmt.Printf("%s\n", CleanURI(text)) + // Output: You can visit or for more information +} + +func ExampleCleanWikiMarkup() { + text := `* Test image [[Image:fileto.png]].` + + fmt.Printf("%s\n", CleanWikiMarkup(text)) + // Output: * Test image . +} + +func ExampleMergeSpaces() { + line := " a\n\nb c d\n\n" + fmt.Printf("Without merging newline: '%s'\n", MergeSpaces(line, false)) + fmt.Printf("With merging newline: '%s'\n", MergeSpaces(line, true)) + // Output: + // Without merging newline: ' a + // + // b c d + // + // ' + // With merging newline: ' a + // b c d + // ' +} + +func ExampleSplit() { + line := `a b c [A] B C` + fmt.Printf("%s\n", Split(line, false, false)) + fmt.Printf("%s\n", Split(line, true, false)) + fmt.Printf("%s\n", Split(line, false, true)) + fmt.Printf("%s\n", Split(line, true, true)) + // Output: + // [a b c [A] B C] + // [a b c A B C] + // [a b c [A] B C] + // [a b c] +} + +func ExampleTrimNonAlnum() { + inputs := []string{ + "[[alpha]]", + "[[alpha", + "alpha]]", + "alpha", + "alpha0", + "1alpha", + "1alpha0", + "[][][]", + } + + for _, in := range inputs { + fmt.Printf("'%s'\n", TrimNonAlnum(in)) + } + // Output: + // 'alpha' + // 'alpha' + // 'alpha' + // 'alpha' + // 'alpha0' + // '1alpha' + // '1alpha0' + // '' +} + +func ExampleUniq() { + words := []string{"a", "", "A"} + fmt.Printf("%s %s\n", Uniq(words, false), words) + words = []string{"a", "", "A"} + fmt.Printf("%s %s\n", Uniq(words, true), words) + // Output: + // [a] [a ] + // [a A] [a A] +} |
