|
| |||||||||||||
#include "lexer.h"#include "substitute.h"#include <stdlib.h>#include "mit-copyright.h"Go to the source code of this file.
Functions | |
| string | substitute (string(*)() lookup, string text) |
|
||||||||||||
|
Definition at line 128 of file substitute.c. References lookup(), string, string_Concat2, string_Copy, and string_CreateFromData. 00131 {
00132 string result_so_far = string_Copy("");
00133 char *p, *temp;
00134
00135 for (;;) {
00136 /*
00137 * Move [^$]* from start of text to end of result_so_far:
00138 */
00139 for (p = text; *p && (*p) != '$'; p++);
00140 if (text != p) {
00141 temp = string_CreateFromData(text, p - text);
00142 text = p;
00143 result_so_far = string_Concat2(result_so_far, temp);
00144 free(temp);
00145 }
00146
00147 /*
00148 * If text now empty, exit -- the result is in result_so_far:
00149 */
00150 if (!*text)
00151 return (result_so_far);
00152
00153 /*
00154 * Otherwise, text begins with a '$'. Eat it then call
00155 * eat_dollar_sign_stuff to process stuff after it.
00156 * Append result to result_so_far, update text, & continue.
00157 */
00158 text++;
00159 p = eat_dollar_sign_stuff(lookup, &text);
00160 result_so_far = string_Concat2(result_so_far, p);
00161 }
00162 }
|
| Last updated at Tue Dec 18 21:07:42 PST 2007. | This site and project hosted by... |