Editing infobar applies changes to buffer

This commit is contained in:
Krzosa Karol
2024-07-31 07:32:42 +02:00
parent 2ab1917b73
commit be99b0aabb
9 changed files with 164 additions and 38 deletions

View File

@@ -150,3 +150,42 @@ String16 CutPostfix(String16 *string, int64_t len) {
*string = Chop(*string, len);
return result;
}
String16 Trim(String16 string) {
if (string.len == 0)
return string;
int64_t whitespace_begin = 0;
for (; whitespace_begin < string.len; whitespace_begin++) {
if (!IsWhitespace(string.data[whitespace_begin])) {
break;
}
}
int64_t whitespace_end = string.len;
for (; whitespace_end != whitespace_begin; whitespace_end--) {
if (!IsWhitespace(string.data[whitespace_end - 1])) {
break;
}
}
if (whitespace_begin == whitespace_end) {
string.len = 0;
} else {
string = GetSlice(string, whitespace_begin, whitespace_end);
}
return string;
}
String16 TrimEnd(String16 string) {
int64_t whitespace_end = string.len;
for (; whitespace_end != 0; whitespace_end--) {
if (!IsWhitespace(string.data[whitespace_end - 1])) {
break;
}
}
String16 result = GetPrefix(string, whitespace_end);
return result;
}