mirror of
https://github.com/ddworken/hishtory.git
synced 2025-06-20 11:57:50 +02:00
Simplify stripBackslash
This commit is contained in:
parent
4b5b729328
commit
2ae54ef74e
@ -1274,13 +1274,11 @@ func containsUnescaped(query string, token string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func stripBackslash(query string) string {
|
func stripBackslash(query string) string {
|
||||||
runeQuery := []rune(query)
|
|
||||||
var newQuery []rune
|
var newQuery []rune
|
||||||
for i := 0; i < len(runeQuery); i++ {
|
for _, char := range query {
|
||||||
if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
|
if char != '\\' {
|
||||||
i++
|
newQuery = append(newQuery, char)
|
||||||
}
|
}
|
||||||
newQuery = append(newQuery, runeQuery[i])
|
|
||||||
}
|
}
|
||||||
return string(newQuery)
|
return string(newQuery)
|
||||||
}
|
}
|
||||||
|
@ -489,6 +489,9 @@ func TestStripBackslash(t *testing.T) {
|
|||||||
{"f \\bar", "f bar"},
|
{"f \\bar", "f bar"},
|
||||||
{"f\\:bar", "f:bar"},
|
{"f\\:bar", "f:bar"},
|
||||||
{"f\\:bar\\", "f:bar"},
|
{"f\\:bar\\", "f:bar"},
|
||||||
|
{"\\f\\:bar\\", "f:bar"},
|
||||||
|
{"", ""},
|
||||||
|
{"\\\\", ""},
|
||||||
}
|
}
|
||||||
for _, tc := range testcases {
|
for _, tc := range testcases {
|
||||||
actual := stripBackslash(tc.input)
|
actual := stripBackslash(tc.input)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user