Functions | Variables

/home/ivan/src/sit/branches/3.x/scripts/dojo/src/string/extras.js File Reference

Go to the source code of this file.

Functions

dojo provide ("dojo.string.extras")
dojo require ("dojo.string.common")

Variables

dojo string substituteParams
dojo string capitalize
dojo string isBlank
dojo string encodeAscii
dojo string escape
dojo string escapeXml
dojo string escapeString
dojo string summary
dojo string endsWith
dojo string endsWithAny
dojo string startsWith
dojo string startsWithAny
dojo string has
dojo string normalizeNewlines
dojo string splitEscaped

Function Documentation

dojo provide ( "dojo.string.extras"   ) 
dojo require ( "dojo.string.common"   ) 

Variable Documentation

dojo string capitalize
Initial value:
 function (str) {
    if (!dojo.lang.isString(str)) {
        return "";
    }
    if (arguments.length == 0) {
        str = this;
    }
    var words = str.split(" ");
    for (var i = 0; i < words.length; i++) {
        words[i] = words[i].charAt(0).toUpperCase() + words[i].substring(1);
    }
    return words.join(" ");
}

Definition at line 26 of file extras.js.

dojo string encodeAscii
Initial value:
 function (str) {
    if (!dojo.lang.isString(str)) {
        return str;
    }
    var ret = "";
    var value = escape(str);
    var match, re = /%u([0-9A-F]{4})/i;
    while ((match = value.match(re))) {
        var num = Number("0x" + match[1]);
        var newVal = escape("&#" + num + ";");
        ret += value.substring(0, match.index) + newVal;
        value = value.substring(match.index + match[0].length);
    }
    ret += value.replace(/\+/g, "%2B");
    return ret;
}

Definition at line 45 of file extras.js.

dojo string endsWith
Initial value:
 function (str, end, ignoreCase) {
    if (ignoreCase) {
        str = str.toLowerCase();
        end = end.toLowerCase();
    }
    if ((str.length - end.length) < 0) {
        return false;
    }
    return str.lastIndexOf(end) == str.length - end.length;
}

Definition at line 108 of file extras.js.

dojo string endsWithAny
Initial value:
 function (str) {
    for (var i = 1; i < arguments.length; i++) {
        if (dojo.string.endsWith(str, arguments[i])) {
            return true;
        }
    }
    return false;
}

Definition at line 118 of file extras.js.

dojo string escape
Initial value:
 function (type, str) {
    var args = dojo.lang.toArray(arguments, 1);
    switch (type.toLowerCase()) {
      case "xml":
      case "html":
      case "xhtml":
        return dojo.string.escapeXml.apply(this, args);
      case "sql":
        return dojo.string.escapeSql.apply(this, args);
      case "regexp":
      case "regex":
        return dojo.string.escapeRegExp.apply(this, args);
      case "javascript":
      case "jscript":
      case "js":
        return dojo.string.escapeJavaScript.apply(this, args);
      case "ascii":
        return dojo.string.encodeAscii.apply(this, args);
      default:
        return str;
    }
}

Definition at line 61 of file extras.js.

dojo string escapeString
Initial value:
 function (str) {
    return ("\"" + str.replace(/(["\\])/g, "\\$1") + "\"").replace(/[\f]/g, "\\f").replace(/[\b]/g, "\\b").replace(/[\n]/g, "\\n").replace(/[\t]/g, "\\t").replace(/[\r]/g, "\\r");
}

Definition at line 99 of file extras.js.

dojo string escapeXml
Initial value:
 function (str, noSingleQuotes) {
    str = str.replace(/&/gm, "&amp;").replace(/</gm, "&lt;").replace(/>/gm, "&gt;").replace(/"/gm, "&quot;");
    if (!noSingleQuotes) {
        str = str.replace(/'/gm, "&#39;");
    }
    return str;
};
dojo.string.escapeSql = function (str) {
    return str.replace(/'/gm, "''");
};
dojo.string.escapeRegExp = function (str) {
    return str.replace(/\\/gm, "\\\\").replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1");
};
dojo.string.escapeJavaScript = function (str) {
    return str.replace(/(["'\f\b\n\t\r])/gm, "\\$1");
}

Definition at line 83 of file extras.js.

dojo string has
Initial value:
 function (str) {
    for (var i = 1; i < arguments.length; i++) {
        if (str.indexOf(arguments[i]) > -1) {
            return true;
        }
    }
    return false;
}

Definition at line 141 of file extras.js.

dojo string isBlank
Initial value:
 function (str) {
    if (!dojo.lang.isString(str)) {
        return true;
    }
    return (dojo.string.trim(str).length == 0);
}

Definition at line 39 of file extras.js.

dojo string normalizeNewlines
Initial value:
 function (text, newlineChar) {
    if (newlineChar == "\n") {
        text = text.replace(/\r\n/g, "\n");
        text = text.replace(/\r/g, "\n");
    } else {
        if (newlineChar == "\r") {
            text = text.replace(/\r\n/g, "\r");
            text = text.replace(/\n/g, "\r");
        } else {
            text = text.replace(/([^\r])\n/g, "$1\r\n").replace(/\r([^\n])/g, "\r\n$1");
        }
    }
    return text;
}

Definition at line 149 of file extras.js.

dojo string splitEscaped
Initial value:
 function (str, charac) {
    var components = [];
    for (var i = 0, prevcomma = 0; i < str.length; i++) {
        if (str.charAt(i) == "\\") {
            i++;
            continue;
        }
        if (str.charAt(i) == charac) {
            components.push(str.substring(prevcomma, i));
            prevcomma = i + 1;
        }
    }
    components.push(str.substr(prevcomma));
    return components;
}

Definition at line 163 of file extras.js.

dojo string startsWith
Initial value:
 function (str, start, ignoreCase) {
    if (ignoreCase) {
        str = str.toLowerCase();
        start = start.toLowerCase();
    }
    return str.indexOf(start) == 0;
}

Definition at line 126 of file extras.js.

dojo string startsWithAny
Initial value:
 function (str) {
    for (var i = 1; i < arguments.length; i++) {
        if (dojo.string.startsWith(str, arguments[i])) {
            return true;
        }
    }
    return false;
}

Definition at line 133 of file extras.js.

dojo string substituteParams
Initial value:
 function (template, hash) {
    var map = (typeof hash == "object") ? hash : dojo.lang.toArray(arguments, 1);
    return template.replace(/\%\{(\w+)\}/g, function (match, key) {
        if (typeof (map[key]) != "undefined" && map[key] != null) {
            return map[key];
        }
        dojo.raise("Substitution not found: " + key);
    });
}

Definition at line 17 of file extras.js.

dojo string summary
Initial value:
 function (str, len) {
    if (!len || str.length <= len) {
        return str;
    }
    return str.substring(0, len).replace(/\.+$/, "") + "...";
}

Definition at line 102 of file extras.js.

For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo

© 2008-2011 Support Incident Tracker

Tsohost Logo