Add new files to git

This commit is contained in:
Abs62 2018-02-22 19:49:54 +03:00
parent c204f75e52
commit 135593f663
2 changed files with 110 additions and 0 deletions

102
wildcard.cc Normal file
View file

@ -0,0 +1,102 @@
#include <QRegularExpression>
#include "wildcard.hh"
/*
Modified function from Qt
Translates a wildcard pattern to an equivalent regular expression
pattern (e.g., *.cpp to .*\.cpp).
*/
QString wildcardsToRegexp( const QString & wc_str )
{
const int wclen = wc_str.length();
QString rx;
int i = 0;
bool isEscaping = false; // the previous character is '\'
const QChar *wc = wc_str.unicode();
while( i < wclen ) {
const QChar c = wc[ i++ ];
switch( c.unicode() ) {
case '\\':
if( isEscaping ) {
rx += QLatin1String( "\\\\" );
} // we insert the \\ later if necessary
if( i == wclen ) { // the end
rx += QLatin1String( "\\\\" );
}
isEscaping = true;
break;
case '*':
if( isEscaping ) {
rx += QLatin1String( "\\*" );
isEscaping = false;
} else {
rx += QLatin1String( ".*" );
}
break;
case '?':
if( isEscaping ) {
rx += QLatin1String( "\\?" );
isEscaping = false;
} else {
rx += QLatin1Char( '.' );
}
break;
case '$':
case '(':
case ')':
case '+':
case '.':
case '^':
case '{':
case '|':
case '}':
if( isEscaping ) {
isEscaping = false;
rx += QLatin1String( "\\\\" );
}
rx += QLatin1Char( '\\' );
rx += c;
break;
case '[':
if(isEscaping) {
isEscaping = false;
rx += QLatin1String( "\\[" );
} else {
QString tmp;
tmp += c;
while( i < wclen && wc[ i ] != QLatin1Char( ']' ) ) {
if( wc[ i ] == QLatin1Char( '\\' ) )
tmp += QLatin1Char( '\\' );
tmp += wc[ i++ ];
}
if( i < wclen )
rx += tmp;
else
rx += QRegularExpression::escape( tmp );
}
break;
case ']':
if( isEscaping ){
isEscaping = false;
rx += QLatin1String( "\\" );
}
rx += c;
break;
default:
if( isEscaping ){
isEscaping = false;
rx += QLatin1String( "\\\\" );
}
rx += c;
}
}
return rx;
}

8
wildcard.hh Normal file
View file

@ -0,0 +1,8 @@
#ifndef __WILCARD_HH_INCLUDED__
#define __WILCARD_HH_INCLUDED__
#include <QString>
QString wildcardsToRegexp( const QString & wc_str );
#endif