summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
299b705)
This is the first in a series of changes to the
_Wikitext_encode_link_target function to make it
more consistent with the other, similar
_Wikitext_append_sanitized_link_target function.
Signed-off-by: Wincent Colaiuta <win@wincent.com>
// thing. [[Foo]] was...
static void _Wikitext_encode_link_target(parser_t *parser)
{
// thing. [[Foo]] was...
static void _Wikitext_encode_link_target(parser_t *parser)
{
- char *input = parser->link_target->ptr;
- char *start = input; // remember this so we can check if we're at the start
+ char *src = parser->link_target->ptr;
+ char *start = src; // remember this so we can check if we're at the start
long len = parser->link_target->len;
if (!(len > 0))
return;
long len = parser->link_target->len;
if (!(len > 0))
return;
- char *end = input + len;
static char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
// to avoid most reallocations start with a destination buffer twice the size of the source
static char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
// to avoid most reallocations start with a destination buffer twice the size of the source
char *dest = ALLOC_N(char, dest_len);
char *dest_ptr = dest; // hang on to this so we can pass it to free() later
char *non_space = dest; // remember last non-space character output
char *dest = ALLOC_N(char, dest_len);
char *dest_ptr = dest; // hang on to this so we can pass it to free() later
char *non_space = dest; // remember last non-space character output
- for (; input < end; input++)
+ for (; src < end; src++)
{
if ((dest + 3) > (dest_ptr + dest_len)) // worst case: a single character may grow to 3 characters once encoded
{
{
if ((dest + 3) > (dest_ptr + dest_len)) // worst case: a single character may grow to 3 characters once encoded
{
}
// pass through unreserved characters
}
// pass through unreserved characters
- if (((*input >= 'a') && (*input <= 'z')) ||
- ((*input >= 'A') && (*input <= 'Z')) ||
- ((*input >= '0') && (*input <= '9')) ||
- (*input == '-') ||
- (*input == '_') ||
- (*input == '.') ||
- (*input == '~'))
+ if (((*src >= 'a') && (*src <= 'z')) ||
+ ((*src >= 'A') && (*src <= 'Z')) ||
+ ((*src >= '0') && (*src <= '9')) ||
+ (*src == '-') ||
+ (*src == '_') ||
+ (*src == '.') ||
+ (*src == '~'))
- else if (*input == ' ' && input == start)
+ else if (*src == ' ' && src == start)
start++; // we eat leading space
start++; // we eat leading space
- else if (*input == ' ' && parser->space_to_underscore)
+ else if (*src == ' ' && parser->space_to_underscore)
*dest++ = '_';
else // everything else gets URL-encoded
{
*dest++ = '%';
*dest++ = '_';
else // everything else gets URL-encoded
{
*dest++ = '%';
- *dest++ = hex[(unsigned char)(*input) / 16]; // left
- *dest++ = hex[(unsigned char)(*input) % 16]; // right
- if (*input != ' ')
+ *dest++ = hex[(unsigned char)(*src) / 16]; // left
+ *dest++ = hex[(unsigned char)(*src) % 16]; // right
+ if (*src != ' ')