Search case sensitive and word boundary

This commit is contained in:
Krzosa Karol
2025-12-27 15:54:10 +01:00
parent b6f3a1ebec
commit e4b84dde90
7 changed files with 110 additions and 32 deletions

View File

@@ -216,26 +216,54 @@ API String16 NormalizePath(Allocator allocator, String16 s) {
API bool Seek(String16 string, String16 find, int64_t *index_out, SeekFlag flags) {
bool ignore_case = flags & SeekFlag_IgnoreCase ? true : false;
bool result = false;
bool result = false;
if (flags & SeekFlag_MatchFindLast) {
for (int64_t i = string.len; i != 0; i--) {
int64_t index = i - 1;
String16 substring = GetSlice(string, index, index + find.len);
int64_t index = i - 1;
String16 substring = GetSlice(string, index, index + find.len);
if (AreEqual(substring, find, ignore_case)) {
if (index_out)
*index_out = index;
result = true;
break;
bool ok_boundary = true;
if (flags & SeekFlag_WordBoundary) {
String16 left = GetSlice(string, i - 1, i);
String16 right = GetSlice(string, i + find.len, i + find.len + 1);
if (left.len != 0 && !IsNonWord(left.data[0])) {
ok_boundary = false;
}
if (right.len != 0 && !IsNonWord(right.data[0])) {
ok_boundary = false;
}
}
if (ok_boundary) {
if (index_out) {
*index_out = index;
}
result = true;
break;
}
}
}
} else {
for (int64_t i = 0; i < string.len; i++) {
String16 substring = GetSlice(string, i, i + find.len);
if (AreEqual(substring, find, ignore_case)) {
if (index_out)
*index_out = i;
result = true;
break;
bool ok_boundary = true;
if (flags & SeekFlag_WordBoundary) {
String16 left = GetSlice(string, i - 1, i);
String16 right = GetSlice(string, i + find.len, i + find.len + 1);
if (left.len != 0 && !IsNonWord(left.data[0])) {
ok_boundary = false;
}
if (right.len != 0 && !IsNonWord(right.data[0])) {
ok_boundary = false;
}
}
if (ok_boundary) {
if (index_out) {
*index_out = i;
}
result = true;
break;
}
}
}
}