summaryrefslogtreecommitdiff
path: root/tools/slang-generate/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/slang-generate/main.cpp')
-rw-r--r--tools/slang-generate/main.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/tools/slang-generate/main.cpp b/tools/slang-generate/main.cpp
index 046b2063c..7c0e3672a 100644
--- a/tools/slang-generate/main.cpp
+++ b/tools/slang-generate/main.cpp
@@ -554,30 +554,26 @@ void emitSimpleText(
FILE* stream,
StringSpan const& span)
{
- char const* cursor = span.begin();
- char const* end = span.end();
-
- while (cursor != end)
+ UnownedStringSlice content = span;
+ while (true)
{
- int c = *cursor++;
- switch (c)
+ const auto line = StringUtil::extractLine(content);
+ if (line.begin() == nullptr)
{
- default:
- fprintf(stream, "%c", c);
break;
+ }
- case '\r': case '\n':
- if (cursor != end)
- {
- int d = *cursor;
- if ((c ^ d) == ('\r' ^ '\n'))
- {
- cursor++;
- }
- fprintf(stream, "\n");
- }
+ // Write the line
+ fwrite(line.begin(), 1, line.size(), stream);
+
+ // Specially handle the 'final line', excluding an empty line after \n.
+ // We can detect, as if input ends with 'cr/lf' combination, content.begin == span.end(), else if content.begin() == nullptr.
+ if (content.begin() == nullptr || content.begin() == span.end())
+ {
break;
}
+
+ fprintf(stream, "\n");
}
}