aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ttt.jai44
1 files changed, 11 insertions, 33 deletions
diff --git a/ttt.jai b/ttt.jai
index d1e52ab..08f471a 100644
--- a/ttt.jai
+++ b/ttt.jai
@@ -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);