diff options
author | Neil <nyamatongwe@gmail.com> | 2018-05-14 13:57:03 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-05-14 13:57:03 +1000 |
commit | 3fc8c97d80a6797e60e6b203c9b4aa9d553df8a7 (patch) | |
tree | 9875855a197986e4ba8bf8ab1e8a491d1d1b321f /src/XPM.cxx | |
parent | 9948c490832acd4d211070adfef982d1c0e8b4c4 (diff) | |
download | scintilla-mirror-3fc8c97d80a6797e60e6b203c9b4aa9d553df8a7.tar.gz |
Modernize Platform.h (2) - noexcept, const, constexpr.
ColourDesired is an int instead of long for consistency over different platforms.
Changes made to Point, PRectangle, and ColourDesired.
RoundXYPosition removed.
Diffstat (limited to 'src/XPM.cxx')
-rw-r--r-- | src/XPM.cxx | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/src/XPM.cxx b/src/XPM.cxx index 65099a8b3..0d4a2a068 100644 --- a/src/XPM.cxx +++ b/src/XPM.cxx @@ -22,7 +22,9 @@ using namespace Scintilla; -static const char *NextField(const char *s) { +namespace { + +const char *NextField(const char *s) { // In case there are leading spaces in the string while (*s == ' ') { s++; @@ -37,13 +39,34 @@ static const char *NextField(const char *s) { } // Data lines in XPM can be terminated either with NUL or " -static size_t MeasureLength(const char *s) { +size_t MeasureLength(const char *s) { size_t i = 0; while (s[i] && (s[i] != '\"')) i++; return i; } +unsigned int ValueOfHex(const char ch) noexcept { + if (ch >= '0' && ch <= '9') + return ch - '0'; + else if (ch >= 'A' && ch <= 'F') + return ch - 'A' + 10; + else if (ch >= 'a' && ch <= 'f') + return ch - 'a' + 10; + else + return 0; +} + +ColourDesired ColourFromHex(const char *val) noexcept { + unsigned int r = ValueOfHex(val[0]) * 16 + ValueOfHex(val[1]); + unsigned int g = ValueOfHex(val[2]) * 16 + ValueOfHex(val[3]); + unsigned int b = ValueOfHex(val[4]) * 16 + ValueOfHex(val[5]); + return ColourDesired(r, g, b); +} + +} + + ColourDesired XPM::ColourFromCode(int ch) const { return colourCodeTable[ch]; } @@ -110,7 +133,7 @@ void XPM::Init(const char *const *linesForm) { colourDef += 4; ColourDesired colour(0xff, 0xff, 0xff); if (*colourDef == '#') { - colour.Set(colourDef); + colour = ColourFromHex(colourDef+1); } else { codeTransparent = code; } |