From cc78f9909b47a412f64b14bd2fc341cb5733ac0a Mon Sep 17 00:00:00 2001 From: Robert Knight Date: Sat, 17 May 2008 12:23:55 +0000 Subject: [PATCH] Better comment parsing in keyboard binding files. svn path=/trunk/KDE/kdebase/apps/konsole/; revision=808721 --- src/KeyboardTranslator.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/KeyboardTranslator.cpp b/src/KeyboardTranslator.cpp index 303df9deb..7a2571526 100644 --- a/src/KeyboardTranslator.cpp +++ b/src/KeyboardTranslator.cpp @@ -494,10 +494,24 @@ bool KeyboardTranslatorReader::parseError() } QList KeyboardTranslatorReader::tokenize(const QString& line) { - QString text = line.simplified(); + QString text = line; - // comment line: # comment - static QRegExp comment("\\#.*"); + // remove comments + bool inQuotes = false; + int commentPos = -1; + for (int i=text.length()-1;i>=0;i--) + { + QChar ch = text[i]; + if (ch == '\"') + inQuotes = !inQuotes; + else if (ch == '#' && !inQuotes) + commentPos = i; + } + if (commentPos != -1) + text.remove(commentPos,text.length()); + + text = text.simplified(); + // title line: keyboard "title" static QRegExp title("keyboard\\s+\"(.*)\""); // key line: key KeySequence : "output" @@ -505,8 +519,7 @@ QList KeyboardTranslatorReader::tokenize(const static QRegExp key("key\\s+([\\w\\+\\s\\-]+)\\s*:\\s*(\"(.*)\"|\\w+)"); QList list; - - if ( text.isEmpty() || comment.exactMatch(text) ) + if ( text.isEmpty() ) { return list; }