From 010f397349a81d3a2d5bc32286236c069648e288 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Wed, 9 Aug 2017 23:44:27 +0200 Subject: [PATCH] Rename string_get_length into string_size <== Uniformisation with the other containers. --- bench/bench-string.cpp | 10 +++++----- example/ex-multi01.c | 4 ++-- m-string.h | 6 +++--- tests/test-mstring.c | 16 ++++++++-------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bench/bench-string.cpp b/bench/bench-string.cpp index 429ce9ad..cd578b63 100644 --- a/bench/bench-string.cpp +++ b/bench/bench-string.cpp @@ -278,7 +278,7 @@ int testMLIB_emptyCtor (int count) { for (c=i=0; i < count; i++) { string_t b; string_init(b); - c += string_get_length(b) ^i; + c += string_size(b) ^i; string_clear(b); } return c; @@ -289,7 +289,7 @@ int testMLIB_nonemptyCtor (int count) { for (c=i=0; i < count; i++) { string_t b; string_init_set_str(b, TESTSTRING1); - c += string_get_length(b) ^i; + c += string_size(b) ^i; string_clear(b); } return c; @@ -301,7 +301,7 @@ int testMLIB_cstrAssignment (int count) { string_init(b); for (c=i=0; i < count; i++) { string_set_str(b, TESTSTRING1); - c += string_get_length(b) ^i; + c += string_size(b) ^i; } string_clear(b); return c; @@ -348,7 +348,7 @@ int testMLIB_concat (int count) { for (i=0; i < 250; i++) { string_cat(accum, a); string_cat_str(accum, "!!"); - c += string_get_length(accum) ^i; + c += string_size(accum) ^i; } } string_clear(a); @@ -365,7 +365,7 @@ int testMLIB_replace (int count) { string_replace_at(a, 11, 4, "XXXXXX"); string_replace_at(a, 23, 2, "XXXXXX"); string_replace_at(a, 4, 8, "XX"); - c += string_get_length(a) ^j; + c += string_size(a) ^j; } string_clear(a); diff --git a/example/ex-multi01.c b/example/ex-multi01.c index faf34f00..c98149f5 100644 --- a/example/ex-multi01.c +++ b/example/ex-multi01.c @@ -36,7 +36,7 @@ static void program_init(program_t p, string_t text) { array_int_init(leftstack); string_init_set_str(symbols, "[]<>+-,."); int pc = 0; - for (size_t i = 0; i < string_get_length(text); i++) { + for (size_t i = 0; i < string_size(text); i++) { char c = string_get_char(text, i); if (string_search_char(symbols, c) == STRING_FAILURE) continue; @@ -64,7 +64,7 @@ static void program_clear(program_t p) { static void program_run(program_t p){ tape_t tape; tape_init(tape); - for(size_t pc = 0; pc < string_get_length(p->code); pc++) { + for(size_t pc = 0; pc < string_size(p->code); pc++) { switch (string_get_char(p->code, pc)) { case '+': tape_inc(tape); diff --git a/m-string.h b/m-string.h index d462a6bb..38bb23f5 100644 --- a/m-string.h +++ b/m-string.h @@ -113,7 +113,7 @@ string_clean(string_t v) } static inline size_t -string_get_length(const string_t v) +string_size(const string_t v) { STRING_CONTRACT (v); return v->size; @@ -792,7 +792,7 @@ string_in_str(string_t v, FILE *f) string_t tmp; \ string_init(tmp); \ M_GET_CLEAN oplist (cont); \ - for(size_t i = 0 ; i < string_get_length(str); i++) { \ + for(size_t i = 0 ; i < string_size(str); i++) { \ char c = string_get_char(str, i); \ if (c == sep) { \ string_set_strn(tmp, &str->ptr[begin], i - begin); \ @@ -800,7 +800,7 @@ string_in_str(string_t v, FILE *f) begin = i + 1; \ } \ } \ - string_set_strn(tmp, &str->ptr[begin], string_get_length(str) - begin); \ + string_set_strn(tmp, &str->ptr[begin], string_size(str) - begin); \ M_GET_PUSH oplist (cont, tmp); \ /* HACK: if method reverse is defined, it is likely that we have */ \ /* inserted the items in the wrong order (aka for a list) */ \ diff --git a/tests/test-mstring.c b/tests/test-mstring.c index 90345797..aa3d9844 100644 --- a/tests/test-mstring.c +++ b/tests/test-mstring.c @@ -35,11 +35,11 @@ int main(void) string_init (s2); string_set_str (s1, "Hello, world!"); - assert (string_get_length(s1) == 13); + assert (string_size(s1) == 13); assert (string_get_char(s1, 1) == 'e'); string_clean(s1); - assert (string_get_length(s1) == 0); + assert (string_size(s1) == 0); assert (string_empty_p(s1) == true); assert (strcmp(string_get_cstr(s1), "") == 0); @@ -51,13 +51,13 @@ int main(void) string_clean(s1); string_set_str (s1, "Hello beautiful world!"); - assert (string_get_length(s1) == 22); + assert (string_size(s1) == 22); assert (strcmp(string_get_cstr(s1), "Hello beautiful world!") == 0); string_clean(s1); string_set_str(s1, "Hello"); string_cat_str(s1, ", world!"); - assert (string_get_length(s1) == 13); + assert (string_size(s1) == 13); assert (string_cmp_str(s1, "Hello, world!") == 0); string_set_str(s2, "Hello, world!"); assert (string_cmp(s1, s2) == 0); @@ -112,7 +112,7 @@ int main(void) string_printf (s1, "There is %d Paul!", 2); assert (string_cmp_str (s1, "There is 2 Paul!") == 0); - assert (string_get_length (s1) == 16); + assert (string_size (s1) == 16); string_set_str(s1, "Hello, world()\n"); i = string_cspn(s1, ",()"); @@ -147,18 +147,18 @@ int main(void) string_left(s1, 100); assert (string_empty_p (s1)); - assert (string_get_length (s1) == 0); + assert (string_size (s1) == 0); assert (string_cmp_str (s1, "") == 0); string_right(s1, 100); assert (string_empty_p (s1)); - assert (string_get_length (s1) == 0); + assert (string_size (s1) == 0); assert (string_cmp_str (s1, "") == 0); string_set_str(s2, "Hello"); string_set (s2, s1); assert (string_empty_p (s2)); - assert (string_get_length (s2) == 0); + assert (string_size (s2) == 0); assert (string_cmp_str (s2, "") == 0); string_set_str(s1, "Hello, world!");