2014-10-12 13:40:08 +02:00
|
|
|
/**
|
|
|
|
* String utilities
|
|
|
|
*/
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
define(function () {
|
2014-10-12 13:40:08 +02:00
|
|
|
'use strict';
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
var Str = {};
|
2014-10-12 13:40:08 +02:00
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.lower = function(text){
|
2014-10-12 13:40:08 +02:00
|
|
|
return text.toLowerCase();
|
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.upper = function(text){
|
2014-10-12 13:40:08 +02:00
|
|
|
return text.toUpperCase();
|
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.trim = function(text){
|
2014-10-18 14:00:34 +02:00
|
|
|
if (text.trim){
|
|
|
|
return text.trim();
|
|
|
|
}
|
|
|
|
return text.replace(/^\s*|\s*$/g, '');
|
2014-10-12 13:40:08 +02:00
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.isEmpty = function(text){
|
2014-10-12 13:40:08 +02:00
|
|
|
return this.trim(text) === '';
|
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.rgxEsc = function(text){
|
2014-10-12 13:40:08 +02:00
|
|
|
function escape(e){
|
|
|
|
var a = new RegExp('\\'+e,'g');
|
|
|
|
text = text.replace(a,'\\'+e);
|
|
|
|
}
|
|
|
|
|
|
|
|
var chars = ['\\','[','^','$','.','|','?','*','+','(',')'];
|
|
|
|
for(var e=0; e<chars.length; e++){
|
|
|
|
escape(chars[e]);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
Str.matchCase = function(text, mc){
|
2014-10-12 13:40:08 +02:00
|
|
|
if(!mc){
|
|
|
|
return this.lower(text);
|
|
|
|
}
|
|
|
|
return text;
|
|
|
|
};
|
|
|
|
|
2014-10-26 11:48:13 +01:00
|
|
|
return Str;
|
|
|
|
});
|