mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-01 02:53:22 +00:00
* Import patch from whats refactoring some stuff in r_core_cmd
* Add missing test_str and pool tests in libr/util
This commit is contained in:
parent
ab190b6430
commit
7b07e1371c
@ -117,6 +117,9 @@ R_API char *r_str_word_get_first(const char *string);
|
||||
R_API char *r_str_chop(char *str);
|
||||
R_API const char *r_str_chop_ro(const char *str);
|
||||
R_API char *r_str_trim(char *str);
|
||||
R_API char *r_str_trim_head(char *str);
|
||||
R_API char *r_str_trim_tail(char *str);
|
||||
R_API char *r_str_trim_head_tail(char *str);
|
||||
R_API int r_str_hash(const char *str);
|
||||
R_API char *r_str_clean(char *str);
|
||||
R_API int r_str_nstr(char *from, char *to, int size);
|
||||
|
@ -181,6 +181,37 @@ R_API char *r_str_chop(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API char *r_str_trim_head(char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
while (*str && iswhitechar(*str))
|
||||
str++;
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API char *r_str_trim_tail(char *str)
|
||||
{
|
||||
char *ptr = str;
|
||||
|
||||
if (str == NULL)
|
||||
return NULL;
|
||||
|
||||
ptr += strlen(str)-1;
|
||||
|
||||
while ((ptr > str) && iswhitechar(*ptr)) {
|
||||
*ptr = '\0';
|
||||
ptr--;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
R_API char *r_str_trim_head_tail(char *str)
|
||||
{
|
||||
return r_str_trim_tail(r_str_trim_head(str));
|
||||
}
|
||||
|
||||
R_API char *r_str_trim(char *str)
|
||||
{
|
||||
int i;
|
||||
|
@ -1,7 +1,7 @@
|
||||
# TODO: append EXECEXT to BINS
|
||||
FLAGS=-I../../include -Wl,-R.. -L.. -lr_util -g -DVERSION=\"${VERSION}\"
|
||||
|
||||
all: test rax2 ralloc iter file_slurp_hexpairs pool test_sys
|
||||
all: test rax2 ralloc iter file_slurp_hexpairs pool test_sys test_str
|
||||
|
||||
ralloc:
|
||||
${CC} ${FLAGS} ralloc.c -o ralloc
|
||||
@ -12,6 +12,9 @@ test:
|
||||
test_sys: test_sys.c
|
||||
${CC} ${FLAGS} test_sys.c -o test_sys -lr_util
|
||||
|
||||
test_str: test_str.c
|
||||
${CC} ${FLAGS} test_str.c -o test_str -lr_util
|
||||
|
||||
pool:
|
||||
${CC} ${FLAGS} pool.c -o pool
|
||||
|
||||
@ -24,8 +27,7 @@ iter:
|
||||
file_slurp_hexpairs:
|
||||
${CC} -I../../include test_file_slurp_hexpairs.c -lr_util -o file_slurp_hexpairs
|
||||
|
||||
|
||||
clean:
|
||||
rm -f calc rax2 ralloc test test_sys pool iter
|
||||
rm -f a.out calc rax2 ralloc test test_sys pool iter test_str pool file_slurp_hexpairs
|
||||
|
||||
include ../../rules.mk
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <r_util.h>
|
||||
|
||||
char *buf[] = { "eax", "ebx", "ecx", NULL };
|
||||
ut8 *buf[] = { "eax", "ebx", "ecx", NULL };
|
||||
|
||||
int main()
|
||||
{
|
||||
@ -8,7 +8,7 @@ int main()
|
||||
void *foo = r_mem_pool_alloc(pool);
|
||||
foo = r_mem_pool_alloc(pool);
|
||||
|
||||
printf("%d\n", r_mem_count(buf));
|
||||
printf ("%d\n", r_mem_count(buf));
|
||||
|
||||
r_mem_pool_free(pool);
|
||||
}
|
||||
|
13
libr/util/t/test_str.c
Normal file
13
libr/util/t/test_str.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include "r_util.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
char head[] =" a";
|
||||
char tail[] ="a ";
|
||||
char both[] =" a ";
|
||||
printf("r_str_trim_head('%s',): '%s'\n", " a", r_str_trim_head(head));fflush(stdout);
|
||||
printf("r_str_trim_tail('%s',): '%s'\n", "a ", r_str_trim_tail(tail));fflush(stdout);
|
||||
printf("r_str_trim_head_tail('%s',): '%s'\n", " a ", r_str_trim_head_tail(both));fflush(stdout);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user