aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c15
-rw-r--r--readme.md5
2 files changed, 10 insertions, 10 deletions
diff --git a/main.c b/main.c
index e3f6248..989149f 100644
--- a/main.c
+++ b/main.c
@@ -114,20 +114,19 @@ bool inline static is_equal_to_any(const char *to_compare, const char *test_a, c
}
// Given an UTF8 encoded string, truncate it to length without breaking any UTF8 character.
-// The string should have capacity for at least length number of items.
-// The terminating null byte ('\0') is included in length.
-// TODO null byte should not be part of the length.
+// The string should have capacity for at least length + 1.
+// The terminating null byte ('\0') is not included in length.
// Returns the amount of items discarded.
size_t truncate_string_utf8(char *string, size_t length) {
// Check for special cases where no truncation is required.
- if (length == 0 || string[length-1] == '\0') {
+ if (length == 0 || string[length] == '\0') {
return 0;
}
// Search for a non-UTF8-sequence-item so we can truncate the string.
- size_t idx = length - 1;
- while(idx > 0 && ((string[idx] & 0xC0) == 0x80)) { // TODO Only needs to back up 3 items... because of UTF8 being limited to 4bytes
+ size_t idx = length;
+ while(idx > 0 && ((string[idx] & 0xC0) == 0x80)) {
idx--;
}
string[idx] = '\0';
@@ -657,8 +656,8 @@ bool import_from_csv(database_st *db, const char *path) {
continue;
}
size_t name_length = (name_delimiter - csv_buffer) + 1;
- if (name_length > MAX_TASK_NAME) {
- name_length = MAX_TASK_NAME;
+ if (name_length >= MAX_TASK_NAME) {
+ name_length = MAX_TASK_NAME - 1;
}
// Prepare new task.
diff --git a/readme.md b/readme.md
index 0d70120..973c8d2 100644
--- a/readme.md
+++ b/readme.md
@@ -60,8 +60,8 @@ Task Time Tracker
- [x] Replaced `sprintf` by `snprintf`;
- [x] Make sure that string_buffer bounds are respected;
- [ ] Compress code:
- - [x] Re-do sprint_time5_utf8: -12 LOC;
- - [ ] Re-do truncate_string_utf8: 1761 - XXXX = LOC;
+ - [x] Re-do sprint_time5_utf8: -12 delta LOC;
+ - [x] Re-do truncate_string_utf8: 0 delta LOC;
- [ ] Get input using `get_input(char *input, size_t size, int row, int column)` (what does it returns???):
- [ ] wrap malloc (and maybe others) in a function with error checking
```c
@@ -72,5 +72,6 @@ Task Time Tracker
- `select_task_by_index(database_st *db, size_t???)`
- `sect_active(database_st *db, task_st *task)`
- [ ] Check if draw_tui may be simplified by drawing entire lines of tasks at once and draw columns separators after;
+- [ ] Rename `MAX_TASK_NAME` to `TASK_NAME_BUFFER_SIZE`;
- [ ] Review all code for bugs related to auto-cast on ptrdiff_t/size_t (signed/unsigned);
- [ ] Go over all `TODO` items;