Repository navigation
Expand file tree
/
Copy pathexample_test.go
More file actions
57 lines (45 loc) · 1.79 KB
/
Copy pathexample_test.go
File metadata and controls
57 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package uax14_test
import (
"fmt"
"github.com/SCKelemen/unicode/v6/uax14"
)
func ExampleFindLineBreakOpportunities() {
text := "Hello world! How are you?"
breaks := uax14.FindLineBreakOpportunities(text, uax14.HyphensManual)
fmt.Println("Break positions:", breaks)
// Output: Break positions: [0 6 13 17 21 25]
}
func ExampleFindLineBreakOpportunities_withSoftHyphens() {
// Soft hyphen (U+00AD) between "super" and "cali"
text := "super\u00ADcalifragilistic"
// With HyphensManual, breaks are allowed at soft hyphens
breaks := uax14.FindLineBreakOpportunities(text, uax14.HyphensManual)
fmt.Println("Manual hyphens:", breaks)
// With HyphensNone, no hyphenation breaks
breaksNone := uax14.FindLineBreakOpportunities(text, uax14.HyphensNone)
fmt.Println("No hyphens:", breaksNone)
// Output:
// Manual hyphens: [0 7 22]
// No hyphens: [0 22]
}
func ExampleFindLineBreakOpportunities_wrapping() {
text := "The quick brown fox jumps"
breaks := uax14.FindLineBreakOpportunities(text, uax14.HyphensManual)
// Simple demonstration of using break positions
fmt.Println("Text:", text)
fmt.Println("Break opportunities:", breaks)
fmt.Println("Can break after: 'The ', 'quick ', 'brown ', 'fox '")
// Output:
// Text: The quick brown fox jumps
// Break opportunities: [0 4 10 16 20 25]
// Can break after: 'The ', 'quick ', 'brown ', 'fox '
}
func ExampleFindLineBreakOpportunities_cjk() {
// Chinese/Japanese text can break between characters
// Hiragana (こんにちは) and Kanji (世界) are both classified as ID (Ideographic)
// allowing breaks between each character per UAX #14
text := "こんにちは世界"
breaks := uax14.FindLineBreakOpportunities(text, uax14.HyphensManual)
fmt.Printf("Text has %d break opportunities\n", len(breaks))
// Output: Text has 8 break opportunities
}