Skip to content

Commit 7c6e961

Browse files
committed
Change laco_line_to_words to be more general
This is now a split by function where it can break up a string by any given string.
1 parent 9ba1225 commit 7c6e961

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/util.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ int laco_is_match(const char** matches, const char* test_string) {
179179
return false;
180180
}
181181

182-
char** laco_line_to_words(char* line) {
183-
if(line == NULL) return NULL;
182+
char** laco_split_by(const char* split_with, char* string) {
183+
if(string == NULL) return NULL;
184184

185185
char** result = calloc(16, sizeof(char*));
186186
size_t i = 0;
187187

188188
while(1) {
189-
result[i] = strsep(&line, " ");
189+
result[i] = strsep(&string, split_with);
190190

191191
if(result[i] == NULL) break;
192192

193-
ignore_extra_spaces(&line);
193+
ignore_extra_spaces(&string);
194194

195195
i += 1;
196196
}

src/util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ int laco_is_match(const char** matches, const char* test_string);
4242
* Takes a line, seperated by spaces, and changes it into an array of the
4343
* words that make up the line. The last value of this array will be NULL.
4444
*/
45-
char** laco_line_to_words(char* line);
45+
char** laco_split_by(const char* split_with, char* string);
4646

4747
#endif /* LACO_UTIL_H */

0 commit comments

Comments
 (0)