Add support for regex in uigui_uncrustify.ini. This allows to parse options with separators around the '=' sign

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
pull/3/head
Michele Calgaro 1 year ago
parent 6b2298c21d
commit 160e02ddca
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

File diff suppressed because it is too large Load Diff

@ -45,6 +45,7 @@
#include <tqpopupmenu.h>
#include <tqprocess.h>
#include <tqspinbox.h>
#include <tqregexp.h>
#include <tqstringlist.h>
#include <tqtextcodec.h>
#include <tqtextstream.h>
@ -577,6 +578,8 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
{
TQFile cfgFile(filePathName);
TQString cfgFileData = TQString::null;
TQRegExp stringRegex("\"[^\"]*\"");
TQRegExp endParamRegex("\\s*(#.*)?" + m_cfgFileParameterEnding);
if (!cfgFile.exists())
{
@ -601,8 +604,16 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
// the true parameter string is longer than the false string
if (pBoolean.trueString.length() > pBoolean.falseString.length())
{
int index = -1;
// search for the true string
int index = cfgFileData.find(pBoolean.trueString, 0, false);
if (m_useRegex)
{
index = cfgFileData.find(TQRegExp(pBoolean.trueString), 0);
}
else
{
index = cfgFileData.find(pBoolean.trueString, 0, false);
}
// if true string found set the parameter value to true
if (index != -1)
{
@ -611,7 +622,14 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
// if true string not found, search for false string
else
{
index = cfgFileData.find(pBoolean.falseString, 0, false);
if (m_useRegex)
{
index = cfgFileData.find(TQRegExp(pBoolean.falseString), 0);
}
else
{
index = cfgFileData.find(pBoolean.falseString, 0, false);
}
// if false string found set the parameter value to false
if (index != -1)
{
@ -628,7 +646,15 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
else
{
// search for the false string
int index = cfgFileData.find(pBoolean.falseString, 0, false);
int index = -1;
if (m_useRegex)
{
index = cfgFileData.find(TQRegExp(pBoolean.falseString), 0);
}
else
{
index = cfgFileData.find(pBoolean.falseString, 0, false);
}
// if false string found set the parameter value to false
if (index != -1)
{
@ -637,7 +663,14 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
// if false string not found, search for true string
else
{
index = cfgFileData.find(pBoolean.trueString, 0, false);
if (m_useRegex)
{
index = cfgFileData.find(TQRegExp(pBoolean.trueString), 0);
}
else
{
index = cfgFileData.find(pBoolean.trueString, 0, false);
}
// if true string found set the parameter value to true
if (index != -1)
{
@ -656,19 +689,42 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
// Search for name of each numeric parameter and set the value found behind it.
for(const ParamNumeric &pNumeric : m_paramNumerics)
{
int index = cfgFileData.find(pNumeric.paramCallName, 0);
TQRegExp pRegEx(pNumeric.paramCallName);
int index = -1;
if (m_useRegex)
{
index = pRegEx.search(cfgFileData);
}
else
{
index = cfgFileData.find(pNumeric.paramCallName, 0);
}
// parameter was found in config file
if (index != -1)
{
// set index after the parameter name, so in front of the number
index += pNumeric.paramCallName.length();
if (m_useRegex)
{
index += pRegEx.matchedLength();
}
else
{
index += pNumeric.paramCallName.length();
}
// Find the end of the parameter by searching for set config file parameter ending. Most of
// time this is a carriage return.
int crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1);
int crPos = index + 1;
if (m_useRegex)
{
crPos = endParamRegex.search(cfgFileData, index + 1);
}
else
{
crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1);
}
// get the number and convert it to int
TQString test = cfgFileData.mid(index, crPos - index);
int paramValue = cfgFileData.mid(index, crPos - index).toInt(nullptr);
// disable the signal-slot connection. Otherwise signal is emmitted each time when value is
@ -694,7 +750,17 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
{
// The number of the found values for this parameter name.
int numberOfValues = 0;
int index = cfgFileData.find(pString.paramCallName, 0, false);
TQRegExp pRegEx(pString.paramCallName);
int index = -1;
if (m_useRegex)
{
index = pRegEx.search(cfgFileData);
}
else
{
index = cfgFileData.find(pString.paramCallName, 0, false);
}
// If parameter was found in config file
if (index != -1)
{
@ -704,26 +770,63 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
numberOfValues++;
// Set index after the parameter name, so it points to the front of the string value.
index += pString.paramCallName.length();
if (m_useRegex)
{
index += pRegEx.matchedLength();
}
else
{
index += pString.paramCallName.length();
}
// Find the end of the parameter by searching for set config file parameter ending. Most of
// time this is a carriage return.
int crPos = cfgFileData.find(m_cfgFileParameterEnding, index + 1);
int crPos = index;
if (m_useRegex)
{
crPos = stringRegex.search(cfgFileData, index);
crPos += stringRegex.matchedLength();
}
else
{
crPos = cfgFileData.find(m_cfgFileParameterEnding, index);
}
// Get the string and remember it.
TQString paramStrVal = TQString::null;
if ((crPos - index) >= 2)
{
// Remove leading and trailing quotes
paramStrVal = TQString(cfgFileData.mid(index + 1, crPos - index - 2));
}
if (numberOfValues < 2)
{
paramValueStr = TQString(cfgFileData.mid(index, crPos - index));
paramValueStr = paramStrVal;
}
// If the same parameter has been set multiple times, concatenate the strings dvivided by a
// |.
else
{
paramValueStr = paramValueStr + "|" + TQString(cfgFileData.mid(index, crPos - index));
paramValueStr = paramValueStr + "|" + paramStrVal;
}
// Ignore till end of line if regex are used (this because there could a comment
// after the string itself in the configuration file
if (m_useRegex)
{
crPos = endParamRegex.search(cfgFileData, crPos);
crPos += stringRegex.matchedLength();
}
// Get next value for this setting, if one exists.
index = cfgFileData.find(pString.paramCallName, crPos + 1, false);
if (m_useRegex)
{
index = pRegEx.search(cfgFileData, crPos);
}
else
{
index = cfgFileData.find(pString.paramCallName, crPos, false);
}
}
// Set the text for the line edit.
pString.lineEdit->setText(paramValueStr);
@ -749,6 +852,14 @@ bool IndentHandler::loadConfigFile(const TQString &filePathName)
while (i < pMultiple.choicesStrings.count() && index == -1)
{
index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false);
if (m_useRegex)
{
index = cfgFileData.find(TQRegExp(pMultiple.choicesStrings[i]), 0);
}
else
{
index = cfgFileData.find(pMultiple.choicesStrings[i], 0, false);
}
if (index != -1)
{
pMultiple.comboBox->setCurrentItem(i);
@ -865,6 +976,14 @@ void IndentHandler::readIndentIniFile(const TQString &iniFilePath)
m_outputFileName = m_indenterSettings->value("header/outputFileName").toString();
m_fileTypes = m_indenterSettings->value("header/fileTypes").toString();
m_fileTypes.replace('|', " ");
if (m_indenterSettings->value("header/useRegex").toString() == "true")
{
m_useRegex = true;
}
else
{
m_useRegex = false;
}
// read the categories names which are separated by "|"
TQString categoriesStr = m_indenterSettings->value("header/categories").toString();

@ -162,6 +162,7 @@ class IndentHandler : public TQWidget
TQString m_indenterExecutableCallString;
TQString m_indenterExecutableSuffix;
bool m_indenterProcessFinished;
bool m_useRegex;
//TODO: This function should go into a string helper/tool class/file.
TQString encodeToHTML(const TQString &text);

Loading…
Cancel
Save