Upgrade to ExtJS 3.1.0 - Released 12/16/2009
[extjs.git] / src / util / Format.js
index 747ed1a..80659aa 100644 (file)
@@ -1,5 +1,5 @@
 /*!
- * Ext JS Library 3.0.3
+ * Ext JS Library 3.1.0
  * Copyright(c) 2006-2009 Ext JS, LLC
  * licensing@extjs.com
  * http://www.extjs.com/license
  * @singleton\r
  */\r
 Ext.util.Format = function(){\r
-    var trimRe = /^\s+|\s+$/g;\r
+    var trimRe = /^\s+|\s+$/g,\r
+        stripTagsRE = /<\/?[^>]+>/gi,\r
+        stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,\r
+        nl2brRe = /\r?\n/g;\r
+        \r
     return {\r
         /**\r
          * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length\r
@@ -22,8 +26,8 @@ Ext.util.Format = function(){
         ellipsis : function(value, len, word){\r
             if(value && value.length > len){\r
                 if(word){\r
-                    var vs = value.substr(0, len - 2);\r
-                    var index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));\r
+                    var vs = value.substr(0, len - 2),\r
+                        index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));\r
                     if(index == -1 || index < (len - 15)){\r
                         return value.substr(0, len - 3) + "...";\r
                     }else{\r
@@ -140,10 +144,10 @@ Ext.util.Format = function(){
             v = (Math.round((v-0)*100))/100;\r
             v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);\r
             v = String(v);\r
-            var ps = v.split('.');\r
-            var whole = ps[0];\r
-            var sub = ps[1] ? '.'+ ps[1] : '.00';\r
-            var r = /(\d+)(\d{3})/;\r
+            var ps = v.split('.'),\r
+                whole = ps[0],\r
+                sub = ps[1] ? '.'+ ps[1] : '.00',\r
+                r = /(\d+)(\d{3})/;\r
             while (r.test(whole)) {\r
                 whole = whole.replace(r, '$1' + ',' + '$2');\r
             }\r
@@ -180,9 +184,6 @@ Ext.util.Format = function(){
                 return Ext.util.Format.date(v, format);\r
             };\r
         },\r
-\r
-        // private\r
-        stripTagsRE : /<\/?[^>]+>/gi,\r
         \r
         /**\r
          * Strips all HTML tags\r
@@ -190,18 +191,16 @@ Ext.util.Format = function(){
          * @return {String} The stripped text\r
          */\r
         stripTags : function(v){\r
-            return !v ? v : String(v).replace(this.stripTagsRE, "");\r
+            return !v ? v : String(v).replace(stripTagsRE, "");\r
         },\r
 \r
-        stripScriptsRe : /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,\r
-\r
         /**\r
          * Strips all script tags\r
          * @param {Mixed} value The text from which to strip script tags\r
          * @return {String} The stripped text\r
          */\r
         stripScripts : function(v){\r
-            return !v ? v : String(v).replace(this.stripScriptsRe, "");\r
+            return !v ? v : String(v).replace(stripScriptsRe, "");\r
         },\r
 \r
         /**\r
@@ -350,7 +349,7 @@ Ext.util.Format = function(){
          * @return {String} The string with embedded &lt;br/> tags in place of newlines.\r
          */\r
         nl2br : function(v){\r
-            return v === undefined || v === null ? '' : v.replace(/\n/g, '<br/>');\r
+            return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');\r
         }\r
     }\r
-}();
\ No newline at end of file
+}();\r