Skip to content

Commit

Permalink
lib: Removed t_strsplit_tab()
Browse files Browse the repository at this point in the history
It's too easy to use it accidentally instead of using
t_strsplit_tabescaped(). It's also rarely what is actually wanted.
  • Loading branch information
sirainen committed Oct 28, 2016
1 parent 026d971 commit 05c1d36
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 94 deletions.
41 changes: 0 additions & 41 deletions src/lib/strfuncs.c
Expand Up @@ -591,47 +591,6 @@ char **p_strsplit_spaces(pool_t pool, const char *data,
return split_str(pool, data, separators, TRUE);
}

const char **t_strsplit_tab(const char *data)
{
const char **array;
char *dest;
unsigned int i, array_idx, array_size, dest_size;

if (*data == '\0')
return t_new(const char *, 1);

array_size = 1;
dest_size = 128;
dest = t_buffer_get(dest_size+1);
for (i = 0; data[i] != '\0'; i++) {
if (i >= dest_size) {
dest_size = nearest_power(dest_size+1);
dest = t_buffer_reget(dest, dest_size+1);
}
if (data[i] != '\t')
dest[i] = data[i];
else {
dest[i] = '\0';
array_size++;
}
}
i_assert(i <= dest_size);
dest[i] = '\0';
t_buffer_alloc(i+1);
dest_size = i;

array = t_new(const char *, array_size + 1);
array[0] = dest; array_idx = 1;

for (i = 0; i < dest_size; i++) {
if (dest[i] == '\0')
array[array_idx++] = dest+i+1;
}
i_assert(array_idx == array_size);
array[array_idx] = NULL;
return array;
}

void p_strsplit_free(pool_t pool, char **arr)
{
p_free(pool, arr[0]);
Expand Down
2 changes: 0 additions & 2 deletions src/lib/strfuncs.h
Expand Up @@ -88,8 +88,6 @@ char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators)
const char **t_strsplit_spaces(const char *data, const char *separators)
ATTR_MALLOC ATTR_RETURNS_NONNULL;
void p_strsplit_free(pool_t pool, char **arr);
/* Optimized version of t_strsplit(data, "\t") */
const char **t_strsplit_tab(const char *data) ATTR_MALLOC ATTR_RETURNS_NONNULL;

const char *dec2str(uintmax_t number);

Expand Down
51 changes: 0 additions & 51 deletions src/lib/test-strfuncs.c
Expand Up @@ -45,56 +45,6 @@ static void test_t_strsplit(void)
test_end();
}

static void strsplit_verify(const char *str)
{
T_BEGIN {
const char **s1, **s2;
unsigned int i;

s1 = t_strsplit_tab(str);
s2 = t_strsplit(str, "\t");
for (i = 0; s1[i] != NULL; i++)
test_assert(null_strcmp(s1[i], s2[i]) == 0);
test_assert(s2[i] == NULL);
} T_END;
}

static void test_t_strsplit_tab(void)
{
char buf[4096];
unsigned int i, j, max;

test_begin("t_strsplit_tab");
strsplit_verify("");
strsplit_verify("\t");
strsplit_verify("\t\t");
strsplit_verify("foo");
strsplit_verify("foo\tbar");
strsplit_verify("foo\tbar\tbaz");
strsplit_verify("foo\t\tbaz");
buf[sizeof(buf)-1] = '\0';
for (i = 0; i < sizeof(buf)-1; i++)
buf[i] = '\t';
strsplit_verify(buf);
for (j = 0; j < 256; j++) {
memset(buf, '\t', j);
buf[j+1] = '\0';
strsplit_verify(buf);
}
for (j = 0; j < 100; j++) {
max = (rand() % sizeof(buf)) + 1;
buf[--max] = '\0';
for (i = 0; i < max; i++) {
if (rand() % 10 == 0)
buf[i] = '\t';
else
buf[i] = 'x';
}
strsplit_verify(buf);
}
test_end();
}

static void test_t_str_replace(void)
{
test_begin("t_str_replace");
Expand Down Expand Up @@ -229,7 +179,6 @@ void test_strfuncs(void)
{
test_p_strarray_dup();
test_t_strsplit();
test_t_strsplit_tab();
test_t_str_replace();
test_t_str_trim();
test_t_str_ltrim();
Expand Down

0 comments on commit 05c1d36

Please sign in to comment.