diff options
author | Neil <nyamatongwe@gmail.com> | 2023-02-12 12:01:21 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2023-02-12 12:01:21 +1100 |
commit | 80a1e22a987c4e749dd03500edc3ac4e189537c5 (patch) | |
tree | 1dc58be5e57c8c77036e2201806ac7f20dd38dfb | |
parent | 1b585d29ad82606c327294837e27ffcd7a66172b (diff) | |
download | scintilla-mirror-80a1e22a987c4e749dd03500edc3ac4e189537c5.tar.gz |
Feature [feature-requests:#1476] Move default representation code into
SpecialRepresentations class.
-rw-r--r-- | src/EditView.cxx | 21 | ||||
-rw-r--r-- | src/EditView.h | 1 | ||||
-rw-r--r-- | src/Editor.cxx | 45 | ||||
-rw-r--r-- | src/PositionCache.cxx | 69 | ||||
-rw-r--r-- | src/PositionCache.h | 4 |
5 files changed, 74 insertions, 66 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index f93303f6c..259ebf30d 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -178,13 +178,6 @@ void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRec } } -void Hexits(char *hexits, int ch) noexcept { - hexits[0] = 'x'; - hexits[1] = "0123456789ABCDEF"[ch / 0x10]; - hexits[2] = "0123456789ABCDEF"[ch % 0x10]; - hexits[3] = 0; -} - } EditView::EditView() { @@ -894,20 +887,6 @@ ColourRGBA TextBackground(const EditModel &model, const ViewStyle &vsDraw, const } } -const char *ControlCharacterString(unsigned char ch) noexcept { - const char *const reps[] = { - "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", - "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", - "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", - "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" - }; - if (ch < std::size(reps)) { - return reps[ch]; - } else { - return "BAD"; - } -} - void DrawTextBlob(Surface *surface, const ViewStyle &vsDraw, PRectangle rcSegment, std::string_view text, ColourRGBA textBack, ColourRGBA textFore, bool fillBackground) { if (rcSegment.Empty()) diff --git a/src/EditView.h b/src/EditView.h index 21ef196c3..affb4663e 100644 --- a/src/EditView.h +++ b/src/EditView.h @@ -40,7 +40,6 @@ void DrawTextNoClipPhase(Surface *surface, PRectangle rc, const Style &style, XY std::string_view text, DrawPhase phase); void DrawStyledText(Surface *surface, const ViewStyle &vs, int styleOffset, PRectangle rcText, const StyledText &st, size_t start, size_t length, DrawPhase phase); -void Hexits(char *hexits, int ch) noexcept; typedef void (*DrawTabArrowFn)(Surface *surface, PRectangle rcTab, int ymid, const ViewStyle &vsDraw, Stroke stroke); diff --git a/src/Editor.cxx b/src/Editor.cxx index 273d6db2a..7144a422d 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -212,50 +212,7 @@ void Editor::Finalise() { } void Editor::SetRepresentations() { - reprs.Clear(); - - // C0 control set - const char *const reps[] = { - "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", - "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", - "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", - "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" - }; - for (size_t j=0; j < std::size(reps); j++) { - const char c[2] = { static_cast<char>(j), 0 }; - reprs.SetRepresentation(std::string_view(c, 1), reps[j]); - } - reprs.SetRepresentation("\x7f", "DEL"); - - const int dbcsCodePage = pdoc->dbcsCodePage; - // C1 control set - // As well as Unicode mode, ISO-8859-1 should use these - if (CpUtf8 == dbcsCodePage) { - const char *const repsC1[] = { - "PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA", - "HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3", - "DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA", - "SOS", "SGCI", "SCI", "CSI", "ST", "OSC", "PM", "APC" - }; - for (size_t j=0; j < std::size(repsC1); j++) { - const char c1[3] = { '\xc2', static_cast<char>(0x80+j), 0 }; - reprs.SetRepresentation(c1, repsC1[j]); - } - reprs.SetRepresentation("\xe2\x80\xa8", "LS"); - reprs.SetRepresentation("\xe2\x80\xa9", "PS"); - } - - // Invalid as single bytes in multi-byte encodings - if (dbcsCodePage) { - for (int k = 0x80; k < 0x100; k++) { - if ((CpUtf8 == dbcsCodePage) || !IsDBCSValidSingleByte(dbcsCodePage, k)) { - const char hiByte[2] = { static_cast<char>(k), 0 }; - char hexits[4]; - Hexits(hexits, k); - reprs.SetRepresentation(hiByte, hexits); - } - } - } + reprs.SetDefaultRepresentations(pdoc->dbcsCodePage); } void Editor::DropGraphics() noexcept { diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index a0b7f3129..ae8dd1e66 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -51,6 +51,7 @@ #include "CaseFolder.h" #include "Document.h" #include "UniConversion.h" +#include "DBCS.h" #include "Selection.h" #include "PositionCache.h" @@ -638,6 +639,40 @@ constexpr unsigned int KeyFromString(std::string_view charBytes) noexcept { constexpr unsigned int representationKeyCrLf = KeyFromString("\r\n"); +const char *const repsC0[] = { + "NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", + "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI", + "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", + "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US" +}; + +const char *const repsC1[] = { + "PAD", "HOP", "BPH", "NBH", "IND", "NEL", "SSA", "ESA", + "HTS", "HTJ", "VTS", "PLD", "PLU", "RI", "SS2", "SS3", + "DCS", "PU1", "PU2", "STS", "CCH", "MW", "SPA", "EPA", + "SOS", "SGCI", "SCI", "CSI", "ST", "OSC", "PM", "APC" +}; + +} + +namespace Scintilla::Internal { + +const char *ControlCharacterString(unsigned char ch) noexcept { + if (ch < std::size(repsC0)) { + return repsC0[ch]; + } else { + return "BAD"; + } +} + + +void Hexits(char *hexits, int ch) noexcept { + hexits[0] = 'x'; + hexits[1] = "0123456789ABCDEF"[ch / 0x10]; + hexits[2] = "0123456789ABCDEF"[ch % 0x10]; + hexits[3] = 0; +} + } void SpecialRepresentations::SetRepresentation(std::string_view charBytes, std::string_view value) { @@ -731,6 +766,40 @@ void SpecialRepresentations::Clear() { crlf = false; } +void SpecialRepresentations::SetDefaultRepresentations(int dbcsCodePage) { + Clear(); + + // C0 control set + for (size_t j = 0; j < std::size(repsC0); j++) { + const char c[2] = { static_cast<char>(j), 0 }; + SetRepresentation(std::string_view(c, 1), repsC0[j]); + } + SetRepresentation("\x7f", "DEL"); + + // C1 control set + // As well as Unicode mode, ISO-8859-1 should use these + if (CpUtf8 == dbcsCodePage) { + for (size_t j = 0; j < std::size(repsC1); j++) { + const char c1[3] = { '\xc2', static_cast<char>(0x80 + j), 0 }; + SetRepresentation(c1, repsC1[j]); + } + SetRepresentation("\xe2\x80\xa8", "LS"); + SetRepresentation("\xe2\x80\xa9", "PS"); + } + + // Invalid as single bytes in multi-byte encodings + if (dbcsCodePage) { + for (int k = 0x80; k < 0x100; k++) { + if ((CpUtf8 == dbcsCodePage) || !IsDBCSValidSingleByte(dbcsCodePage, k)) { + const char hiByte[2] = { static_cast<char>(k), 0 }; + char hexits[4]; + Hexits(hexits, k); + SetRepresentation(hiByte, hexits); + } + } + } +} + void BreakFinder::Insert(Sci::Position val) { const int posInLine = static_cast<int>(val); if (posInLine > nextBreak) { diff --git a/src/PositionCache.h b/src/PositionCache.h index 231b9791e..0add8319a 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -180,6 +180,9 @@ public: typedef std::map<unsigned int, Representation> MapRepresentation; +const char *ControlCharacterString(unsigned char ch) noexcept; +void Hexits(char *hexits, int ch) noexcept; + class SpecialRepresentations { MapRepresentation mapReprs; unsigned short startByteHasReprs[0x100] {}; @@ -199,6 +202,7 @@ public: return startByteHasReprs[ch] != 0; } void Clear(); + void SetDefaultRepresentations(int dbcsCodePage); }; struct TextSegment { |