line breaking in strings without inserting newlines

master
Daniel Kolesa 2016-09-24 03:31:41 +02:00
parent 64b12b442b
commit ccf24e95f5
3 changed files with 44 additions and 0 deletions

View File

@ -741,6 +741,19 @@ namespace util {
ret += writer.put(str.front());
break;
}
} else if (str.front() == '\\') {
str.pop_front();
if (str.empty()) {
break;
}
char c = str.front();
if ((c == '\r') || (c == '\n')) {
if (!str.empty() && (c == '\r') && (str.front() == '\n')) {
str.pop_front();
}
continue;
}
ret += writer.put('\\');
} else {
ret += writer.put(str.front());
}

View File

@ -45,6 +45,16 @@ static ostd::ConstCharRange cs_parse_str(ostd::ConstCharRange str) {
break;
}
return str;
case '\\':
++str;
if (!str.empty() && ((*str == '\r') || (*str == '\n'))) {
char c = *str;
++str;
if (!str.empty() && (c == '\r') && (*str == '\n')) {
++str;
}
}
continue;
}
++str;
}
@ -67,6 +77,17 @@ ostd::ConstCharRange GenState::get_str() {
break;
}
goto done;
case '\\': {
next_char();
char c = current();
if ((c == '\r') || (c == '\n')) {
if ((c == '\r') && (current(1) == '\n')) {
next_char();
}
next_char();
}
continue;
}
}
}
done:

View File

@ -199,6 +199,16 @@ namespace util {
break;
}
return str;
case '\\':
++str;
if (!str.empty() && ((*str == '\r') || (*str == '\n'))) {
char c = *str;
++str;
if (!str.empty() && (c == '\r') && (*str == '\n')) {
++str;
}
}
continue;
}
++str;
}