Search case sensitive and word boundary
This commit is contained in:
@@ -206,26 +206,54 @@ API String NormalizePath(Allocator allocator, String s) {
|
||||
|
||||
API bool Seek(String string, String 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;
|
||||
String substring = GetSlice(string, index, index + find.len);
|
||||
int64_t index = i - 1;
|
||||
String 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) {
|
||||
String left = GetSlice(string, i - 1, i);
|
||||
String 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++) {
|
||||
String 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) {
|
||||
String left = GetSlice(string, i - 1, i);
|
||||
String 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ enum {
|
||||
SeekFlag_None = 0,
|
||||
SeekFlag_IgnoreCase = 1,
|
||||
SeekFlag_MatchFindLast = 2,
|
||||
SeekFlag_WordBoundary = 4,
|
||||
};
|
||||
API bool Seek(String string, String find, int64_t *index_out = NULL, SeekFlag flags = SeekFlag_None);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user