Rather than passing in a parser_t and assuming the text we want to
operate on is the one in the struct, pass in the link target str_t
explicitly. This added flexibility will make the
wiki_append_sanitized_link_target function suitable for wider use, which
I am presently going to do in order to fix a bug.
Signed-off-by: Wincent Colaiuta <win@wincent.com>
// - QUOT and AMP characters converted to named entities
// - if trim is true, leading and trailing whitespace trimmed
// - if trim is false, there is no special treatment of spaces
// - QUOT and AMP characters converted to named entities
// - if trim is true, leading and trailing whitespace trimmed
// - if trim is false, there is no special treatment of spaces
-void wiki_append_sanitized_link_target(parser_t *parser, str_t *output, bool trim)
+void wiki_append_sanitized_link_target(str_t *link_target, str_t *output, bool trim)
- char *src = parser->link_target->ptr;
+ char *src = link_target->ptr;
char *start = src; // remember this so we can check if we're at the start
char *non_space = output->ptr + output->len; // remember last non-space character output
char *start = src; // remember this so we can check if we're at the start
char *non_space = output->ptr + output->len; // remember last non-space character output
- char *end = src + parser->link_target->len;
+ char *end = src + link_target->len;
while (src < end)
{
// need at most 8 bytes to display each input character (�)
while (src < end)
{
// need at most 8 bytes to display each input character (�)
GC_WRAP_STR(parser.link_target, link_target_gc);
str_t *output = str_new();
GC_WRAP_STR(output, output_gc);
GC_WRAP_STR(parser.link_target, link_target_gc);
str_t *output = str_new();
GC_WRAP_STR(output, output_gc);
- wiki_append_sanitized_link_target(&parser, output, true);
+ wiki_append_sanitized_link_target(parser.link_target, output, true);
return string_from_str(output);
}
return string_from_str(output);
}
str_append(parser->output, link_start, sizeof(link_start) - 1);
if (parser->link_target->len > 0)
{
str_append(parser->output, link_start, sizeof(link_start) - 1);
if (parser->link_target->len > 0)
{
- wiki_append_sanitized_link_target(parser, parser->output, false);
+ wiki_append_sanitized_link_target(parser->link_target, parser->output, false);
if (scope_includes_separator)
{
str_append(parser->output, separator, sizeof(separator) - 1);
if (scope_includes_separator)
{
str_append(parser->output, separator, sizeof(separator) - 1);
{
// use link target as link text
str_clear(parser->link_text);
{
// use link target as link text
str_clear(parser->link_text);
- wiki_append_sanitized_link_target(parser, parser->link_text, true);
+ wiki_append_sanitized_link_target(parser->link_target, parser->link_text, true);
}
else
wiki_trim_link_text(parser);
}
else
wiki_trim_link_text(parser);