diff options
| author | dam <dam@gudinoff> | 2023-03-21 00:18:46 +0000 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-03-21 00:18:46 +0000 |
| commit | b9971dce185f876b9358d399f23ebb4a1630ef1b (patch) | |
| tree | dc0020cff10c17316482c10e6827d10c69327db9 /ttt.jai | |
| parent | 7bd617825b0edca20bd4ef5ad4e49c4fd2ffde76 (diff) | |
| download | task-time-tracker-b9971dce185f876b9358d399f23ebb4a1630ef1b.tar.zst task-time-tracker-b9971dce185f876b9358d399f23ebb4a1630ef1b.zip | |
Prototyping import_from_csv.
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 44 |
1 files changed, 11 insertions, 33 deletions
@@ -187,11 +187,11 @@ Text_Encoding :: enum u8 #specified { truncate_string :: (str: string, length: s64, $encoding: Text_Encoding = .UTF8) -> length: s64 #no_abc { // TODO Should I use #no_abc ? assert(str.data != null); assert(str.count >= length); - + data := str.data; count := str.count; - #if encoding == .UTF8 { // WIP simplify this if/else and try to use only idx or length + #if encoding == .UTF8 { // Find index of first continuation byte. idx := length; while (idx > 0 && ((data[idx - 1] & 0xC0) == 0x80)) { @@ -239,7 +239,8 @@ bool is_empty_string(const char *string) { // Uses strchr to replace all instances of find by replace. // Returns string. -char *replace_char(char *string, char find, char replace) { +char *replace_char(char *string, char find, char replace) { // TODO Use modules/String/module.jai:replace_chars + char *idx = string; while((idx = strchr(idx, find)) != NULL) { *idx = replace; @@ -809,7 +810,12 @@ import_from_csv :: (db: *Database, path: string) -> bool { task: Task; values := split(line, ","); // TODO Temporary memory... if file is too big this may break. - memcpy(task.name.data, values[0].data, xx min(task.name.count, values[0].count)); + + // Import task name. + name_length := min(task.name.count, values[0].count); + memcpy(task.name.data, values[0].data, name_length); + truncate_string(xx task.name, name_length); + advance(*values); for values { task.times[it_index] = string_to_int(it); @@ -1286,34 +1292,6 @@ bool read_enter_confirmation(int row, int style, const char *message) { */ main :: () { - - print("---\n"); - - format :: (value: string) { - print("value is '%'\n", value); - } - - format("direct"); - va := "var A"; - format(va); - - sb := "var B"; - vb: [2048] u8; - memcpy(vb.data, sb.data, sb.count); - xb: string = xx sb; - print("> xb.count = %\n> xb.data = %\n", xb.count, xb.data); - format(xx vb); - - print("--- --- ---\n"); - xpto: string = copy_string("ç€dam"); - memcpy(vb.data, xpto.data, xpto.count); - truncate_string(xx vb, 4); - // memset(xpto.data, 0, 5); - print(">'%'\n", xpto); - print(">'%'\n", cast(string)vb); - - return; - defer free_memory(); @@ -1339,7 +1317,7 @@ main :: () { { import_from_csv(*db, ar_file_path); -// for db.tasks print_task(it); + for db.tasks print_task(it); print_task :: (task: Task) { for task.times print("% |", it); |
