Use String_AppendUtf8 instead of Platform_DecodeString for non windows platforms

This commit is contained in:
UnknownShadow200 2020-12-19 13:13:37 +11:00
parent 14de95774d
commit 3f0a2686a9
5 changed files with 17 additions and 19 deletions

View File

@ -27,6 +27,7 @@
#define Socket__Error() WSAGetLastError()
static HANDLE heap;
static void Platform_DecodeString(cc_string* dst, const void* data, int len);
const cc_result ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION;
const cc_result ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND;
@ -490,7 +491,7 @@ cc_result Directory_Enum(const cc_string* dirPath, void* obj, Directory_EnumCall
if (src[0] == '.' && src[1] == '.' && src[2] == '\0') continue;
len = String_Length(src);
Platform_DecodeString(&path, src, len);
String_AppendUtf8(&path, src, len);
/* TODO: fallback to stat when this fails */
if (entry->d_type == DT_DIR) {
@ -1546,7 +1547,8 @@ int Platform_EncodeString(void* data, const cc_string* src) {
return src->length * 2;
}
void Platform_DecodeString(cc_string* dst, const void* data, int len) {
/* Attempts to append all characters from the platform specific encoded data to the given string. */
static void Platform_DecodeString(cc_string* dst, const void* data, int len) {
#ifdef UNICODE
String_AppendUtf16(dst, (const cc_unichar*)data, len * 2);
#else
@ -1656,10 +1658,6 @@ int Platform_EncodeString(void* data, const cc_string* src) {
return len;
}
void Platform_DecodeString(cc_string* dst, const void* data, int len) {
String_AppendUtf8(dst, (const cc_uint8*)data, len);
}
static void Platform_InitPosix(void) {
signal(SIGCHLD, SIG_IGN);
/* So writing to closed socket doesn't raise SIGPIPE */
@ -1701,7 +1699,7 @@ cc_bool Platform_DescribeError(cc_result res, cc_string* dst) {
if (len == -1) return false;
len = String_CalcLen(chars, NATIVE_STR_LEN);
Platform_DecodeString(dst, chars, len);
String_AppendUtf8(dst, chars, len);
return true;
}
@ -1936,7 +1934,7 @@ cc_string JavaGetString(JNIEnv* env, jstring str, char* buffer) {
dst.buffer = buffer;
dst.length = 0;
dst.capacity = NATIVE_STR_LEN;
String_AppendUtf8(&dst, (const cc_uint8*)src, len);
String_AppendUtf8(&dst, src, len);
(*env)->ReleaseStringUTFChars(env, str, src);
return dst;

View File

@ -34,8 +34,6 @@ extern const cc_result ReturnCode_SocketWouldBlock;
/* NOTE: Only useful for platform specific function calls - do NOT try to interpret the data. */
/* Returns the number of bytes written, excluding trailing NULL terminator. */
int Platform_EncodeString(void* data, const cc_string* src);
/* Attempts to append all characters from the platform specific encoded data to the given string. */
void Platform_DecodeString(cc_string* dst, const void* data, int len);
/* Initialises the platform specific state. */
void Platform_Init(void);

View File

@ -594,7 +594,8 @@ void String_AppendUtf16(cc_string* value, const cc_unichar* chars, int numBytes)
}
}
void String_AppendUtf8(cc_string* value, const cc_uint8* chars, int numBytes) {
void String_AppendUtf8(cc_string* value, const void* data, int numBytes) {
const cc_uint8* chars = (const cc_uint8*)data;
int len; cc_codepoint cp; char c;
for (; numBytes > 0; numBytes -= len) {
@ -606,7 +607,8 @@ void String_AppendUtf8(cc_string* value, const cc_uint8* chars, int numBytes) {
}
}
void String_DecodeCP1252(cc_string* value, const cc_uint8* chars, int numBytes) {
void String_DecodeCP1252(cc_string* value, const void* data, int numBytes) {
const cc_uint8* chars = (const cc_uint8*)data;
int i; char c;
for (i = 0; i < numBytes; i++) {

View File

@ -186,10 +186,10 @@ int Convert_CP437ToUtf8(char c, cc_uint8* data);
void String_AppendUtf16(cc_string* str, const cc_unichar* chars, int numBytes);
/* Attempts to append all characters from UTF8 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void String_AppendUtf8(cc_string* str, const cc_uint8* chars, int numBytes);
void String_AppendUtf8(cc_string* str, const void* data, int numBytes);
/* Attempts to append all characters from CP-1252 encoded data to the given string. */
/* Characters not in code page 437 are omitted. */
void String_DecodeCP1252(cc_string* str, const cc_uint8* chars, int numBytes);
void String_DecodeCP1252(cc_string* str, const void* data, int numBytes);
/* Attempts to convert the given string into an unsigned 8 bit integer. */
CC_API cc_bool Convert_ParseUInt8(const cc_string* str, cc_uint8* value);

View File

@ -2069,7 +2069,7 @@ void Clipboard_GetText(cc_string* value) {
} else if (!(err = PasteboardCopyItemFlavorData(pbRef, itemID, FMT_UTF8, &outData))) {
ptr = CFDataGetBytePtr(outData);
len = CFDataGetLength(outData);
if (ptr) String_AppendUtf8(value, (cc_uint8*)ptr, len);
if (ptr) String_AppendUtf8(value, ptr, len);
}
}
@ -3513,7 +3513,7 @@ EMSCRIPTEN_KEEPALIVE void Window_GotClipboardText(char* src) {
if (!clipboard_func) return;
String_InitArray(str, strBuffer);
Platform_DecodeString(&str, src, String_CalcLen(src, 2048));
String_AppendUtf8(&str, src, String_CalcLen(src, 2048));
clipboard_func(&str, clipboard_obj);
clipboard_func = NULL;
}
@ -3652,7 +3652,7 @@ EMSCRIPTEN_KEEPALIVE void Window_OnFileUploaded(const char* src) {
cc_string file; char buffer[FILENAME_SIZE];
String_InitArray(file, buffer);
Platform_DecodeString(&file, src, String_Length(src));
String_AppendUtf8(&file, src, String_Length(src));
uploadCallback(&file);
uploadCallback = NULL;
}
@ -3701,7 +3701,7 @@ EMSCRIPTEN_KEEPALIVE void Window_OnTextChanged(const char* src) {
cc_string str; char buffer[800];
String_InitArray(str, buffer);
Platform_DecodeString(&str, src, String_CalcLen(src, 3200));
String_AppendUtf8(&str, src, String_CalcLen(src, 3200));
Event_RaiseString(&InputEvents.TextChanged, &str);
}
@ -4887,7 +4887,7 @@ void GLContext_GetApiInfo(cc_string* info) {
len = String_CalcLen(buffer, NATIVE_STR_LEN);
if (!len) return;
String_AppendConst(info, "GPU: ");
String_AppendUtf8(info, (const cc_uint8*)buffer, len);
String_AppendUtf8(info, buffer, len);
}
#endif
#endif