Handle stretches of blanks.
Don't create zero-length strings.
This commit is contained in:
parent
9762502ea6
commit
5118881e6c
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
|
|
||||||
const char *BLANKS = " \t";
|
const char *BLANKS = " \t";
|
||||||
const char *TEXT = " hi there fr[ie]nd";
|
const char *TEXT = " hi there fr [ ie]nd";
|
||||||
/* 01234567890123456789
|
/* 01234567890123456789
|
||||||
^ ^
|
^ ^
|
||||||
*/
|
*/
|
||||||
|
|
@ -32,18 +32,23 @@ main(void)
|
||||||
while (NULL != rest) {
|
while (NULL != rest) {
|
||||||
/* How many chars have we got? */
|
/* How many chars have we got? */
|
||||||
diff = rest - text;
|
diff = rest - text;
|
||||||
printf("%ld\n", diff);
|
/*printf("%ld\n", diff);*/
|
||||||
|
|
||||||
/* Allocate and copy out the substring. */
|
if (diff) {
|
||||||
snip = (char *)GC_malloc(diff + 1);
|
/* Allocate and copy out the substring. */
|
||||||
strncat(snip, text, diff);
|
snip = (char *)GC_malloc(diff + 1);
|
||||||
printf("%s\n", snip);
|
strncat(snip, text, diff);
|
||||||
|
printf("%s\n", snip);
|
||||||
|
}
|
||||||
|
|
||||||
/* The next char is a space or '[' or ']'. */
|
/* 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);
|
text = trim_leading_blanks(++rest);
|
||||||
|
/*printf(">>>%s\n\n", text);*/
|
||||||
rest = strpbrk(text, " []");
|
rest = strpbrk(text, " []");
|
||||||
}
|
}
|
||||||
printf("%s\n", text);
|
printf("%s\n", text);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue