mirror of
https://github.com/duke-git/lancet.git
synced 2026-11-16 05:12:11 +08:00
fix(strutil): preserve IndexOffset not-found results (#367)
This commit is contained in:
1 parent
34c7e36d29
commit
99ed115de4
2 files changed
+6
-1
No files matched your search
+4
-1
@@ -483,7 +483,10 @@ func IndexOffset(str string, substr string, idxFrom int) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
return strings.Index(str[idxFrom:], substr) + idxFrom
|
||||
if index := strings.Index(str[idxFrom:], substr); index >= 0 {
|
||||
return index + idxFrom
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
// ReplaceWithMap returns a copy of `str`,
|
||||
|
||||
@@ -660,6 +660,8 @@ func TestIndexOffset(t *testing.T) {
|
||||
{str, "d", len(str) - 1, len(str) - 1},
|
||||
{str, "d", len(str), -1},
|
||||
{str, "f", -1, -1},
|
||||
{str, "missing", 5, -1},
|
||||
{str, "foo", 5, -1},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
|
||||
Reference in new issue
Block a user