summaryrefslogtreecommitdiffhomepage
path: root/cmap_test.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-03-09 00:09:28 +0100
committerGitHub <[email protected]>2020-03-09 00:09:28 +0100
commitde99eca6d86ee2e05c85fb7793f8a737811abce6 (patch)
treee3a59212892ea51a0df9772ebe2af8babf1c8615 /cmap_test.c
parent582c3d1b319e163368eb0a232e6d76e40ea947a6 (diff)
downloadSTC-modified-de99eca6d86ee2e05c85fb7793f8a737811abce6.tar.gz
STC-modified-de99eca6d86ee2e05c85fb7793f8a737811abce6.zip
Fixed CString bugs
Diffstat (limited to 'cmap_test.c')
-rw-r--r--cmap_test.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/cmap_test.c b/cmap_test.c
index 5dd6fb54..3db1252f 100644
--- a/cmap_test.c
+++ b/cmap_test.c
@@ -72,14 +72,14 @@ void stringSpeed(int limit) {
CString s = cstring_initializer;
char ch[2] = {0, 0};
size_t x = 0;
- const char* p = 0;
+ size_t p = 0;
for (int n = 0; n < limit; ++n) { ch[0] = 'A' + (rand() % 26); cstring_append(&s, ch); }
const char* search = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
cstring_append(&s, search);
clock_t before = clock();
for (int n = 0; n < limit; ++n) {
p = cstring_find(s, 0, search + (n % 100));
- if (p) x += (p - s.str);
+ if (p != cstring_npos) x += p;
}
clock_t diff = clock() - before;
printf("cstring length = %llu / %llu, sum %llu speed: %f\n", cstring_size(s), cstring_capacity(s), x, 1.0 * diff / CLOCKS_PER_SEC);
@@ -90,16 +90,17 @@ int main()
int i = 0;
stringSpeed(20000);
- return 0;
- CString cs = cstring_make("one three four");
- printf("%s\n", cs.str);
- cstring_insert(&cs, 3, " two");
- printf("%s\n", cs.str);
- cstring_erase(&cs, 7, strlen(" three"));
- printf("%s\n", cs.str);
+ CString cs = cstring_make("one-nine-three-seven-five");
+ printf("%s.\n", cs.str);
+ cstring_insert(&cs, 3, "-two");
+ printf("%s.\n", cs.str);
+ cstring_erase(&cs, 7, 5); // -nine
+ printf("%s.\n", cs.str);
+ cstring_replace(&cs, 0, "seven", "four");
+ printf("%s.\n", cs.str);
- printf("found: %s\n", cstring_findN(cs, 0, "fout", 3));
+ printf("found: %s\n", cs.str + cstring_find(cs, 0, "four"));
cstring_assign(&cs, "one two three four five six seven");
cstring_replace(&cs, 0, "four", "F-O-U-R");
printf("replace: %s\n", cs.str);