[1349] | 1 | /* |
---|
| 2 | * FCKeditor - The text editor for Internet - http://www.fckeditor.net |
---|
| 3 | * Copyright (C) 2003-2007 Frederico Caldeira Knabben |
---|
| 4 | * |
---|
| 5 | * == BEGIN LICENSE == |
---|
| 6 | * |
---|
| 7 | * Licensed under the terms of any of the following licenses at your |
---|
| 8 | * choice: |
---|
| 9 | * |
---|
| 10 | * - GNU General Public License Version 2 or later (the "GPL") |
---|
| 11 | * http://www.gnu.org/licenses/gpl.html |
---|
| 12 | * |
---|
| 13 | * - GNU Lesser General Public License Version 2.1 or later (the "LGPL") |
---|
| 14 | * http://www.gnu.org/licenses/lgpl.html |
---|
| 15 | * |
---|
| 16 | * - Mozilla Public License Version 1.1 or later (the "MPL") |
---|
| 17 | * http://www.mozilla.org/MPL/MPL-1.1.html |
---|
| 18 | * |
---|
| 19 | * == END LICENSE == |
---|
| 20 | * |
---|
| 21 | * Extensions to the JavaScript Core. |
---|
| 22 | * |
---|
| 23 | * All custom extentions functions are PascalCased to differ from the standard |
---|
| 24 | * camelCased ones. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | String.prototype.Contains = function( textToCheck ) |
---|
| 28 | { |
---|
| 29 | return ( this.indexOf( textToCheck ) > -1 ) ; |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | String.prototype.Equals = function() |
---|
| 33 | { |
---|
| 34 | var aArgs = arguments ; |
---|
| 35 | |
---|
| 36 | // The arguments could also be a single array. |
---|
| 37 | if ( aArgs.length == 1 && aArgs[0].pop ) |
---|
| 38 | aArgs = aArgs[0] ; |
---|
| 39 | |
---|
| 40 | for ( var i = 0 ; i < aArgs.length ; i++ ) |
---|
| 41 | { |
---|
| 42 | if ( this == aArgs[i] ) |
---|
| 43 | return true ; |
---|
| 44 | } |
---|
| 45 | return false ; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | String.prototype.IEquals = function() |
---|
| 49 | { |
---|
| 50 | var thisUpper = this.toUpperCase() ; |
---|
| 51 | |
---|
| 52 | var aArgs = arguments ; |
---|
| 53 | |
---|
| 54 | // The arguments could also be a single array. |
---|
| 55 | if ( aArgs.length == 1 && aArgs[0].pop ) |
---|
| 56 | aArgs = aArgs[0] ; |
---|
| 57 | |
---|
| 58 | for ( var i = 0 ; i < aArgs.length ; i++ ) |
---|
| 59 | { |
---|
| 60 | if ( thisUpper == aArgs[i].toUpperCase() ) |
---|
| 61 | return true ; |
---|
| 62 | } |
---|
| 63 | return false ; |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | String.prototype.ReplaceAll = function( searchArray, replaceArray ) |
---|
| 67 | { |
---|
| 68 | var replaced = this ; |
---|
| 69 | |
---|
| 70 | for ( var i = 0 ; i < searchArray.length ; i++ ) |
---|
| 71 | { |
---|
| 72 | replaced = replaced.replace( searchArray[i], replaceArray[i] ) ; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | return replaced ; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | Array.prototype.AddItem = function( item ) |
---|
| 79 | { |
---|
| 80 | var i = this.length ; |
---|
| 81 | this[ i ] = item ; |
---|
| 82 | return i ; |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | Array.prototype.IndexOf = function( value ) |
---|
| 86 | { |
---|
| 87 | for ( var i = 0 ; i < this.length ; i++ ) |
---|
| 88 | { |
---|
| 89 | if ( this[i] == value ) |
---|
| 90 | return i ; |
---|
| 91 | } |
---|
| 92 | return -1 ; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | String.prototype.StartsWith = function( value ) |
---|
| 96 | { |
---|
| 97 | return ( this.substr( 0, value.length ) == value ) ; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | // Extends the String object, creating a "EndsWith" method on it. |
---|
| 101 | String.prototype.EndsWith = function( value, ignoreCase ) |
---|
| 102 | { |
---|
| 103 | var L1 = this.length ; |
---|
| 104 | var L2 = value.length ; |
---|
| 105 | |
---|
| 106 | if ( L2 > L1 ) |
---|
| 107 | return false ; |
---|
| 108 | |
---|
| 109 | if ( ignoreCase ) |
---|
| 110 | { |
---|
| 111 | var oRegex = new RegExp( value + '$' , 'i' ) ; |
---|
| 112 | return oRegex.test( this ) ; |
---|
| 113 | } |
---|
| 114 | else |
---|
| 115 | return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ; |
---|
| 116 | } |
---|
| 117 | |
---|
| 118 | String.prototype.Remove = function( start, length ) |
---|
| 119 | { |
---|
| 120 | var s = '' ; |
---|
| 121 | |
---|
| 122 | if ( start > 0 ) |
---|
| 123 | s = this.substring( 0, start ) ; |
---|
| 124 | |
---|
| 125 | if ( start + length < this.length ) |
---|
| 126 | s += this.substring( start + length , this.length ) ; |
---|
| 127 | |
---|
| 128 | return s ; |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | String.prototype.Trim = function() |
---|
| 132 | { |
---|
| 133 | // We are not using \s because we don't want "non-breaking spaces to be caught". |
---|
| 134 | return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | String.prototype.LTrim = function() |
---|
| 138 | { |
---|
| 139 | // We are not using \s because we don't want "non-breaking spaces to be caught". |
---|
| 140 | return this.replace( /^[ \t\n\r]*/g, '' ) ; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | String.prototype.RTrim = function() |
---|
| 144 | { |
---|
| 145 | // We are not using \s because we don't want "non-breaking spaces to be caught". |
---|
| 146 | return this.replace( /[ \t\n\r]*$/g, '' ) ; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | String.prototype.ReplaceNewLineChars = function( replacement ) |
---|
| 150 | { |
---|
| 151 | return this.replace( /\n/g, replacement ) ; |
---|
| 152 | } |
---|