-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.go
More file actions
59 lines (48 loc) · 1.32 KB
/
stack.go
File metadata and controls
59 lines (48 loc) · 1.32 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
58
59
package prm
// Default stack what will be used by ctx
var dStack = []SkipFunc{
SkipIfFirst,
SkipIfPrev,
SkipIfAbbrev,
SkipIfApos,
}
// SetStack are allowing to set
// a new runes skipping stack
func SetStack(stack []SkipFunc) {
dStack = stack
}
// SkipFunc type for runes skipping checks.
// If function is returing a true value then
// the letter (with index of j) will be skiped
type SkipFunc func(i, j int, lttrs []rune, sep rune) bool
// SkipIfFirst checks if a letter is first
// it will remove itself from the stack if a passed
// letters index isn't zero
func SkipIfFirst(i, j int, lttrs []rune, sep rune) (skip bool) {
if i == 0 {
skip = true
}
return
}
// SkipIfPrev checks if a previous letter is a separator
func SkipIfPrev(i, j int, lttrs []rune, sep rune) (skip bool) {
if lttrs[i-1] == sep {
skip = true
}
return
}
// SkipIfAbbrev checks if a previous letter is an uppercase ASCII
// and next one is an uppercase rune too
func SkipIfAbbrev(i, j int, lttrs []rune, sep rune) (skip bool) {
if isUpper(lttrs[i-1]) && (len(lttrs)-1 > j && isUpper(lttrs[j+1])) {
skip = true
}
return
}
// SkipIfApos checks if a previous rune was a letter and current one is an apostrophe
func SkipIfApos(i, j int, lttrs []rune, sep rune) (skip bool) {
if !notLoN(lttrs[i-1]) && lttrs[j] == '\'' {
skip = true
}
return
}