Go to the documentation of this file.
27#include <QtCore/QStringList>
28#include <QtCore/QStack>
29#include <QtCore/QRegExp>
52 ushort ec = d->escapechar.unicode();
53 State state = {
noquote,
false };
59 while (pos < str.length()) {
60 ushort cc = str.unicode()[pos].unicode();
75 rsts = rst.join( QLatin1String(
" ") );
76 rsts.replace( QRegExp(QLatin1String(
"([$`\"\\\\])")), QLatin1String(
"\\\\1") );
78 rsts = rst.join( QLatin1String(
" ") );
79 rsts.replace( QRegExp(QLatin1String(
"(['\\\\])")), QLatin1String(
"\\\\1") );
81 rsts = rst.join( QLatin1String(
" ") );
82 rsts.replace( QLatin1Char(
'\''), QLatin1String(
"'\\''") );
85 str.remove( pos, len );
92 str.replace( pos, len, rsts );
99 }
else if (cc ==
'\\') {
105 state = sstack.pop();
106 }
else if (cc ==
'$') {
107 cc = str.unicode()[++pos].unicode();
109 sstack.push( state );
110 if (str.unicode()[pos + 1].unicode() ==
'(') {
111 Save sav = { str, pos + 2 };
113 state.current =
math;
117 state.current =
paren;
118 state.dquote =
false;
120 }
else if (cc ==
'{') {
121 sstack.push( state );
122 state.current =
subst;
123 }
else if (!state.dquote) {
125 sstack.push( state );
127 }
else if (cc ==
'"') {
128 sstack.push( state );
134 }
else if (cc ==
'`') {
135 str.replace( pos, 1, QLatin1String(
"$( " ));
138 if (pos2 >= str.length()) {
142 cc = str.unicode()[pos2].unicode();
146 cc = str.unicode()[++pos2].unicode();
147 if (cc ==
'$' || cc ==
'`' || cc ==
'\\' ||
148 (cc ==
'"' && state.dquote))
150 str.remove( pos2 - 1, 1 );
156 str[pos2] = QLatin1Char(
')');
157 sstack.push( state );
158 state.current =
paren;
159 state.dquote =
false;
163 state = sstack.pop();
164 }
else if (cc ==
'\'') {
166 sstack.push( state );
169 }
else if (cc ==
'"') {
171 sstack.push( state );
175 }
else if (state.current ==
subst) {
177 state = sstack.pop();
178 }
else if (cc ==
')') {
179 if (state.current ==
math) {
180 if (str.unicode()[pos + 1].unicode() ==
')') {
181 state = sstack.pop();
186 pos = ostack.top().pos;
187 str = ostack.top().str;
189 state.current =
paren;
190 state.dquote =
false;
191 sstack.push( state );
194 }
else if (state.current ==
paren)
195 state = sstack.pop();
198 }
else if (cc ==
'}') {
200 state = sstack.pop();
203 }
else if (cc ==
'(') {
204 sstack.push( state );
205 state.current =
paren;
206 }
else if (cc ==
'{') {
207 sstack.push( state );
212 return sstack.empty();
virtual int expandPlainMacro(const QString &str, int pos, QStringList &ret)
This function is called for every single char within the string if the escape char is QChar::null.
virtual int expandEscapedMacro(const QString &str, int pos, QStringList &ret)
This function is called every time the escape char is found if it is not QChar::null.
bool expandMacrosShellQuote(QString &str, int &pos)
Perform safe macro expansion (substitution) on a string for use in shell commands.
A group of functions providing macro expansion (substitution) in strings, optionally with quoting app...
QString joinArgs(const QStringList &args)
Quotes and joins args together according to system shell rules.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 17 2025 00:00:00 by
doxygen 1.13.2 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.