Changeset View
Changeset View
Standalone View
Standalone View
src/kconfig_compiler/kconfig_compiler.cpp
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Line(s) | 168 | { | |||
---|---|---|---|---|---|
170 | r.replace(QLatin1Char('\\'), QLatin1String("\\\\")); | 170 | r.replace(QLatin1Char('\\'), QLatin1String("\\\\")); | ||
171 | r.replace(QLatin1Char('\"'), QLatin1String("\\\"")); | 171 | r.replace(QLatin1Char('\"'), QLatin1String("\\\"")); | ||
172 | r.remove(QLatin1Char('\r')); | 172 | r.remove(QLatin1Char('\r')); | ||
173 | r.replace(QLatin1Char('\n'), QLatin1String("\\n\"\n\"")); | 173 | r.replace(QLatin1Char('\n'), QLatin1String("\\n\"\n\"")); | ||
174 | return QLatin1Char('\"') + r + QLatin1Char('\"'); | 174 | return QLatin1Char('\"') + r + QLatin1Char('\"'); | ||
175 | } | 175 | } | ||
176 | 176 | | |||
177 | QString literalString(const QString &s) | 177 | QString literalString(const QString &s) | ||
178 | { | 178 | { | ||
179 | bool isAscii = true; | 179 | bool isAscii = ! std::any_of(std::begin(s), std::end(s), [](QChar a) { return a.unicode() > 127; }); | ||
patrickelectric: std::any_of ? | |||||
ervin: Indeed, could be replaced by any_of since we're at it. | |||||
Nitpick: there shouldn't be a space after ! Also: use std::cbegin and std::cend (I think they're allowed nowadays) ervin: Nitpick: there shouldn't be a space after !
Also: use std::cbegin and std::cend (I think… | |||||
180 | for (int i = s.length(); i--;) | | |||
181 | if (s[i].unicode() > 127) { | | |||
182 | isAscii = false; | | |||
183 | } | | |||
184 | | ||||
185 | if (isAscii) { | 180 | if (isAscii) { | ||
186 | return QLatin1String("QStringLiteral( ") + quoteString(s) + QLatin1String(" )"); | 181 | return QLatin1String("QStringLiteral( ") + quoteString(s) + QLatin1String(" )"); | ||
187 | } else { | 182 | } else { | ||
188 | return QLatin1String("QString::fromUtf8( ") + quoteString(s) + QLatin1String(" )"); | 183 | return QLatin1String("QString::fromUtf8( ") + quoteString(s) + QLatin1String(" )"); | ||
189 | } | 184 | } | ||
190 | } | 185 | } | ||
191 | 186 | | |||
192 | 187 | | |||
▲ Show 20 Lines • Show All 584 Lines • Show Last 20 Lines |
std::any_of ?