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 {
|
||||
runeQuery := []rune(query)
|
||||
var newQuery []rune
|
||||
for i := 0; i < len(runeQuery); i++ {
|
||||
if runeQuery[i] == '\\' && i+1 < len(runeQuery) {
|
||||
i++
|
||||
for _, char := range query {
|
||||
if char != '\\' {
|
||||
newQuery = append(newQuery, char)
|
||||
}
|
||||
newQuery = append(newQuery, runeQuery[i])
|
||||
}
|
||||
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"},
|
||||
{"", ""},
|
||||
{"\\\\", ""},
|
||||
}
|
||||
for _, tc := range testcases {
|
||||
actual := stripBackslash(tc.input)
|
||||
|
Loading…
x
Reference in New Issue
Block a user