Skip to content

Commit

Permalink
Duyệt tuần tự từng token - tok_traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
bangoc committed Jan 2, 2022
1 parent e40cb42 commit 604e85d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ const char* ascii_spaces = "\t\n\v\f\r ";

gvec_t str_tokens(char *line, const char *delims) {
gvec_t tokens = gvec_create(5, NULL);
char *tmp = strtok(line, delims);
while (tmp) {
gvec_append(tokens, gtype_s(tmp));
tmp = strtok(NULL, delims);
tok_traverse(tk, line, delims) {
gvec_append(tokens, gtype_s(tk));
}
return tokens;
}
2 changes: 2 additions & 0 deletions str.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ extern const char* ascii_spaces;
gvec_t str_tokens(char *line, const char *delims);

#define str_split(line) str_tokens(line, ascii_spaces)
#define tok_traverse(cur, line, delims) \
for (char *cur = strtok(line, delims); cur; cur = strtok(NULL, delims))

#endif // STR_H_

0 comments on commit 604e85d

Please sign in to comment.