String16 routines
This commit is contained in:
@@ -386,10 +386,6 @@ function OnUpdate(e)
|
||||
end
|
||||
|
||||
function OnCommand(e)
|
||||
if e.key == KEY_F1 then
|
||||
local word = GetLoadWord()
|
||||
C('git grep -n '..word)
|
||||
end
|
||||
end
|
||||
|
||||
function OnInit()
|
||||
|
||||
@@ -237,6 +237,32 @@ bool StartsWith(String16 a, String16 start, unsigned ignore_case = false) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String16 Copy(Allocator allocator, String16 string) {
|
||||
wchar_t *copy = (wchar_t *)AllocSize(allocator, sizeof(wchar_t) * (string.len + 1));
|
||||
memcpy(copy, string.data, string.len);
|
||||
copy[string.len] = 0;
|
||||
String16 result = {copy, string.len};
|
||||
return result;
|
||||
}
|
||||
|
||||
String16 Copy(Allocator allocator, wchar_t *string) {
|
||||
String16 s = {string, (int64_t)WideLength(string)};
|
||||
return Copy(allocator, s);
|
||||
}
|
||||
|
||||
void NormalizePathInPlace(String16 s) {
|
||||
for (int64_t i = 0; i < s.len; i++) {
|
||||
if (s.data[i] == L'\\')
|
||||
s.data[i] = L'/';
|
||||
}
|
||||
}
|
||||
|
||||
String16 NormalizePath(Allocator allocator, String16 s) {
|
||||
String16 copy = Copy(allocator, s);
|
||||
NormalizePathInPlace(copy);
|
||||
return copy;
|
||||
}
|
||||
|
||||
String16 SkipNumberEx(String16 *string) {
|
||||
String16 col = {string->data, 0};
|
||||
for (int64_t i = 0; i < string->len; i += 1) {
|
||||
@@ -278,4 +304,27 @@ String16 SkipWhitespace(String16 *string) {
|
||||
begin.len += 1;
|
||||
}
|
||||
return begin;
|
||||
}
|
||||
|
||||
String16 FormatV(Allocator allocator, const wchar_t *data, va_list args1) {
|
||||
va_list args2;
|
||||
va_copy(args2, args1);
|
||||
int64_t len = vswprintf(0, 0, data, args2);
|
||||
va_end(args2);
|
||||
|
||||
wchar_t *result = (wchar_t *)AllocSize(allocator, sizeof(wchar_t) * (len + 1));
|
||||
vswprintf(result, (int)(len + 1), data, args1);
|
||||
String16 res = {result, len};
|
||||
return res;
|
||||
}
|
||||
|
||||
#define STRING16_FORMAT(allocator, data, result) \
|
||||
va_list args1; \
|
||||
va_start(args1, data); \
|
||||
String16 result = FormatV(allocator, data, args1); \
|
||||
va_end(args1)
|
||||
|
||||
String16 Format(Allocator allocator, const wchar_t *data, ...) PrintfFormatAttribute(2, 3) {
|
||||
STRING16_FORMAT(allocator, data, result);
|
||||
return result;
|
||||
}
|
||||
@@ -277,10 +277,6 @@ function OnUpdate(e)
|
||||
end
|
||||
|
||||
function OnCommand(e)
|
||||
if e.key == KEY_F1 then
|
||||
local word = GetLoadWord()
|
||||
C('git grep -n '..word)
|
||||
end
|
||||
end
|
||||
|
||||
function OnInit()
|
||||
|
||||
Reference in New Issue
Block a user