File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ package exstrings
9
9
import (
10
10
"crypto/sha256"
11
11
"crypto/subtle"
12
+ "strings"
12
13
"unsafe"
13
14
)
14
15
@@ -30,3 +31,24 @@ func SHA256(str string) [32]byte {
30
31
func ConstantTimeEqual (a , b string ) bool {
31
32
return subtle .ConstantTimeCompare (UnsafeBytes (a ), UnsafeBytes (b )) == 1
32
33
}
34
+
35
+ func LongestSequenceOf (a string , b rune ) int {
36
+ // IndexRune has some optimizations, so use it to find the starting point
37
+ firstIndex := strings .IndexRune (a , b )
38
+ if firstIndex == - 1 {
39
+ return 0
40
+ }
41
+ count := 0
42
+ maxCount := 0
43
+ for _ , r := range a [firstIndex :] {
44
+ if r == b {
45
+ count ++
46
+ if count > maxCount {
47
+ maxCount = count
48
+ }
49
+ } else {
50
+ count = 0
51
+ }
52
+ }
53
+ return maxCount
54
+ }
You can’t perform that action at this time.
0 commit comments