Feature #838

Consider adding multireplace to the Core

Added by Miroslav Fidler over 9 years ago. Updated over 9 years ago.

Status:ApprovedStart date:08/27/2014
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:-Spent time:-
Target version:-

Description

String Replace(const String& s, const VectorMap<String, String>& replace)
{
    String r;
    int i = 0;
    while(i < s.GetCount()) {
        int best = -1;
        int bestlen = 0;
        int len = s.GetCount() - i;
        const char *q = ~s + i;
        for(int j = 0; j < replace.GetCount(); j++) {
            const String& m = replace.GetKey(j);
            int l = m.GetCount();
            if(l <= len && l > bestlen && memcmp(~m, q, l) == 0) {
                bestlen = l;
                best = j;
            }
        }
        if(best >= 0) {
            i += bestlen;
            r.Cat(replace[best]);
        }
        else {
            r.Cat(*q);
            i++;
        }
    }
    return r;
}

History

#1 Updated by Miroslav Fidler over 9 years ago

  • Status changed from New to Approved

Also available in: Atom PDF