const char *BLANKS = " \t";
-const char *TEXT = " hi there fr[ie]nd";
+const char *TEXT = " hi there fr [ ie]nd";
/* 01234567890123456789
^ ^
*/
while (NULL != rest) {
/* How many chars have we got? */
diff = rest - text;
- printf("%ld\n", diff);
+ /*printf("%ld\n", diff);*/
- /* Allocate and copy out the substring. */
- snip = (char *)GC_malloc(diff + 1);
- strncat(snip, text, diff);
- printf("%s\n", snip);
+ if (diff) {
+ /* Allocate and copy out the substring. */
+ snip = (char *)GC_malloc(diff + 1);
+ strncat(snip, text, diff);
+ printf("%s\n", snip);
+ }
/* The next char is a space or '[' or ']'. */
- printf("<%c>\n", rest[0]);
+ if ('[' == rest[0] || ']' == rest[0]) {
+ printf("%c\n", rest[0]);
+ }
/* */
text = trim_leading_blanks(++rest);
+ /*printf(">>>%s\n\n", text);*/
rest = strpbrk(text, " []");
}
printf("%s\n", text);