We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1de030f commit d2d18a7Copy full SHA for d2d18a7
exstrings/stringutil.go
@@ -9,6 +9,7 @@ package exstrings
9
import (
10
"crypto/sha256"
11
"crypto/subtle"
12
+ "strings"
13
"unsafe"
14
)
15
@@ -30,3 +31,24 @@ func SHA256(str string) [32]byte {
30
31
func ConstantTimeEqual(a, b string) bool {
32
return subtle.ConstantTimeCompare(UnsafeBytes(a), UnsafeBytes(b)) == 1
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
+}
0 commit comments