+4
-11
@@ -15,5 +15,3 @@ exports.Format = function(s, m) { | ||
| } | ||
| if ((j - i) %2 == 0) { | ||
| output = output + s[j]; | ||
| } else { | ||
| if ((j - i) %2 != 0) { | ||
| var param = ""; | ||
@@ -30,14 +28,9 @@ while (j < s.length && s[j] != ' ') { | ||
| } | ||
| if (s[j] == ' ') { | ||
| output = output + ' '; | ||
| } | ||
| } | ||
| i = j + 1; | ||
| } else { | ||
| output = output + s[i]; | ||
| i++; | ||
| i = j; | ||
| } | ||
| output = output + s[i]; | ||
| i++; | ||
| } | ||
| return output; | ||
| } |
+1
-1
| { | ||
| "name": "stringf", | ||
| "version": "1.0.0", | ||
| "version": "1.0.1", | ||
| "description": "Dead simple string formatter", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+14
-17
@@ -1,4 +0,6 @@ | ||
| # Sringf | ||
| # Sringf [](https://opensource.org/licenses/Apache-2.0) [](https://badge.fury.io/js/stringf) | ||
| Dead simple cross-language string formatter | ||
| No dependencies, O(N*m) | ||
| # Usage | ||
@@ -23,3 +25,3 @@ ## go | ||
| ## js | ||
| ``` | ||
| ```js | ||
| var stringf = require("stringf") | ||
@@ -35,12 +37,12 @@ | ||
| # Pseudocode for implement in your own language | ||
| ``` | ||
| input: | ||
| # Pseudocode to implement in your own language | ||
| ### input: | ||
| a string, s | ||
| a map string to string, paramMap | ||
| output: | ||
| ### output: | ||
| a string with param replaced | ||
| ``` | ||
| let ESCCHAR ← '#', i ← 0, output ← "" | ||
| while i < length(s) do | ||
@@ -53,6 +55,4 @@ if s[i] = ESCCHAR then | ||
| output ← output + ESCCHAR | ||
| if (j - i) mod 2 = 0 then | ||
| output ← output + s[j] | ||
| else | ||
| let param ← "" | ||
| if (j - i) mod 2 ≠ 0 then | ||
| let param ← "" (parse parameter key) | ||
| while j < length(s) and s[j] ≠ ' ' do | ||
@@ -65,9 +65,6 @@ param ← param + s[j] | ||
| return output | ||
| if s[j] = ' ' then | ||
| output ← output + ' ' | ||
| i ← j + 1 | ||
| else | ||
| output ← output + s[i] | ||
| i ← i + 1 | ||
| i ← j | ||
| output ← output + s[i] | ||
| i ← i + 1 | ||
| return output | ||
| ``` |
+4
-12
@@ -18,5 +18,3 @@ package stringf | ||
| } | ||
| if (j - i) % 2 == 0 { | ||
| output = output + string(s[j]) | ||
| } else { | ||
| if (j - i) % 2 != 0 { | ||
| param := "" | ||
@@ -31,16 +29,10 @@ for j < len(s) && s[j] != byte(' ') { | ||
| } | ||
| if j == len(s) { return output } | ||
| if s[j] == byte(' ') { | ||
| output = output + " " | ||
| } | ||
| } | ||
| i = j + 1 | ||
| } else { | ||
| output = output + string(s[i]) | ||
| i++ | ||
| i = j | ||
| } | ||
| output = output + string(s[i]) | ||
| i++ | ||
| } | ||
| return output | ||
| } |
5147
-1.42%101
-10.62%67
-4.29%