diff options
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;  		} | 
