zsxxsz wrote:
Hi, below are the functions from Phobos and Tango with the same use, we can
see why so many people like Tango more than Phobos.

In Phobos:

string encode(string s)
{
    // The ifs are (temprarily, we hope) necessary, because
    // std.string.write.replace
    // does not do copy-on-write, but instead copies always.

    if (s.indexOf('&') != -1) s = replace(s,"&","&");
    if (s.indexOf('"') != -1) s = replace(s,"\"",""");
    if (s.indexOf("'") != -1) s = replace(s,"'","'");
    if (s.indexOf('<') != -1) s = replace(s,"<","&lt;");
    if (s.indexOf('>') != -1) s = replace(s,">","&gt;");
    return s;
}

That's from std.xml. I won't make any excuse for it, it's very inefficient.

Reply via email to