Editing infobar applies changes to buffer
This commit is contained in:
@@ -700,7 +700,6 @@ struct CircularArray {
|
||||
T *data;
|
||||
int16_t cap;
|
||||
int16_t write;
|
||||
int16_t buffer_is_full;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@@ -718,25 +717,23 @@ void Add(CircularArray<T> *arr, T item) {
|
||||
arr->cap = 128;
|
||||
arr->data = AllocArray(arr->allocator, T, arr->cap);
|
||||
}
|
||||
int idx = arr->write;
|
||||
arr->write = (arr->write + 1) % arr->cap;
|
||||
if (arr->write == 0) arr->buffer_is_full = 1;
|
||||
arr->data[idx] = item;
|
||||
int16_t i = arr->write;
|
||||
arr->write = (arr->write + 1) % arr->cap;
|
||||
arr->data[i] = item;
|
||||
}
|
||||
|
||||
static int GetCircularIndex(int cap, int idx) {
|
||||
int result = idx % cap;
|
||||
if (result < 0) result = cap + result;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T Get(CircularArray<T> *arr, int idx, T default_value) {
|
||||
if (idx >= arr->cap) return default_value;
|
||||
int i = arr->write - 1 - idx;
|
||||
if (i < 0 && arr->buffer_is_full) {
|
||||
i = arr->cap + i;
|
||||
}
|
||||
|
||||
if (i >= 0 && i < arr->cap) {
|
||||
return arr->data[i];
|
||||
} else {
|
||||
return default_value;
|
||||
}
|
||||
int idx = circ->write - 1 - i;
|
||||
idx = GetCircularIndex(circ->size, idx);
|
||||
int result = circ->data[idx];
|
||||
return result;
|
||||
}
|
||||
|
||||
struct UTF32Result {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user