summaryrefslogtreecommitdiff
path: root/lib/dojo/string.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dojo/string.js')
-rw-r--r--lib/dojo/string.js162
1 files changed, 2 insertions, 160 deletions
diff --git a/lib/dojo/string.js b/lib/dojo/string.js
index 2e1cc5015..0b8ce6f4c 100644
--- a/lib/dojo/string.js
+++ b/lib/dojo/string.js
@@ -4,163 +4,5 @@
see: http://dojotoolkit.org/license for details
*/
-
-if(!dojo._hasResource["dojo.string"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
-dojo._hasResource["dojo.string"] = true;
-dojo.provide("dojo.string");
-
-dojo.getObject("string", true, dojo);
-
-/*=====
-dojo.string = {
- // summary: String utilities for Dojo
-};
-=====*/
-
-dojo.string.rep = function(/*String*/str, /*Integer*/num){
- // summary:
- // Efficiently replicate a string `n` times.
- // str:
- // the string to replicate
- // num:
- // number of times to replicate the string
-
- if(num <= 0 || !str){ return ""; }
-
- var buf = [];
- for(;;){
- if(num & 1){
- buf.push(str);
- }
- if(!(num >>= 1)){ break; }
- str += str;
- }
- return buf.join(""); // String
-};
-
-dojo.string.pad = function(/*String*/text, /*Integer*/size, /*String?*/ch, /*Boolean?*/end){
- // summary:
- // Pad a string to guarantee that it is at least `size` length by
- // filling with the character `ch` at either the start or end of the
- // string. Pads at the start, by default.
- // text:
- // the string to pad
- // size:
- // length to provide padding
- // ch:
- // character to pad, defaults to '0'
- // end:
- // adds padding at the end if true, otherwise pads at start
- // example:
- // | // Fill the string to length 10 with "+" characters on the right. Yields "Dojo++++++".
- // | dojo.string.pad("Dojo", 10, "+", true);
-
- if(!ch){
- ch = '0';
- }
- var out = String(text),
- pad = dojo.string.rep(ch, Math.ceil((size - out.length) / ch.length));
- return end ? out + pad : pad + out; // String
-};
-
-dojo.string.substitute = function( /*String*/ template,
- /*Object|Array*/map,
- /*Function?*/ transform,
- /*Object?*/ thisObject){
- // summary:
- // Performs parameterized substitutions on a string. Throws an
- // exception if any parameter is unmatched.
- // template:
- // a string with expressions in the form `${key}` to be replaced or
- // `${key:format}` which specifies a format function. keys are case-sensitive.
- // map:
- // hash to search for substitutions
- // transform:
- // a function to process all parameters before substitution takes
- // place, e.g. mylib.encodeXML
- // thisObject:
- // where to look for optional format function; default to the global
- // namespace
- // example:
- // Substitutes two expressions in a string from an Array or Object
- // | // returns "File 'foo.html' is not found in directory '/temp'."
- // | // by providing substitution data in an Array
- // | dojo.string.substitute(
- // | "File '${0}' is not found in directory '${1}'.",
- // | ["foo.html","/temp"]
- // | );
- // |
- // | // also returns "File 'foo.html' is not found in directory '/temp'."
- // | // but provides substitution data in an Object structure. Dotted
- // | // notation may be used to traverse the structure.
- // | dojo.string.substitute(
- // | "File '${name}' is not found in directory '${info.dir}'.",
- // | { name: "foo.html", info: { dir: "/temp" } }
- // | );
- // example:
- // Use a transform function to modify the values:
- // | // returns "file 'foo.html' is not found in directory '/temp'."
- // | dojo.string.substitute(
- // | "${0} is not found in ${1}.",
- // | ["foo.html","/temp"],
- // | function(str){
- // | // try to figure out the type
- // | var prefix = (str.charAt(0) == "/") ? "directory": "file";
- // | return prefix + " '" + str + "'";
- // | }
- // | );
- // example:
- // Use a formatter
- // | // returns "thinger -- howdy"
- // | dojo.string.substitute(
- // | "${0:postfix}", ["thinger"], null, {
- // | postfix: function(value, key){
- // | return value + " -- howdy";
- // | }
- // | }
- // | );
-
- thisObject = thisObject || dojo.global;
- transform = transform ?
- dojo.hitch(thisObject, transform) : function(v){ return v; };
-
- return template.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g,
- function(match, key, format){
- var value = dojo.getObject(key, false, map);
- if(format){
- value = dojo.getObject(format, false, thisObject).call(thisObject, value, key);
- }
- return transform(value, key).toString();
- }); // String
-};
-
-/*=====
-dojo.string.trim = function(str){
- // summary:
- // Trims whitespace from both sides of the string
- // str: String
- // String to be trimmed
- // returns: String
- // Returns the trimmed string
- // description:
- // This version of trim() was taken from [Steven Levithan's blog](http://blog.stevenlevithan.com/archives/faster-trim-javascript).
- // The short yet performant version of this function is dojo.trim(),
- // which is part of Dojo base. Uses String.prototype.trim instead, if available.
- return ""; // String
-}
-=====*/
-
-dojo.string.trim = String.prototype.trim ?
- dojo.trim : // aliasing to the native function
- function(str){
- str = str.replace(/^\s+/, '');
- for(var i = str.length - 1; i >= 0; i--){
- if(/\S/.test(str.charAt(i))){
- str = str.substring(0, i + 1);
- break;
- }
- }
- return str;
- };
-
-}
+//>>built
+define("dojo/string",["./_base/kernel","./_base/lang"],function(_1,_2){_2.getObject("string",true,_1);_1.string.rep=function(_3,_4){if(_4<=0||!_3){return "";}var _5=[];for(;;){if(_4&1){_5.push(_3);}if(!(_4>>=1)){break;}_3+=_3;}return _5.join("");};_1.string.pad=function(_6,_7,ch,_8){if(!ch){ch="0";}var _9=String(_6),_a=_1.string.rep(ch,Math.ceil((_7-_9.length)/ch.length));return _8?_9+_a:_a+_9;};_1.string.substitute=function(_b,_c,_d,_e){_e=_e||_1.global;_d=_d?_2.hitch(_e,_d):function(v){return v;};return _b.replace(/\$\{([^\s\:\}]+)(?:\:([^\s\:\}]+))?\}/g,function(_f,key,_10){var _11=_2.getObject(key,false,_c);if(_10){_11=_2.getObject(_10,false,_e).call(_e,_11,key);}return _d(_11,key).toString();});};_1.string.trim=String.prototype.trim?_2.trim:function(str){str=str.replace(/^\s+/,"");for(var i=str.length-1;i>=0;i--){if(/\S/.test(str.charAt(i))){str=str.substring(0,i+1);break;}}return str;};return _1.string;}); \ No newline at end of file