+
+ if (http_pos >= remaining_in_output) {
+ // Http not in range, grab until space or EOL, halt as normal.
+ // Note this works because (http_pos = npos) is unsigned(-1)
+
+ mark_newline = true;
+ } else if (http_pos == 0) {
+ // At http, grab ALL until FIRST whitespace or end marker. loop.
+ // If at end of string, next loop will be empty string to mark end of weblink.
+
+ frag_length = 6; // Frag is at least "http://"
+
+ // Chars to mark end of weblink
+ // TODO? replace this with a safer (slower) regex whitelist?
+ static const std::wstring delim_chars = L"\'\";,";
+ wchar_t tempchar = linestring[in_pos+frag_length];
+ while (frag_length < remaining_in_input &&
+ !iswspace(tempchar) &&
+ delim_chars.find(tempchar) == std::wstring::npos) {
+ ++frag_length;
+ tempchar = linestring[in_pos+frag_length];
+ }
+
+ space_pos = frag_length - 1;
+ // This frag may need to be force-split. That's ok, urls aren't "words"
+ if (frag_length >= remaining_in_output) {
+ mark_newline = true;
+ }
+ } else {
+ // Http in range, grab until http, loop
+
+ space_pos = http_pos - 1;
+ frag_length = http_pos;
+ }
+
+ // Include trailing space in current frag