From 592888b088288a131710b3e90142e7ac1178285a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Fri, 18 Mar 2016 05:30:35 +0800 Subject: [PATCH] Added Substring count function --- botanjs/src/System/utils/Perf.js | 24 ++++++++++++++++++++++-- botanjs/src/externs/System.utils.Perf.js | 2 ++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/botanjs/src/System/utils/Perf.js b/botanjs/src/System/utils/Perf.js index 4b0c82e..4e2f933 100644 --- a/botanjs/src/System/utils/Perf.js +++ b/botanjs/src/System/utils/Perf.js @@ -22,7 +22,7 @@ /* }}}*/ // Reverse an array using XOR swap - var Array_Reverse = function( array ) + var ArrayReverse = function( array ) { var i = null; var l = array.length; @@ -39,6 +39,26 @@ } }; + // Count Occurance of a string + var CountSubString = function ( str, search ) + { + if ( search.length <= 0 ) + { + return str.length + 1; + } + + var c = 0; + + for( var i = str.indexOf( search ); 0 <= i ; i = str.indexOf( search, i ) ) + { + c ++; + i ++; + } + + return c; + }; + ns[ NS_EXPORT ]( EX_READONLY_GETTER, "uuid", UUID ); - ns[ NS_EXPORT ]( EX_FUNC, "ArrayReverse", Array_Reverse ); + ns[ NS_EXPORT ]( EX_FUNC, "CountSubstr", CountSubString ); + ns[ NS_EXPORT ]( EX_FUNC, "ArrayReverse", ArrayReverse ); })(); diff --git a/botanjs/src/externs/System.utils.Perf.js b/botanjs/src/externs/System.utils.Perf.js index 756699f..8b7b6ed 100644 --- a/botanjs/src/externs/System.utils.Perf.js +++ b/botanjs/src/externs/System.utils.Perf.js @@ -6,3 +6,5 @@ System.utils.Perf.uuid; /** @type {Function} */ System.utils.Perf.ArrayReverse; +/** @type {Function} */ +System.utils.Perf.CountSubstr;