@@ -77,6 +77,48 @@ const QList<Rules::Match> Rules::matchRules() const
7777 return m_matchRules;
7878}
7979
80+ Rules::Match::Substitution Rules::parseSubstitution (const QString &string)
81+ {
82+ if (string.at (0 ) != ' s' || string.length () < 5 )
83+ return Match::Substitution ();
84+
85+ const QChar sep = string.at (1 );
86+
87+ if (string.at (string.length () - 1 ) != sep)
88+ return Match::Substitution ();
89+
90+ int i = 2 , end = 0 ;
91+ Match::Substitution subst;
92+
93+ // Separator might have been escaped with a backslash
94+ while (i > end) {
95+ int backslashCount = 0 ;
96+ if ((end = string.indexOf (sep, i)) > -1 ) {
97+ for (i = end - 1 ; i >= 2 ; i--) {
98+ if (string.at (i) == ' \\ ' )
99+ backslashCount++;
100+ else
101+ break ;
102+ }
103+ } else {
104+ return Match::Substitution (); // error
105+ }
106+
107+ if (backslashCount % 2 != 0 ) {
108+ // Separator was escaped. Search for another one
109+ i = end + 1 ;
110+ }
111+ }
112+
113+ // Found the end of the pattern
114+ subst.pattern = QRegExp (string.mid (2 , end - 2 ));
115+ if (!subst.pattern .isValid ())
116+ return Match::Substitution (); // error
117+ subst.replacement = string.mid (end + 1 , string.length () - 1 - end - 1 );
118+
119+ return subst;
120+ }
121+
80122void Rules::load ()
81123{
82124 load (filename);
@@ -94,7 +136,9 @@ void Rules::load(const QString &filename)
94136 QRegExp matchActionLine (" action\\ s+(\\ w+)" , Qt::CaseInsensitive);
95137 QRegExp matchRepoLine (" repository\\ s+(\\ S+)" , Qt::CaseInsensitive);
96138 QRegExp matchDescLine (" description\\ s+(.+)$" , Qt::CaseInsensitive);
139+ QRegExp matchRepoSubstLine (" substitute repository\\ s+(.+)$" , Qt::CaseInsensitive);
97140 QRegExp matchBranchLine (" branch\\ s+(\\ S+)" , Qt::CaseInsensitive);
141+ QRegExp matchBranchSubstLine (" substitute branch\\ s+(.+)$" , Qt::CaseInsensitive);
98142 QRegExp matchRevLine (" (min|max) revision (\\ d+)" , Qt::CaseInsensitive);
99143 QRegExp matchAnnotateLine (" annotated\\ s+(\\ S+)" , Qt::CaseInsensitive);
100144 QRegExp matchPrefixLine (" prefix\\ s+(\\ S+)" , Qt::CaseInsensitive);
@@ -179,6 +223,22 @@ void Rules::load(const QString &filename)
179223 } else if (matchBranchLine.exactMatch (line)) {
180224 match.branch = matchBranchLine.cap (1 );
181225 continue ;
226+ } else if (matchRepoSubstLine.exactMatch (line)) {
227+ Match::Substitution subst = parseSubstitution (matchRepoSubstLine.cap (1 ));
228+ if (!subst.isValid ()) {
229+ qFatal (" Malformed substitution in rules file: line %d: %s" ,
230+ lineNumber, qPrintable (origLine));
231+ }
232+ match.repo_substs += subst;
233+ continue ;
234+ } else if (matchBranchSubstLine.exactMatch (line)) {
235+ Match::Substitution subst = parseSubstitution (matchBranchSubstLine.cap (1 ));
236+ if (!subst.isValid ()) {
237+ qFatal (" Malformed substitution in rules file: line %d: %s" ,
238+ lineNumber, qPrintable (origLine));
239+ }
240+ match.branch_substs += subst;
241+ continue ;
182242 } else if (matchRevLine.exactMatch (line)) {
183243 if (matchRevLine.cap (1 ) == " min" )
184244 match.minRevision = matchRevLine.cap (2 ).toInt ();
0 commit comments