summaryrefslogtreecommitdiff
path: root/source/slang
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang')
-rw-r--r--source/slang/slang-source-loc.cpp41
-rw-r--r--source/slang/slang-source-loc.h4
2 files changed, 9 insertions, 36 deletions
diff --git a/source/slang/slang-source-loc.cpp b/source/slang/slang-source-loc.cpp
index faa7e77c3..e6882ff55 100644
--- a/source/slang/slang-source-loc.cpp
+++ b/source/slang/slang-source-loc.cpp
@@ -212,44 +212,17 @@ const List<uint32_t>& SourceFile::getLineBreakOffsets()
if (m_lineBreakOffsets.getCount() == 0)
{
UnownedStringSlice content = getContent();
-
- char const* begin = content.begin();
- char const* end = content.end();
-
- char const* cursor = begin;
-
- // Treat the beginning of the file as a line break
- m_lineBreakOffsets.add(0);
-
- while (cursor != end)
+ char const* contentBegin = content.begin();
+
+ while (true)
{
- int c = *cursor++;
- switch (c)
+ auto line = StringUtil::extractLine(content);
+ if (line.begin() == nullptr)
{
- case '\r': case '\n':
- {
- // When we see a line-break character we need
- // to record the line break, but we also need
- // to deal with the annoying issue of encodings,
- // where a multi-byte sequence might encode
- // the line break.
-
- // Check to make sure that the EOF hasn't been reached.
- if (cursor != end)
- {
- int d = *cursor;
- if ((c ^ d) == ('\r' ^ '\n'))
- cursor++;
- }
-
- m_lineBreakOffsets.add(uint32_t(cursor - begin));
- break;
- }
- default:
- break;
+ break;
}
+ m_lineBreakOffsets.add(uint32_t(line.begin() - contentBegin));
}
-
// Note that we do *not* treat the end of the file as a line
// break, because otherwise we would report errors like
// "end of file inside string literal" with a line number
diff --git a/source/slang/slang-source-loc.h b/source/slang/slang-source-loc.h
index 632c05084..30affeaab 100644
--- a/source/slang/slang-source-loc.h
+++ b/source/slang/slang-source-loc.h
@@ -63,7 +63,7 @@ struct PathInfo
const String getMostUniqueIdentity() const;
// So simplify construction. In normal usage it's safer to use make methods over constructing directly.
- static PathInfo makeUnknown() { return PathInfo { Type::Unknown, "unknown", String() }; }
+ static PathInfo makeUnknown() { return PathInfo { Type::Unknown, String(), String() }; }
static PathInfo makeTokenPaste() { return PathInfo{ Type::TokenPaste, "token paste", String()}; }
static PathInfo makeNormal(const String& foundPathIn, const String& uniqueIdentity) { SLANG_ASSERT(uniqueIdentity.getLength() > 0 && foundPathIn.getLength() > 0); return PathInfo { Type::Normal, foundPathIn, uniqueIdentity }; }
static PathInfo makePath(const String& pathIn) { SLANG_ASSERT(pathIn.getLength() > 0); return PathInfo { Type::FoundPath, pathIn, String()}; }
@@ -219,7 +219,7 @@ enum class SourceLocType
// A source location in a format a human might like to see
struct HumaneSourceLoc
{
- PathInfo pathInfo;
+ PathInfo pathInfo = PathInfo::makeUnknown();
Int line = 0;
Int column = 0;
};