@@ -33,19 +33,23 @@ func Token(argv1 string, argv2 string, epoch int) string {
33
33
34
34
// Squeeze remove redundant characters from the given string
35
35
// Arguments:
36
- // - argv1 (string): String including redundant characters like "neko chan"
37
- // - chars (string): Characters to be squeezed, for example " "
36
+ // - argv0 (string): String including redundant characters like "neko chan"
37
+ // - argv1 (string): Characters to be squeezed, for example " "
38
38
// Returns:
39
39
// - (string): Squeezed string such as "neko chan"
40
- func Squeeze (argv1 string , chars string ) string {
41
- if argv1 == "" { return "" }
42
- if len (chars ) == 0 { return argv1 }
40
+ func Squeeze (argv0 string , argv1 byte ) string {
41
+ if argv0 == "" { return "" }
43
42
44
- for strings .Contains (argv1 , chars + chars ) {
45
- // Remove redundant characters from "argv1"
46
- argv1 = strings .ReplaceAll (argv1 , chars + chars , chars )
43
+ bytebuffer := []byte (argv0 )
44
+ textbuffer := make ([]byte , 0 , len (bytebuffer ))
45
+
46
+ cb := byte (0 ); for _ , by := range bytebuffer {
47
+ // Remove a character that is the same character of the previous character
48
+ if by == argv1 && by == cb { continue }
49
+ textbuffer = append (textbuffer , by )
50
+ cb = by
47
51
}
48
- return argv1
52
+ return string ( textbuffer )
49
53
}
50
54
51
55
// Sweep clears the string out.
@@ -56,7 +60,7 @@ func Squeeze(argv1 string, chars string) string {
56
60
func Sweep (argv1 string ) string {
57
61
if argv1 == "" { return "" }
58
62
59
- argv1 = Squeeze (strings .TrimSpace (strings .ReplaceAll (argv1 , "\t " , " " )), " " )
63
+ argv1 = Squeeze (strings .TrimSpace (strings .ReplaceAll (argv1 , "\t " , " " )), ' ' )
60
64
for strings .Contains (argv1 , " --" ) {
61
65
// Delete all the string after a boundary string like " --neko-chan"
62
66
if strings .Contains (argv1 , "-- " ) { break }
0 commit comments