Almost there on parsing.
This commit is contained in:
parent
2f71db945a
commit
6694d3d596
|
|
@ -1,9 +1,11 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <gc.h>
|
||||||
|
|
||||||
|
|
||||||
const char *BLANKS = " \t";
|
const char *BLANKS = " \t";
|
||||||
const char *TEXT = " hi there friend";
|
const char *TEXT = " hi there fr[ie]nd";
|
||||||
/* 01234567890123456789
|
/* 01234567890123456789
|
||||||
^ ^
|
^ ^
|
||||||
*/
|
*/
|
||||||
|
|
@ -22,15 +24,19 @@ trim_leading_blanks(char *str)
|
||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
char *rest, *text;
|
char *rest, *text, *snip;
|
||||||
ptrdiff_t diff;
|
ptrdiff_t diff;
|
||||||
|
|
||||||
text = trim_leading_blanks((char *)TEXT);
|
text = trim_leading_blanks((char *)TEXT);
|
||||||
rest = strpbrk(text, " []");
|
rest = strpbrk(text, " []");
|
||||||
while (NULL != rest) {
|
while (NULL != rest) {
|
||||||
diff = rest - text;
|
diff = rest - text;
|
||||||
text = rest;
|
|
||||||
printf("%ld\n", diff);
|
printf("%ld\n", diff);
|
||||||
rest = strpbrk(++rest, " []");
|
snip = (char *)GC_malloc(diff + 1);
|
||||||
|
strncat(snip, text, diff);
|
||||||
|
printf("%s <%c>\n", snip, rest[0]);
|
||||||
|
text = ++rest;
|
||||||
|
rest = strpbrk(text, " []");
|
||||||
}
|
}
|
||||||
|
printf("%s\n", text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue