ALOT OF CHANGES
This commit is contained in:
@@ -228,7 +228,7 @@ inline int64_t StringLen(char *string) {
|
||||
return i;
|
||||
}
|
||||
|
||||
inline int64_t WideLength(wchar_t *string) {
|
||||
inline int64_t WideLength(char16_t *string) {
|
||||
if (!string) return 0;
|
||||
int64_t len = 0;
|
||||
while (*string++ != 0)
|
||||
@@ -248,9 +248,9 @@ struct Slice {
|
||||
Slice(const char *s) : data((char *)s), len(StringLen((char *)s)) {}
|
||||
Slice(const char *s, int64_t l) : data((char *)s), len(l) {}
|
||||
|
||||
Slice(wchar_t *s) : data(s), len(WideLength(s)) {}
|
||||
Slice(const wchar_t *s) : data((wchar_t *)s), len(WideLength((wchar_t *)s)) {}
|
||||
Slice(const wchar_t *s, int64_t l) : data((wchar_t *)s), len(l) {}
|
||||
Slice(char16_t *s) : data(s), len(WideLength(s)) {}
|
||||
Slice(const char16_t *s) : data((char16_t *)s), len(WideLength((char16_t *)s)) {}
|
||||
Slice(const char16_t *s, int64_t l) : data((char16_t *)s), len(l) {}
|
||||
|
||||
T &operator[](int64_t index) {
|
||||
Assert(index < len);
|
||||
@@ -782,7 +782,7 @@ struct UTF8Iter {
|
||||
};
|
||||
|
||||
using String = Slice<char>;
|
||||
using String16 = Slice<wchar_t>;
|
||||
using String16 = Slice<char16_t>;
|
||||
bool IsValid(UTF8Iter &iter);
|
||||
void Advance(UTF8Iter *iter);
|
||||
UTF8Iter IterateUTF8Ex(char *data, int64_t len);
|
||||
@@ -792,7 +792,7 @@ UTF8Iter IterateUTF8(String string);
|
||||
bool IsAlphabetic(char a);
|
||||
#define FmtString(string) (int)(string).len, (string).data
|
||||
bool AreEqual(String a, String b, unsigned ignore_case = false);
|
||||
int64_t CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen);
|
||||
int64_t CreateWidecharFromChar(char16_t *buffer, int64_t buffer_size, char *in, int64_t inlen);
|
||||
inline bool operator==(String a, String b) { return AreEqual(a, b); }
|
||||
inline bool operator!=(String a, String b) { return !AreEqual(a, b); }
|
||||
|
||||
@@ -805,16 +805,17 @@ inline bool operator!=(String a, String b) { return !AreEqual(a, b); }
|
||||
String Format(Allocator allocator, const char *data, ...);
|
||||
String FormatV(Allocator allocator, const char *data, va_list args1);
|
||||
String ToString(Allocator allocator, String16 string);
|
||||
String ToString(Allocator allocator, wchar_t *string, int64_t len);
|
||||
String ToString(Allocator allocator, wchar_t *wstring);
|
||||
String ToString(Allocator allocator, char16_t *string, int64_t len);
|
||||
String ToString(Allocator allocator, char16_t *wstring);
|
||||
String16 ToString16(Allocator allocator, String string);
|
||||
wchar_t *ToWidechar(Allocator allocator, String string);
|
||||
char16_t *ToWidechar(Allocator allocator, String string);
|
||||
void NormalizePathInPlace(String s);
|
||||
String ChopLastSlash(String s);
|
||||
String ChopLastPeriod(String s);
|
||||
String SkipToLastSlash(String s);
|
||||
String SkipToLastPeriod(String s);
|
||||
String Copy(Allocator allocator, String string);
|
||||
Int GetSize(Array<String> array);
|
||||
/*
|
||||
Hash table implementation:
|
||||
Pointers to values
|
||||
@@ -1212,13 +1213,13 @@ UTF16Result UTF32ToUTF16(uint32_t codepoint) {
|
||||
return result;
|
||||
}
|
||||
|
||||
#define UTF__HANDLE_DECODE_ERROR(question_mark) \
|
||||
#define UTF__HANDLE_DECODE_ERROR(question_mark, I) \
|
||||
{ \
|
||||
if (outlen < buffer_size - 1) buffer[outlen++] = (question_mark); \
|
||||
break; \
|
||||
i += I; \
|
||||
}
|
||||
|
||||
int64_t CreateCharFromWidechar(char *buffer, int64_t buffer_size, wchar_t *in, int64_t inlen) {
|
||||
int64_t CreateCharFromWidechar(char *buffer, int64_t buffer_size, char16_t *in, int64_t inlen) {
|
||||
int64_t outlen = 0;
|
||||
for (int64_t i = 0; i < inlen && in[i];) {
|
||||
UTF32Result decode = UTF16ToUTF32((uint16_t *)(in + i), (int64_t)(inlen - i));
|
||||
@@ -1231,15 +1232,15 @@ int64_t CreateCharFromWidechar(char *buffer, int64_t buffer_size, wchar_t *in, i
|
||||
buffer[outlen++] = encode.out_str[j];
|
||||
}
|
||||
}
|
||||
} else UTF__HANDLE_DECODE_ERROR('?');
|
||||
} else UTF__HANDLE_DECODE_ERROR('?');
|
||||
} else UTF__HANDLE_DECODE_ERROR('?', 0);
|
||||
} else UTF__HANDLE_DECODE_ERROR('?', 1);
|
||||
}
|
||||
|
||||
buffer[outlen] = 0;
|
||||
return outlen;
|
||||
}
|
||||
|
||||
int64_t CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, int64_t inlen) {
|
||||
int64_t CreateWidecharFromChar(char16_t *buffer, int64_t buffer_size, char *in, int64_t inlen) {
|
||||
int64_t outlen = 0;
|
||||
for (int64_t i = 0; i < inlen;) {
|
||||
UTF32Result decode = UTF8ToUTF32((uint8_t *)(in + i), (int64_t)(inlen - i));
|
||||
@@ -1252,8 +1253,8 @@ int64_t CreateWidecharFromChar(wchar_t *buffer, int64_t buffer_size, char *in, i
|
||||
buffer[outlen++] = encode.out_str[j];
|
||||
}
|
||||
}
|
||||
} else UTF__HANDLE_DECODE_ERROR(0x003f);
|
||||
} else UTF__HANDLE_DECODE_ERROR(0x003f);
|
||||
} else UTF__HANDLE_DECODE_ERROR(0x003f, 0);
|
||||
} else UTF__HANDLE_DECODE_ERROR(0x003f, 1);
|
||||
}
|
||||
|
||||
buffer[outlen] = 0;
|
||||
@@ -1546,6 +1547,12 @@ String Merge(Allocator allocator, Array<String> list, String separator = " ") {
|
||||
return string;
|
||||
}
|
||||
|
||||
Int GetSize(Array<String> array) {
|
||||
Int result = 0;
|
||||
For (array) result += it.len;
|
||||
return result;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
String FormatV(Allocator allocator, const char *data, va_list args1) {
|
||||
va_list args2;
|
||||
@@ -1565,20 +1572,20 @@ String Format(Allocator allocator, const char *data, ...) {
|
||||
}
|
||||
|
||||
String16 ToString16(Allocator allocator, String string) {
|
||||
Assert(sizeof(wchar_t) == 2);
|
||||
wchar_t *buffer = (wchar_t *)AllocSize(allocator, sizeof(wchar_t) * (string.len + 1));
|
||||
Assert(sizeof(char16_t) == 2);
|
||||
char16_t *buffer = (char16_t *)AllocSize(allocator, sizeof(char16_t) * (string.len + 1));
|
||||
int64_t size = CreateWidecharFromChar(buffer, string.len + 1, string.data, string.len);
|
||||
String16 result = {buffer, size};
|
||||
return result;
|
||||
}
|
||||
|
||||
wchar_t *ToWidechar(Allocator allocator, String string) {
|
||||
char16_t *ToWidechar(Allocator allocator, String string) {
|
||||
String16 result = ToString16(allocator, string);
|
||||
return result.data;
|
||||
}
|
||||
|
||||
String ToString(Allocator allocator, String16 string) {
|
||||
Assert(sizeof(wchar_t) == 2);
|
||||
Assert(sizeof(char16_t) == 2);
|
||||
|
||||
int64_t buffer_size = (string.len + 1) * 2;
|
||||
char *buffer = (char *)AllocSize(allocator, buffer_size);
|
||||
@@ -1589,11 +1596,11 @@ String ToString(Allocator allocator, String16 string) {
|
||||
return result;
|
||||
}
|
||||
|
||||
String ToString(Allocator allocator, wchar_t *string, int64_t len) {
|
||||
String ToString(Allocator allocator, char16_t *string, int64_t len) {
|
||||
return ToString(allocator, {string, len});
|
||||
}
|
||||
|
||||
String ToString(Allocator allocator, wchar_t *wstring) {
|
||||
String ToString(Allocator allocator, char16_t *wstring) {
|
||||
int64_t size = WideLength(wstring);
|
||||
String result = ToString(allocator, {wstring, size});
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user