2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2009 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Extensions to the JavaScript Core.
\r
23 * All custom extensions functions are PascalCased to differ from the standard
\r
27 String.prototype.Contains = function( textToCheck )
\r
29 return ( this.indexOf( textToCheck ) > -1 ) ;
\r
32 String.prototype.Equals = function()
\r
34 var aArgs = arguments ;
\r
36 // The arguments could also be a single array.
\r
37 if ( aArgs.length == 1 && aArgs[0].pop )
\r
40 for ( var i = 0 ; i < aArgs.length ; i++ )
\r
42 if ( this == aArgs[i] )
\r
48 String.prototype.IEquals = function()
\r
50 var thisUpper = this.toUpperCase() ;
\r
52 var aArgs = arguments ;
\r
54 // The arguments could also be a single array.
\r
55 if ( aArgs.length == 1 && aArgs[0].pop )
\r
58 for ( var i = 0 ; i < aArgs.length ; i++ )
\r
60 if ( thisUpper == aArgs[i].toUpperCase() )
\r
66 String.prototype.ReplaceAll = function( searchArray, replaceArray )
\r
68 var replaced = this ;
\r
70 for ( var i = 0 ; i < searchArray.length ; i++ )
\r
72 replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
\r
78 String.prototype.StartsWith = function( value )
\r
80 return ( this.substr( 0, value.length ) == value ) ;
\r
83 // Extends the String object, creating a "EndsWith" method on it.
\r
84 String.prototype.EndsWith = function( value, ignoreCase )
\r
86 var L1 = this.length ;
\r
87 var L2 = value.length ;
\r
94 var oRegex = new RegExp( value + '$' , 'i' ) ;
\r
95 return oRegex.test( this ) ;
\r
98 return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
\r
101 String.prototype.Remove = function( start, length )
\r
106 s = this.substring( 0, start ) ;
\r
108 if ( start + length < this.length )
\r
109 s += this.substring( start + length , this.length ) ;
\r
114 String.prototype.Trim = function()
\r
116 // We are not using \s because we don't want "non-breaking spaces to be caught".
\r
117 return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;
\r
120 String.prototype.LTrim = function()
\r
122 // We are not using \s because we don't want "non-breaking spaces to be caught".
\r
123 return this.replace( /^[ \t\n\r]*/g, '' ) ;
\r
126 String.prototype.RTrim = function()
\r
128 // We are not using \s because we don't want "non-breaking spaces to be caught".
\r
129 return this.replace( /[ \t\n\r]*$/g, '' ) ;
\r
132 String.prototype.ReplaceNewLineChars = function( replacement )
\r
134 return this.replace( /\n/g, replacement ) ;
\r
137 String.prototype.Replace = function( regExp, replacement, thisObj )
\r
139 if ( typeof replacement == 'function' )
\r
141 return this.replace( regExp,
\r
144 return replacement.apply( thisObj || this, arguments ) ;
\r
148 return this.replace( regExp, replacement ) ;
\r
151 Array.prototype.IndexOf = function( value )
\r
153 for ( var i = 0 ; i < this.length ; i++ )
\r
155 if ( this[i] == value )
\r