Make procedure parameters just named values rather than copied variables

This commit is contained in:
gingerBill
2019-07-15 21:18:37 +01:00
parent 3d531be711
commit f25818e923
19 changed files with 138 additions and 131 deletions
+4 -5
View File
@@ -89,7 +89,6 @@ _open_file_dialog :: proc(title: string, dir: string,
// Filters need to be passed as a pair of strings (title, filter)
filter_len := u32(len(filters));
if filter_len % 2 != 0 do return "", false;
default_filter = clamp(default_filter, 1, filter_len / 2);
filter: string;
filter = strings.join(filters, "\u0000", context.temp_allocator);
@@ -102,7 +101,7 @@ _open_file_dialog :: proc(title: string, dir: string,
title = utf8_to_wstring(title, context.temp_allocator),
filter = utf8_to_wstring(filter, context.temp_allocator),
initial_dir = utf8_to_wstring(dir, context.temp_allocator),
filter_index = u32(default_filter),
filter_index = u32(clamp(default_filter, 1, filter_len / 2)),
def_ext = utf8_to_wstring(default_ext, context.temp_allocator),
flags = u32(flags),
};
@@ -121,7 +120,7 @@ _open_file_dialog :: proc(title: string, dir: string,
return "", false;
}
file_name := ucs2_to_utf8(file_buf[:], allocator);
file_name := utf16_to_utf8(file_buf[:], allocator);
path = strings.trim_right_null(file_name);
return;
}
@@ -143,7 +142,7 @@ select_file_to_save :: proc(title := SAVE_TITLE, dir := ".",
return;
}
// TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
// TODO: Implement convenience function for select_file_to_open with ALLOW_MULTI_SELECT that takes
// it output of the form "path\u0000\file1u\0000file2" and turns it into []string with the path + file pre-concatenated for you.
OFN_ALLOWMULTISELECT :: 0x00000200; // NOTE(Jeroen): Without OFN_EXPLORER it uses the Win3 dialog.
@@ -186,4 +185,4 @@ CDERR_LOCKRESFAILURE :: 0x00000008;
CDERR_MEMALLOCFAILURE :: 0x00000009;
CDERR_MEMLOCKFAILURE :: 0x0000000A;
CDERR_NOHOOK :: 0x0000000B;
CDERR_REGISTERMSGFAIL :: 0x0000000C;
CDERR_REGISTERMSGFAIL :: 0x0000000C;
+2 -2
View File
@@ -9,6 +9,6 @@ foreign {
get_cwd :: proc(allocator := context.temp_allocator) -> string {
buffer := make([]u16, MAX_PATH_WIDE, allocator);
_get_cwd_wide(Wstring(&buffer[0]), MAX_PATH_WIDE);
file := ucs2_to_utf8(buffer[:], allocator);
file := utf16_to_utf8(buffer[:], allocator);
return strings.trim_right_null(file);
}
}
+3 -3
View File
@@ -728,7 +728,7 @@ CP_UTF8 :: 65001; // UTF-8 translation
MB_ERR_INVALID_CHARS :: 8;
WC_ERR_INVALID_CHARS :: 128;
utf8_to_ucs2 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
utf8_to_utf16 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
if len(s) < 1 {
return nil;
}
@@ -751,13 +751,13 @@ utf8_to_ucs2 :: proc(s: string, allocator := context.temp_allocator) -> []u16 {
return text[:len(text)-1];
}
utf8_to_wstring :: proc(s: string, allocator := context.temp_allocator) -> Wstring {
if res := utf8_to_ucs2(s, allocator); res != nil {
if res := utf8_to_utf16(s, allocator); res != nil {
return Wstring(&res[0]);
}
return nil;
}
ucs2_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
utf16_to_utf8 :: proc(s: []u16, allocator := context.temp_allocator) -> string {
if len(s) < 1 {
return "";
}