C++ (Qt)template <class FormatFunc>QString regex_replace(const QString & input, const QRegExp & regex, FormatFunc format_func){ QString out = input; int pos = 0; while ((pos = regex.indexIn(out, pos)) != -1) { auto s = format_func(regex.cap(1)); out.replace( pos, regex.matchedLength(), s ); pos += s.length(); } return out;}
C++ (Qt)...QString ReplaceBlanks( const QString & src ){ QString dst; const QString & spaceTxt("&#65533;"); int srcPos = 0; TVec vec = CollectPairs(src, "<span", "</span>"); for (int i = 0; i < vec.size(); ++i) { int beg = vec[i].first; int end = vec[i].second; dst += QStringRef(&src, srcPos, beg - srcPos); for (int j = beg; j < end; ++j) dst += spaceTxt; srcPos = end; } dst += QStringRef(&src, srcPos, src.size() - srcPos); return dst;}...
C++ (Qt)dst += QStringRef(&src, srcPos, beg - srcPos);...dst += spaceTxt;