[LyX/master] Improve color test

Juergen Spitzmueller <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 6ee9961763344710282888056096727596867c8f
Author: Juergen Spitzmueller <[email protected]>
Date:   Wed Mar 11 16:42:17 2026 +0100

    Improve color test
    
    This checks for correctness of the values
---
 src/tests/dummy4checklayout.cpp | 51 +++++++++++++++++++++++++++++++++--------
 1 file changed, 42 insertions(+), 9 deletions(-)

diff --git a/src/tests/dummy4checklayout.cpp b/src/tests/dummy4checklayout.cpp
index 0f21db1dfa..b15d5c1327 100644
--- a/src/tests/dummy4checklayout.cpp
+++ b/src/tests/dummy4checklayout.cpp
@@ -25,6 +25,7 @@
 #include "output_xhtml.h"
 #include "xml.h"
 
+#include "support/lstrings.h"
 #include "support/Lexer.h"
 #include "support/Messages.h"
 
@@ -34,6 +35,8 @@ using namespace std;
 
 namespace lyx {
 
+using namespace support;
+
 // Make linker happy
 
 LaTeXColors & theLaTeXColors()
@@ -65,7 +68,7 @@ LaTeXColor LaTeXColors::getLaTeXColor(string const & /* name */)
 	return LaTeXColor();
 }
 
-bool LaTeXColor::read(lyx::support::Lexer & lex)
+bool LaTeXColor::read(Lexer & lex)
 {
 	if (!lex.next()) {
 		lex.printError("No name given for LaTeX color: `$$Token'.");
@@ -81,7 +84,7 @@ bool LaTeXColor::read(lyx::support::Lexer & lex)
 }
 
 
-bool LaTeXColor::readColor(lyx::support::Lexer & lex)
+bool LaTeXColor::readColor(Lexer & lex)
 {
 	enum LaTeXColorTags {
 		LC_CATEGORY = 1,
@@ -96,7 +99,7 @@ bool LaTeXColor::readColor(lyx::support::Lexer & lex)
 	};
 
 	// Keep these sorted alphabetically!
-	lyx::support::LexerKeyword latexColorTags[] = {
+	LexerKeyword latexColorTags[] = {
 		{ "category",             LC_CATEGORY },
 		{ "cmyk",                 LC_CMYK },
 		{ "colormodel",           LC_COLOR_MODEL },
@@ -116,10 +119,10 @@ bool LaTeXColor::readColor(lyx::support::Lexer & lex)
 		int le = lex.lex();
 		// See comment in LyXRC.cpp.
 		switch (le) {
-		case lyx::support::Lexer::LEX_FEOF:
+		case Lexer::LEX_FEOF:
 			continue;
 
-		case lyx::support::Lexer::LEX_UNDEF: // parse error
+		case Lexer::LEX_UNDEF: // parse error
 			lex.printError("Unknown LaTeXColor tag `$$Token'");
 			error = true;
 			continue;
@@ -131,13 +134,43 @@ bool LaTeXColor::readColor(lyx::support::Lexer & lex)
 		case LC_END: // end of structure
 			finished = true;
 			break;
-		case LC_GUINAME:
-		case LC_HEXNAME:
 		case LC_CATEGORY:
 		case LC_CMYK:
 		case LC_COLOR_MODEL:
-		case LC_LATEXNAME: 
-		case LC_SVG_CLASH:
+		case LC_LATEXNAME: {
+			// check if this is an ASCII string
+			lex.eatLine();
+			string const val = lex.getString();
+			if (!isAscii(val)){
+				lex.printError("Value isn't ASCII: " + val);
+				error = true;
+				continue;
+			}
+			break;
+		}
+		case LC_HEXNAME: {
+			// check if this is a Hex color
+			lex.eatLine();
+			docstring const val = trim(lex.getDocString(true));
+			if (val.size() != 6 || !isHex(val)){
+				lex.printError("Value isn't proper hex color: " + to_utf8(val));
+				error = true;
+				continue;
+			}
+			break;
+		}
+		case LC_SVG_CLASH: {
+			// check if this is an ASCII string
+			lex.eatLine();
+			string const val = lowercase(lex.getString());
+			if (val != "0" && val != "1" && val != "true" && val != "false") {
+				lex.printError("Value isn't proper boolean: " + val);
+				error = true;
+				continue;
+			}
+			break;
+		}
+		case LC_GUINAME:
 		case LC_REQUIRES: {
 			// simply eat the value
 			lex.eatLine();
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.