1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-01 04:20:27 +02:00
This commit is contained in:
Justin Lin
2019-07-01 10:02:12 +08:00
parent 6bb3b445b4
commit 60931ec8b9

View File

@@ -4,14 +4,15 @@
* @copyright Justin Lin, 2017
* @license https://opensource.org/licenses/lgpl-3.0.html
*
* @see https://openhome.cc/eGossip/OpenSCAD/lib-parse_number.html
* @see https://openhome.cc/eGossip/OpenSCAD/lib2-parse_number.html
*
**/
function _str_to_int(t, i = 0, mapper = [["0", 0], ["1", 1], ["2", 2], ["3", 3], ["4", 4], ["5", 5], ["6", 6], ["7", 7], ["8", 8], ["9", 9]]) =
i == len(mapper) ? -1 : (
mapper[i][0] == t ? mapper[i][1] : _str_to_int(t, i + 1)
);
function _str_to_int(t) =
let(
dict = [["0", 0], ["1", 1], ["2", 2], ["3", 3], ["4", 4], ["5", 5], ["6", 6], ["7", 7], ["8", 8], ["9", 9]],
n = dict[search(t, dict)[0]][1]
) n;
function _parse_positive_int(t, value = 0, i = 0) =
i == len(t) ? value : _parse_positive_int(t, value * pow(10, i) + _str_to_int(t[i]), i + 1);