From f997170c3eb0afa64d10b39b86799bad67dc5c02 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 3 Jun 2021 20:24:44 +1000 Subject: Add APIs for setting appearance (traditional blob or plain text) and colour of representations and support setting a representation for the "\r\n" line end sequence. --- src/PositionCache.cxx | 94 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 61 insertions(+), 33 deletions(-) (limited to 'src/PositionCache.cxx') diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index fb3d8fa01..8123552bd 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -534,10 +534,10 @@ std::shared_ptr LineLayoutCache::Retrieve(Sci::Line lineNumber, Sci: } // Simply pack the (maximum 4) character bytes into an int -static unsigned int KeyFromString(const char *charBytes, size_t len) noexcept { - PLATFORM_ASSERT(len <= 4); +static unsigned int KeyFromString(std::string_view charBytes) noexcept { + PLATFORM_ASSERT(charBytes.length() <= 4); unsigned int k=0; - for (size_t i=0; isecond); +const Representation *SpecialRepresentations::RepresentationFromCharacter(std::string_view charBytes) const { + if (charBytes.length() <= 4) { + const unsigned char ucStart = charBytes.empty() ? 0 : charBytes[0]; + if (!startByteHasReprs[ucStart]) + return nullptr; + MapRepresentation::const_iterator it = mapReprs.find(KeyFromString(charBytes)); + if (it != mapReprs.end()) { + return &(it->second); + } } return nullptr; } -bool SpecialRepresentations::Contains(const char *charBytes, size_t len) const { - PLATFORM_ASSERT(len <= 4); - const unsigned char ucStart = charBytes[0]; +bool SpecialRepresentations::Contains(std::string_view charBytes) const { + PLATFORM_ASSERT(charBytes.length() <= 4); + const unsigned char ucStart = charBytes.empty() ? 0 : charBytes[0]; if (!startByteHasReprs[ucStart]) return false; - MapRepresentation::const_iterator it = mapReprs.find(KeyFromString(charBytes, len)); + MapRepresentation::const_iterator it = mapReprs.find(KeyFromString(charBytes)); return it != mapReprs.end(); } @@ -675,7 +700,10 @@ TextSegment BreakFinder::Next() { else if (encodingFamily == EncodingFamily::dbcs) charWidth = pdoc->DBCSDrawBytes( std::string_view(&ll->chars[nextBreak], lineRange.end - nextBreak)); - const Representation *repr = preprs->RepresentationFromCharacter(&ll->chars[nextBreak], charWidth); + // Special case \r\n line ends if there is a representation + if (preprs->Contains("\r\n") && ll->chars[nextBreak] == '\r' && ll->chars[nextBreak + 1] == '\n') + charWidth = 2; + const Representation *repr = preprs->RepresentationFromCharacter(std::string_view(&ll->chars[nextBreak], charWidth)); if (((nextBreak > 0) && (ll->styles[nextBreak] != ll->styles[nextBreak - 1])) || repr || (nextBreak == saeNext)) { -- cgit v1.2.3