aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2024-03-22 08:37:29 +0000
committerMario <mario@mariovavti.com>2024-03-22 08:37:29 +0000
commit1aeb05628b6a2a069c46980efbe628362c9e3e74 (patch)
treee9aed15d0cd74e0c23dcb05c7be8fe9541efdf36 /vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
parent5b7387459cf4de8f7354d81cb0392c4225714d94 (diff)
parentb464fae3bf22585888c5f3def8eded76fd48ed16 (diff)
downloadvolse-hubzilla-9.0.tar.gz
volse-hubzilla-9.0.tar.bz2
volse-hubzilla-9.0.zip
Merge branch '9.0RC'9.0
Diffstat (limited to 'vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php')
-rw-r--r--vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php54
1 files changed, 54 insertions, 0 deletions
diff --git a/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php b/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
new file mode 100644
index 000000000..755ba3320
--- /dev/null
+++ b/vendor/mmccook/php-json-canonicalization-scheme/src/Utils.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Mmccook\JsonCanonicalizator;
+
+class Utils
+{
+ /**
+ * @param array $array
+ * @return bool
+ */
+ public static function isAssoc(array $array): bool
+ {
+ $keys = array_keys($array);
+
+ return array_keys($keys) !== $keys;
+ }
+
+ public static function asHex(string $data): string
+ {
+ return rtrim(chunk_split(bin2hex($data), 2, ' '));
+ }
+
+ public static function es6NumberFormat(float $number): string
+ {
+
+ if (is_nan($number) || is_infinite($number)) {
+ throw new \RuntimeException("can't use Nan or Infinity in json");
+ }
+
+ if (0.0 === $number) {
+ return '0';
+ }
+
+ $sign = '';
+ if ($number < 0) {
+ $sign = '-';
+ $number = -$number;
+ }
+
+ if ($number < 1e+21 && $number >= 1e-6) {
+ $formatted = sprintf('%F', $number);
+ $formatted = rtrim($formatted, '0'); // first remove all zeros at the end
+ $formatted = rtrim($formatted, '.'); // If the string now ends with a decimal point, then remove it, too.
+ } else {
+ $formatted = sprintf('%e', $number);
+ $parts = explode('e', $formatted);
+ $parts[0] = rtrim($parts[0], '0');
+ $parts[0] = rtrim($parts[0], '.');
+ $formatted = implode('e', $parts);
+ }
+
+ return $sign . $formatted;
+ }
+}