joon hee - StandardLibrary-1.81
NAME
String - a class to construct string instances
SYNOPSIS
var str = new String("This is a string"); var ostr = str.slice(0,5); alert(ostr);
DESCRIPTION
This is a class that is used to construct String instances where as a String is a essentially an arrangement of Characters.
METHODS
Inherited
From Function.prototype: apply, call, toSource, toString, valueOf
From Object.prototype: hasOwnProperty, isPrototypeOf, propertyIsEnumerable, unwatch, watch
charAt(Number index) Returns String
charCodeAt(Number index) Returns Number
concat(*@strings) Returns String
indexOf(String searchString, Number searchStart) returns Number
lastIndexOf(String searchString, Number searchStart) Returns Number
localeCompare() Returns Number
match(Regexp regexp) Returns Array
quote() Returns String
replace(String|RegExp separator, String|RegExp replacement) Returns String
String.prototype.replace = function(seperator, replacement) { var isRegExp = seperator.constructor.toSource().indexOf("RegExp") !== -1; if( isRegExp ) { return this.split(seperator).join(replacement); } else { return ''; } };
search(Regexp regexp) Returns Number
slice(Number startIndex, Number endIndex) Returns String
split(String|RegExp separator) Returns Array
substr(Number fromIndex, Number amount) Returns String
substring(Number index1, Number index2) Returns String
toLocaleLowerCase() Returns String
toLocaleUpperCase() Returns String
toLowerCase() Returns String
toUpperCase() Returns String
toSource() Returns String
toString() Returns String
trim() Returns String
trimLeft() Returns String
trimRight() Returns String
valueOf() Returns String
HTML WRAPPERS
anchor(String href) Returns String
bold() Returns String
big() Returns String
blink() Returns String
fixed() Returns String
fontcolor() Returns String
fontsize() Returns String
italics() Returns String
small() Returns String
strike() Returns String
sub() Returns String
sup() Returns String
AUTHOR
Jhuni, <jhuni_x@yahoo.com>
COPYRIGHT
Public Domain
/*=pod =head1 NAME String - a class to construct string instances =head1 SYNOPSIS var str = new String("This is a string"); var ostr = str.slice(0,5); alert(ostr); =head1 DESCRIPTION This is a class that is used to construct String instances where as a String is a essentially an arrangement of Characters. =head1 METHODS =head2 Inherited From Function.prototype: apply, call, toSource, toString, valueOf From Object.prototype: hasOwnProperty, isPrototypeOf, propertyIsEnumerable, unwatch, watch =cut*/ /*=pod =head2 charAt(Number index) Returns String =head2 charCodeAt(Number index) Returns Number =cut*/ /*=pod =head2 concat(*@strings) Returns String =cut*/ String.prototype.concat = function(/* Str *@strings */) { var rval = this+''; for( var i = 0, l = arguments.length; i<l;i++ ) { rval += arguments[i]; } return rval; }; /*=pod =head2 indexOf(String searchString, Number searchStart) returns Number =cut*/ String.prototype.indexOf = function(searchString, searchStart) { var searchStart = (typeof searchStart === 'undefined') ? 0 : searchStart; var searchLength = searchString.length; var endPoint = this.length - searchLength + 1; for( var startPoint = searchStart; startPoint < endPoint; startPoint++ ) { var isMatch = true; for( var i = 0; i < searchLength; i++ ) { if( this.charAt(startPoint+i) !== searchString.charAt(i) ) { isMatch = false; break; } } if( isMatch ) { return startPoint; } } return -1; }; /*=pod =head2 lastIndexOf(String searchString, Number searchStart) Returns Number =cut*/ String.prototype.lastIndexOf = function(searchString,searchStart) { var str = (typeof searchStart !== 'undefined') ?this.substr(0,searchStart+1) : this.toString(); str = str.split('').reverse().join(''); var index = str.indexOf(searchString); return( (index === -1) ? -1 : (str.length - 1 - index) ); }; /*=pod =head2 localeCompare() Returns Number =head2 match(Regexp regexp) Returns Array =cut*/ /*=pod =head2 quote() Returns String =cut*/ String.prototype.quote = function() { return '"' + this.replace(/\\/g,"\\\\").replace(/"/g, "\\\"").replace(/\n/, "\\n") + '"'; }; /*=pod =head2 replace(String|RegExp separator, String|RegExp replacement) Returns String String.prototype.replace = function(seperator, replacement) { var isRegExp = seperator.constructor.toSource().indexOf("RegExp") !== -1; if( isRegExp ) { return this.split(seperator).join(replacement); } else { return ''; } }; =cut*/ /*=pod =head2 search(Regexp regexp) Returns Number =cut*/ String.prototype.search = function(regexp) { var spaces = this.split(regexp); if( spaces.length === 1 ) { return -1; } return( spaces[0].length ); }; /*=pod =head2 slice(Number startIndex, Number endIndex) Returns String =cut*/ String.prototype.slice = function(startIndex, endIndex) { var startIndex = (typeof startIndex === 'undefined') ? 0 : startIndex; var endIndex = (typeof endIndex === 'undefined') ? this.length : endIndex; var rval = ''; for( var i = startIndex; i < endIndex; i++ ) { rval += this.charAt(i); } return rval; }; /*=pod =head2 split(String|RegExp separator) Returns Array =cut*/ /*=pod =head2 substr(Number fromIndex, Number amount) Returns String =cut*/ String.prototype.substr = function(fromIndex, amount) { var fromIndex = (typeof fromIndex === 'undefined') ? 0 : fromIndex; var amount = (typeof amount === 'undefined') ? this.length : amount; var rval = ''; var endpoint = fromIndex+amount; for( var i = fromIndex; i < endpoint; i++ ) { rval += this.charAt(i); } return rval; }; /*=pod =head2 substring(Number index1, Number index2) Returns String =cut*/ String.prototype.substring = function(index1, index2) { var index1 = (typeof index1 === 'undefined') ? 0 : index1; var index2 = (typeof index2 === 'undefined') ? this.length : index2; var startIndex = (index1 > index2) ? index2 : index1; var endIndex = (index1 > index2) ? index1 : index2; var rval = ''; for( ; startIndex < endIndex; startIndex++ ) { rval += this.charAt(startIndex); } return rval; }; /*=pod =head2 toLocaleLowerCase() Returns String =head2 toLocaleUpperCase() Returns String =head2 toLowerCase() Returns String =head2 toUpperCase() Returns String =cut*/ (function(){ var alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; String.prototype.toUpperCase = function() { var rval = ''; var len = this.length; for( var i = 0; i < len; i++ ) { var mychar = this.charCodeAt(i); if( 122 >= mychar && mychar >= 97 ) { rval += alphabet.charAt(mychar-97+26); } else { rval += this.charAt(i); } } return rval; }; String.prototype.toLowerCase = function() { var rval = ''; var len = this.length; for( var i = 0; i < len; i++ ) { var mychar = this.charCodeAt(i); if( 90 >= mychar && mychar >= 65 ) { rval += alphabet.charAt(mychar-65); } else { rval += this.charAt(i); } } return rval; }; })(); /*=pod =head2 toSource() Returns String =cut*/ String.prototype.toSource = function() { // escape slashes is necessary: return '(new String(' + this.quote() + '))'; }; /*=pod =head2 toString() Returns String =cut*/ String.prototype.toString = function() { return this+''; }; /*=pod =head2 trim() Returns String =cut*/ String.prototype.trim = function() { return( this.replace(/^\s+|\s+$/g,'') ); }; /*=pod =head2 trimLeft() Returns String =cut*/ String.prototype.trimLeft = function() { return( this.replace(/^\s+/,'') ); }; /*=pod =head2 trimRight() Returns String =cut*/ String.prototype.trimRight = function() { return( this.replace(/\s+$/g,'') ); }; /*=pod =head2 valueOf() Returns String =cut*/ /*=pod =head1 HTML WRAPPERS =cut*/ /*=pod =head2 anchor(String href) Returns String =cut*/ String.prototype.anchor = function(href) { return '<a name="' + href + '">' + this + '</a>'; }; /*=pod =head2 bold() Returns String =cut*/ String.prototype.bold = function() { return '<b>' + this + '</b>'; }; /*=pod =head2 big() Returns String =cut*/ String.prototype.big = function() { return '<big>' + this + '</big>'; }; /*=pod =head2 blink() Returns String =cut*/ String.prototype.blink = function() { return '<blink>' + this + '</blink>'; }; /*=pod =head2 fixed() Returns String =cut*/ String.prototype.fixed = function() { return '<tt>' + this + '</tt>'; }; /*=pod =head2 fontcolor() Returns String =cut*/ String.prototype.fontcolor = function(color) { return '<font color="' + color + '">' + this + '</font>'; }; /*=pod =head2 fontsize() Returns String =cut*/ String.prototype.fontsize = function(size) { return '<font size="' + size + '">' + this + '</font>'; }; /*=pod =head2 italics() Returns String =cut*/ String.prototype.italics = function() { return '<i>' + this + '</i>'; }; /*=pod =head2 small() Returns String =cut*/ String.prototype.small = function() { return '<small>' + this + '</small>'; }; /*=pod =head2 strike() Returns String =cut*/ String.prototype.strike = function() { return '<strike>' + this + '</strike>'; }; /*=pod =head2 sub() Returns String =cut*/ String.prototype.sub = function() { return '<sub>' + this + '</sub>'; }; /*=pod =head2 sup() Returns String =cut*/ String.prototype.sup = function() { return '<sup>' + this + '</sup>'; }; /*=pod =head1 AUTHOR Jhuni, <jhuni_x@yahoo.com> =head1 COPYRIGHT Public Domain =cut*/