penguin/AstroJS

Javascript framework for my blog

commit 592888b088288a131710b3e90142e7ac1178285a

author斟酌 鵬兄 <tgckpg@gmail.com>
date2016-03-17T21:30:35Z
subjectAdded Substring count function
commit 592888b088288a131710b3e90142e7ac1178285a
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2016-03-17T21:30:35Z

    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;