moar utilitys
moar utility functions
by Terrance Smith
JavaScript
//usage: var str = " somestring ".trim();
//output: "somestring"
//Credits to http://blog.stevenlevithan.com/archives/faster-trim-javascript
String.prototype.trim = function() {
"use strict";
return this.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
};
function Mid(str, start, len) {
"use strict";
// Make sure start and len are within proper bounds
if (start < 0 || len < 0) {
return "";
}
var iEnd, iLen = String(str).length;
if (start + len > iLen) {
iEnd = iLen;
} else {
iEnd = start + len;
}
return String(str).substring(start, iEnd);
}
function InStr(strSearch, charSearchFor) {
"use strict";
var i = 0;
for (i = 0; i < String(strSearch).length; i++) {
if (charSearchFor == Mid(strSearch, i, 1)) {
return i;
}
}
return -1;
}
String.isNullOrEmpty = function(value) {
"use strict";
//Credit to the following for a detailed explaination
//http://codereview.stackexchange.com/questions/5572/feedback-on-implementation-of-string-isnullorwhitespace-in-javascript
return !value;
};
function Cleanse(x) {
if (String.isNullOrWhiteSpace(x)) {
return x;
} else {
x = x.replace(" ", "");
x = x.replace(",", "");
x = x.replace("$", "");
}
return x;
}
String.isNullOrWhiteSpace = function(value) {
"use strict";
return (String.isNullOrEmpty(value.trim()));
};
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
"use strict";
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
function createThreeDimentionalArray(firstSize, secondSize, thirdSize) {
"use strict";
var threeDimArray, firstDimentionSize = firstSize,
secondDimentionSize = secondSize,
thirdDimentionSize = thirdSize,
firstDimention = new...