From cb41e69bdb9db68617fb6a4651a4fdb6af2b5442 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 25 Jul 2023 09:39:27 +0200 Subject: [PATCH 1/3] clean: remove test to deleted func (reallocarray) --- tests/reallocarray.🗿 | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 tests/reallocarray.🗿 diff --git a/tests/reallocarray.🗿 b/tests/reallocarray.🗿 deleted file mode 100644 index 3a14868..0000000 --- a/tests/reallocarray.🗿 +++ /dev/null @@ -1,11 +0,0 @@ -main() -{ - local tmp; - name = "reallocarray"; - - tmp = strdup("yo"); - if (tmp == NULL) - return 1; - tmp = reallocarray(tmp, strlen(tmp), 5); - test_str(tmp, "yo", ""); -} From 2b97d38b7e320b22a7fe911f9944374e42d8035f Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 25 Jul 2023 09:41:07 +0200 Subject: [PATCH 2/3] rename replace func to replace_index --- src/{replace.🗿 => replace_index.🗿} | 2 +- tests/replace.🗿 | 9 --------- tests/replace_index.🗿 | 9 +++++++++ 3 files changed, 10 insertions(+), 10 deletions(-) rename src/{replace.🗿 => replace_index.🗿} (89%) delete mode 100644 tests/replace.🗿 create mode 100644 tests/replace_index.🗿 diff --git a/src/replace.🗿 b/src/replace_index.🗿 similarity index 89% rename from src/replace.🗿 rename to src/replace_index.🗿 index fa69170..0463e6a 100644 --- a/src/replace.🗿 +++ b/src/replace_index.🗿 @@ -1,4 +1,4 @@ -replace(str, fill, start, stop) +replace_index(str, fill, start, stop) { local out; local sum; diff --git a/tests/replace.🗿 b/tests/replace.🗿 deleted file mode 100644 index 6651487..0000000 --- a/tests/replace.🗿 +++ /dev/null @@ -1,9 +0,0 @@ -main() -{ - name = "replace"; - - test_str(replace("yo ca va ?", "t", 2, 3), "yotca va ?", ""); - test_str(replace("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill"); - test_str(replace("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", ""); - test_str(replace("", "aaaaa", 0, 0), "aaaaa", ""); -} diff --git a/tests/replace_index.🗿 b/tests/replace_index.🗿 new file mode 100644 index 0000000..21eb920 --- /dev/null +++ b/tests/replace_index.🗿 @@ -0,0 +1,9 @@ +main() +{ + name = "replace_index"; + + test_str(replace_index("yo ca va ?", "t", 2, 3), "yotca va ?", ""); + test_str(replace_index("yo ca va ?", "", 2, 3), "yoca va ?", "empty fill"); + test_str(replace_index("yo ca va ?", "aaaaa", 2, 3), "yoaaaaaca va ?", ""); + test_str(replace_index("", "aaaaa", 0, 0), "aaaaa", ""); +} From 09e0d32c15bd33c56d212e249edc0f6f23e626f2 Mon Sep 17 00:00:00 2001 From: starnakin Date: Tue, 25 Jul 2023 09:48:20 +0200 Subject: [PATCH 3/3] clean and opti --- src/free_tab.🗿 | 2 +- src/memset.🗿 | 2 +- src/ntoa.🗿 | 4 ++-- src/ntoa_s.🗿 | 19 ++----------------- src/putstr.🗿 | 8 ++++---- src/puttab.🗿 | 2 +- 6 files changed, 11 insertions(+), 26 deletions(-) diff --git a/src/free_tab.🗿 b/src/free_tab.🗿 index 5a03829..0ff0417 100644 --- a/src/free_tab.🗿 +++ b/src/free_tab.🗿 @@ -7,7 +7,7 @@ free_tab(tab) if ([tmp] == 0) return; free([tmp]); - tmp = tmp + 1; + tmp++; } return free(tab); } diff --git a/src/memset.🗿 b/src/memset.🗿 index f7d4161..0b007cb 100644 --- a/src/memset.🗿 +++ b/src/memset.🗿 @@ -6,6 +6,6 @@ memset(tab, size, value) if (i == size) return (tab); [tab + i] = value; - i = i + 1; + i++; } } diff --git a/src/ntoa.🗿 b/src/ntoa.🗿 index 5d6e26d..0f055a0 100644 --- a/src/ntoa.🗿 +++ b/src/ntoa.🗿 @@ -9,7 +9,7 @@ ntoa_get_size(number) if (number == 0) return (size); number = number / 10; - size = size + 1; + size++; } } @@ -29,7 +29,7 @@ ntoa(number) { if (number == 0) return (str); - size = size - 1; + size--; [str + size] = number % 10 + '0'; number = number / 10; } diff --git a/src/ntoa_s.🗿 b/src/ntoa_s.🗿 index 33ea431..9adc3ff 100644 --- a/src/ntoa_s.🗿 +++ b/src/ntoa_s.🗿 @@ -1,18 +1,3 @@ -ntoa_get_size(number) -{ - local size = 0; - - if (number == 0) - return 1; - loop - { - if (number == 0) - return (size); - number = number / 10; - size = size + 1; - } -} - ntoa_s(number) { local str, sign, size; @@ -24,7 +9,7 @@ ntoa_s(number) } size = ntoa_get_size(number); if (sign) - size = size + 1; + size++; str = galloc(size + 1); if (str == 0) return (0); @@ -39,6 +24,6 @@ ntoa_s(number) return (str); [str + size - 1] = number % 10 + '0'; number = number / 10; - size = size - 1; + size--; } } diff --git a/src/putstr.🗿 b/src/putstr.🗿 index 5c5c77c..ef2c102 100644 --- a/src/putstr.🗿 +++ b/src/putstr.🗿 @@ -1,14 +1,14 @@ putstr(str) { - local i = 0; + local tmp = str; if (str == NULL) { putstr("(null)"); return NULL; } loop { - if ([str + i] == 0) + if ([tmp] == 0) return str; - putchar([str + i]); - i = i + 1; + putchar([tmp]); + tmp++; } } diff --git a/src/puttab.🗿 b/src/puttab.🗿 index efdc930..afc3022 100644 --- a/src/puttab.🗿 +++ b/src/puttab.🗿 @@ -10,7 +10,7 @@ puttab_str(tab) putchar('"'); putstr([tab]); putchar('"'); - tab = tab + 1; + tab++; if ([tab] != 0) putstr(", "); }