void ImportList::import() { if(!selectedFile->isOpen() && !selectedFile->open(QIODevice::ReadOnly | QIODevice::Text)) return; int mapsize = ui->lwColumnOrder->count()+ui->lwAvailableColumns->count(); int map[mapsize]; // 0 - name, 1 - year, 2 - quality, 3 - IMDB for(int i = 0; map[i] = 0, i < mapsize; i++); QString regexp; for(int i = 0; i < ui->lwColumnOrder->count(); i++) { UserRoleData userData = ui->lwColumnOrder->item(i)->data(Qt::UserRole).value<UserRoleData>(); regexp = regexp + userData.regexp + ","; map[(int)userData.mapPosition] = i+1; } regexp.chop(1); QRegExp regEx(regexp); QTextStream in(selectedFile); while(!in.atEnd()) { QString line = in.readLine(); regEx.indexIn(line); QStringList caps = regEx.capturedTexts(); caps[0] = ""; MovieInfo mi; mi.setName(caps[map[0]]); mi.setYear(caps[map[1]].toInt()); mi.setQuality(caps[map[2]]); mi.setIMDBLink(caps[map[3]]); importedMovies.push_back(mi); } m_settings.beginGroup(IMPORT_GROUP); m_settings.setValue(LAST_SELECTED_FILE_KEY, ui->leFilePath->text()); m_settings.beginWriteArray(SELECTED_COLUMNS_ARRAY); for(int i = 0; i < ui->lwColumnOrder->count(); i++) { m_settings.setArrayIndex(i); m_settings.setValue(SELECTED_COLUMNS_COLUMN_KEY, ui->lwColumnOrder->item(i)->text()); } m_settings.endArray(); m_settings.endGroup(); this->accept(); }
const XMLCh *FunctionReplace::replace(const XMLCh *input, const XMLCh *pattern, const XMLCh *replacement, const XMLCh *options, MemoryManager *mm) { // Always turn off head character optimisation, since it is broken XMLBuffer optionsBuf; optionsBuf.set(options); optionsBuf.append(chLatin_H); //Now attempt to replace RegularExpression regEx(pattern, optionsBuf.getRawBuffer(), mm); #ifdef HAVE_ALLMATCHES return regEx.replace(input, replacement, mm); #else return regEx.replace(input, replacement); #endif }
bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user, QString & error) { int minNameLength = settingsCache->value("users/minnamelength", 6).toInt(); if(minNameLength < 1) minNameLength = 1; int maxNameLength = settingsCache->value("users/maxnamelength", 12).toInt(); bool allowLowercase = settingsCache->value("users/allowlowercase", true).toBool(); bool allowUppercase = settingsCache->value("users/allowuppercase", true).toBool(); bool allowNumerics = settingsCache->value("users/allownumerics", true).toBool(); bool allowPunctuationPrefix = settingsCache->value("users/allowpunctuationprefix", false).toBool(); QString allowedPunctuation = settingsCache->value("users/allowedpunctuation", "_").toString(); QString disallowedWordsStr = settingsCache->value("users/disallowedwords", "").toString(); QStringList disallowedWords = disallowedWordsStr.split(",", QString::SkipEmptyParts); disallowedWords.removeDuplicates(); QString disallowedRegExpStr = settingsCache->value("users/disallowedregexp", "").toString(); error = QString("%1|%2|%3|%4|%5|%6|%7|%8|%9").arg(minNameLength).arg(maxNameLength).arg(allowLowercase).arg(allowUppercase).arg(allowNumerics).arg(allowPunctuationPrefix).arg(allowedPunctuation).arg(disallowedWordsStr).arg(disallowedRegExpStr); if (user.length() < minNameLength || user.length() > maxNameLength) return false; if (!allowPunctuationPrefix && allowedPunctuation.contains(user.at(0))) return false; for (const QString &word : disallowedWords) { if (user.contains(word, Qt::CaseInsensitive)) return false; } for (const QRegExp ®Exp : settingsCache->disallowedRegExp) { if (regExp.exactMatch(user)) return false; } QString regEx("["); if (allowLowercase) regEx.append("a-z"); if (allowUppercase) regEx.append("A-Z"); if(allowNumerics) regEx.append("0-9"); regEx.append(QRegExp::escape(allowedPunctuation)); regEx.append("]+"); static QRegExp re = QRegExp(regEx); return re.exactMatch(user); }
int Utils::GetPiVersion(const QString &propFilePath) { int version = 0; // open devices proc file QFile propFile(propFilePath); if (!propFile.exists()) { SendMessage("Device Property file missing " + propFilePath); return 0; } if (!propFile.open(QFile::ReadOnly | QFile::Text)) { SendMessage("Could not open device property file " + propFilePath); return 0; } QString deviceDesc = propFile.readAll(); propFile.close(); // Extract Pi ver from text QRegExp regEx("Pi (\\d+)"); if (regEx.indexIn(deviceDesc)) { QStringList versionList = regEx.capturedTexts(); if (versionList.count() > 1) { bool ok; QString versionStr = versionList.at(1); SendMessage("version = " + versionStr); version = versionStr.toInt(&ok); if (ok) { return version; } } } if (!version) { SendMessage("Version not found from " + propFilePath); } return version; }
void ImportList::reloadPreview() { if(ui->lwColumnOrder->count() == 0 ) return; if(!selectedFile->isOpen() && !selectedFile->open(QIODevice::ReadOnly | QIODevice::Text)) return; QStringList header; QString regexp; for(int i = 0; i < ui->lwColumnOrder->count(); i++) { regexp = regexp + ui->lwColumnOrder->item(i)->data(Qt::UserRole).value<UserRoleData>().regexp + ","; header << ui->lwColumnOrder->item(i)->text(); } regexp.chop(1); ui->twPreview->setRowCount(0); ui->twPreview->setColumnCount(header.count()); ui->twPreview->setHorizontalHeaderLabels(header); QRegExp regEx(regexp); QTextStream in(selectedFile); for(int i = 0; i < 3 && !in.atEnd(); i++) { QString line = in.readLine(); regEx.indexIn(line); QStringList caps = regEx.capturedTexts(); ui->twPreview->insertRow(i); for(int j = 0; j < ui->twPreview->columnCount() && j < caps.count()-1; j++) ui->twPreview->setItem(i, j, new QTableWidgetItem(caps[j+1])); } ui->twPreview->resizeRowsToContents(); selectedFile->close(); }
void StatesEditorView::duplicateCurrentState() { QmlModelState state = currentState(); Q_ASSERT(!state.isBaseState()); QString newName = state.name(); // Strip out numbers at the end of the string QRegExp regEx(QString("[0-9]+$")); int numberIndex = newName.indexOf(regEx); if ((numberIndex != -1) && (numberIndex+regEx.matchedLength()==newName.length())) newName = newName.left(numberIndex); int i = 1; QStringList stateNames = rootStateGroup().names(); while (stateNames.contains(newName + QString::number(i))) i++; QmlModelState newState = state.duplicate(newName + QString::number(i)); setCurrentState(newState); }
ZStr *zStrReplace( ZStr *lines, char *matchRegEx, char *replaceStr ) { ZRegExp regEx( matchRegEx ); int lenOfReplace = strlen( replaceStr ); for( ZStr *l=lines; l; l=l->next ) { ZStr *replace = new ZStr; char *ll = l->getS(); int readOff = 0; int foundOff = 0; int foundLen = 0; while( regEx.test(ll + readOff) ) { foundOff = regEx.getPos(0) + readOff; foundLen = regEx.getLen(0); replace->appendS( ll + readOff, foundOff-readOff ); replace->appendS( replaceStr, lenOfReplace ); readOff = foundOff + foundLen; } replace->appendS( ll + foundOff+foundLen, strlen(ll)-foundOff+foundLen ); if( l->s ) { free( l->s ); } l->s = replace->s; } return lines; }
MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, wxT("STC test"), wxDefaultPosition, wxSize(1024, 768)) { TextCtrl = new wxStyledTextCtrl(this, wxID_ANY); TextCtrl->SetFocus(); // set all of the used styles to the same font // each token type has its own 'style' that can be changed // independently. wxFont font(wxFontInfo(10).AntiAliased(true).FaceName(wxT("Courier New"))); for (int i = wxSTC_H_DEFAULT; i <= wxSTC_H_QUESTION; i++) { TextCtrl->StyleSetFont(i, font); } TextCtrl->StyleSetFont(wxSTC_H_VALUE, font); for (int i = wxSTC_HPHP_DEFAULT; i <= wxSTC_HPHP_OPERATOR; i++) { TextCtrl->StyleSetFont(i, font); } TextCtrl->StyleSetFont(wxSTC_HPHP_COMPLEX_VARIABLE, font); // the lexer that highlights PHP code is the wxSTC_LEX_HTML. this lexer can handle // HTML and any embedded server side language (PHP, ASP, Python, etc..). Because of // this, the lexer has more states than all other lexers; that's why we need // to set aside more style bits for this lexer. TextCtrl->SetLexer(wxSTC_LEX_HTML); TextCtrl->SetStyleBits(7); // make the keywords bold and blue. TextCtrl->StyleSetBold(wxSTC_HPHP_WORD, true); TextCtrl->StyleSetForeground(wxSTC_HPHP_WORD, *wxBLUE); TextCtrl->SetKeyWords(0, wxT("html body")); TextCtrl->SetKeyWords(4, wxString::FromAscii("php if else do while for foreach switch case " "break default function return public private protected class " " interface extends implements static")); // make comments dark green TextCtrl->StyleSetBold(wxSTC_HPHP_COMMENT, true); TextCtrl->StyleSetBold(wxSTC_HPHP_COMMENTLINE, true); TextCtrl->StyleSetForeground(wxSTC_HPHP_COMMENT, wxTheColourDatabase->Find(wxT("Dark Green"))); TextCtrl->StyleSetBackground(wxSTC_HPHP_COMMENTLINE, wxTheColourDatabase->Find(wxT("Dark Green"))); // intialize the markers. this marker will be used to put arrows in the // left margin const int HIT_MARKER = 1; TextCtrl->MarkerDefine(HIT_MARKER, wxSTC_MARK_ARROW, *wxRED, *wxRED); TextCtrl->SetText(wxT("<?php\r\nfunction f() {\n\n}\n\n$s = \"this is a test this \";\r\n?>")); TextCtrl->Colourise(0, -1); // 128 => 8th bit on since first 7 bits of style bits are for the lexer // this means that there is only one bit left for indicators; resulting // in only 1 indicator being avaible when using scintilla with the HTML lexer. int STYLE_FIND = 128; int INDICATOR = 0; TextCtrl->IndicatorSetStyle(INDICATOR, wxSTC_INDIC_SQUIGGLE); TextCtrl->IndicatorSetForeground(INDICATOR, *wxRED); wxString text = TextCtrl->GetText(); wxRegEx regEx(wxT("this")); if (regEx.IsValid()) { size_t matchStart, matchLength; int lastHit = 0; while (regEx.Matches(text, 0)) { if (regEx.GetMatch(&matchStart, &matchLength, 0)) { printf("hit at %ld (length: %ld)\n", (lastHit + matchStart), matchLength); TextCtrl->StartStyling(lastHit + matchStart, STYLE_FIND); TextCtrl->SetStyling(matchLength, STYLE_FIND); // careful with positions; STC positions are byte offsets while // most string functions from wxString or UnicodeString or std::string // are in characters. This means that we always need to do // conversion from chars to bytes, otherwise line numbers will be off. In this case, since the // text is ASCII it is OK. int line = TextCtrl->LineFromPosition(lastHit + matchStart); // in this demo the markes will stay forever; but in an application // we must explicitly call MarkerDelete to remove // the markers. TextCtrl->MarkerAdd(line, HIT_MARKER); } lastHit = matchStart + matchLength; text = text.substr(lastHit, -1); } TextCtrl->Colourise(0, -1); } }
void MainWindow::startDocumentWriting(DocumentWriter* dw) { qDebug() << __PRETTY_FUNCTION__; if (theImageFiles.empty()) { QMessageBox::critical(this, "No images", "No images were found"); return; } // Use the first file image name as a template for the new filename prefix QString defaultPrefix = "Cropped-"; QRegExp regEx("^\\D*"); int matchPos = regEx.indexIn(theImageFiles.first()); if (matchPos != -1) { //defaultPrefix = theImageFiles.first().mid(matchPos,regEx.matchedLength()); defaultPrefix = regEx.cap() + "-crop-"; qDebug() << "Default Prefix: " << defaultPrefix; } else { qDebug() << "Default Prefix: " << defaultPrefix << " (hardcoded default)"; } // Determine the prefix for the new image files bool userOk; QString prefix = QInputDialog::getText(this, "Image Prefix", "Enter the prefix for the cropped images", QLineEdit::Normal, defaultPrefix, &userOk); if (!userOk || ( prefix == "")) { qDebug() << "User aborted"; return; } qDebug() << "User chosen prefix = " << prefix; // Have the user choose an output directory QString outputDir = QFileDialog::getExistingDirectory(this, "Choose output directory", "Choose directory to write output files"); if (outputDir.isEmpty()) { QMessageBox::critical(this, "Error", "No directory chosen to process images"); return; } qDebug() << "User chosen output directory = " << outputDir; theProcessingInProgressFlag = true; isImageProcessingAllowed(); ui->theImagesProcessedLabel->setText("Start"); ui->theImagesProcessedPb->setValue(0); // Setup the document writer with the data it needs for processing dw->setOutputInfo(outputDir, prefix); dw->setImageData(theImagePath, theImageFiles); dw->setSelectionInfo(thePagePointsList); // Connect callbacks connect(dw, SIGNAL(JobSuccessful()), this, SLOT(imageProcessingComplete())); connect(dw, SIGNAL(JobFailed(QString)), this, SLOT(imageProcessingError(QString))); connect(dw, SIGNAL(JobPercentComplete(int,int)), this, SLOT(imageProcessingStatus(int,int))); // Start the job asynchronously QThreadPool::globalInstance()->start(dw); }