diff --git a/hwe/ts/util/simpleSerialize.ts b/hwe/ts/util/simpleSerialize.ts new file mode 100644 index 00000000..7c4c7878 --- /dev/null +++ b/hwe/ts/util/simpleSerialize.ts @@ -0,0 +1,17 @@ +import { isInteger, isString } from "lodash"; + +export function simpleSerialize(...values : (string|number)[]): string{ + const result = []; + for(const value of values){ + if(isString(value)){ + result.push(`str(${value.length},${value})`); + continue; + } + if(isInteger(value)){ + result.push(`int(${value})`); + } + const float6 = value.toLocaleString("en-US", {maximumFractionDigits: 6}); + result.push(`float(${float6})`); + } + return result.join('|'); +} \ No newline at end of file diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 7fb18f82..d18fefca 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -850,4 +850,25 @@ class Util extends \utilphp\util yield $a => $b; } } + + public static function simpleSerialize(string|int|float ...$values): string{ + $result = []; + foreach($values as $value){ + if(is_string($value)){ + $length = mb_strlen($value); + $result[] = "str({$length},{$value})"; + continue; + } + if(is_int($value)){ + $result[] = "int({$value})"; + continue; + } + if(is_float($value)){ + $value = number_format($value, 6, '.', ''); + $result[] = "float({$value})"; + continue; + } + } + return join('|', $result); + } };