@auto_js/utility 0.0.9 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/platform/format.cc +29 -26
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auto_js/utility",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "author": "https://github.com/laverdet/",
5
5
  "homepage": "https://github.com/laverdet/isolated-vm/tree/experimental/packages/utility",
6
6
  "license": "ISC",
@@ -1,60 +1,62 @@
1
+ module;
2
+ #include <version>
1
3
  export module util:platform.format;
2
4
  import std;
3
5
 
4
6
  namespace util {
5
7
 
6
- #if defined(__GNUC__) && !defined(__clang__)
8
+ #if __GLIBCXX__
7
9
 
8
10
  // Claude-generated `std::format` fill to avoid gcc 16.2.0 libstdc++ requirement.
9
11
 
10
12
  template <class Type>
11
13
  struct printf_arg {
12
- static_assert(false, "type is not formattable by the `util::format` polyfill");
14
+ static_assert(false, "type is not formattable by the `util::format` polyfill");
13
15
  };
14
16
 
15
17
  template <>
16
18
  struct printf_arg<bool> {
17
- constexpr static auto spec = std::string_view{"%s"};
18
- constexpr static auto pass(bool value) { return std::tuple{value ? "true" : "false"}; }
19
+ constexpr static auto spec = std::string_view{"%s"};
20
+ constexpr static auto pass(bool value) { return std::tuple{value ? "true" : "false"}; }
19
21
  };
20
22
 
21
23
  template <>
22
24
  struct printf_arg<char> {
23
- constexpr static auto spec = std::string_view{"%c"};
24
- constexpr static auto pass(char value) { return std::tuple{value}; }
25
+ constexpr static auto spec = std::string_view{"%c"};
26
+ constexpr static auto pass(char value) { return std::tuple{value}; }
25
27
  };
26
28
 
27
29
  template <class Type>
28
30
  requires std::signed_integral<Type>
29
31
  struct printf_arg<Type> {
30
- constexpr static auto spec = std::string_view{"%lld"};
31
- constexpr static auto pass(Type value) { return std::tuple{static_cast<long long>(value)}; }
32
+ constexpr static auto spec = std::string_view{"%lld"};
33
+ constexpr static auto pass(Type value) { return std::tuple{static_cast<long long>(value)}; }
32
34
  };
33
35
 
34
36
  template <class Type>
35
37
  requires std::unsigned_integral<Type>
36
38
  struct printf_arg<Type> {
37
- constexpr static auto spec = std::string_view{"%llu"};
38
- constexpr static auto pass(Type value) { return std::tuple{static_cast<unsigned long long>(value)}; }
39
+ constexpr static auto spec = std::string_view{"%llu"};
40
+ constexpr static auto pass(Type value) { return std::tuple{static_cast<unsigned long long>(value)}; }
39
41
  };
40
42
 
41
43
  template <class Type>
42
- requires (std::same_as<Type, float> || std::same_as<Type, double>)
44
+ requires(std::same_as<Type, float> || std::same_as<Type, double>)
43
45
  struct printf_arg<Type> {
44
- constexpr static auto spec = std::string_view{"%g"};
45
- constexpr static auto pass(Type value) { return std::tuple{static_cast<double>(value)}; }
46
+ constexpr static auto spec = std::string_view{"%g"};
47
+ constexpr static auto pass(Type value) { return std::tuple{static_cast<double>(value)}; }
46
48
  };
47
49
 
48
50
  template <>
49
51
  struct printf_arg<long double> {
50
- constexpr static auto spec = std::string_view{"%Lg"};
51
- constexpr static auto pass(long double value) { return std::tuple{value}; }
52
+ constexpr static auto spec = std::string_view{"%Lg"};
53
+ constexpr static auto pass(long double value) { return std::tuple{value}; }
52
54
  };
53
55
 
54
56
  template <>
55
57
  struct printf_arg<const char*> {
56
- constexpr static auto spec = std::string_view{"%s"};
57
- constexpr static auto pass(const char* value) { return std::tuple{value}; }
58
+ constexpr static auto spec = std::string_view{"%s"};
59
+ constexpr static auto pass(const char* value) { return std::tuple{value}; }
58
60
  };
59
61
 
60
62
  template <>
@@ -62,10 +64,10 @@ struct printf_arg<char*> : printf_arg<const char*> {};
62
64
 
63
65
  template <>
64
66
  struct printf_arg<std::string_view> {
65
- constexpr static auto spec = std::string_view{"%.*s"};
66
- constexpr static auto pass(std::string_view value) {
67
- return std::tuple{static_cast<int>(value.size()), value.data()};
68
- }
67
+ constexpr static auto spec = std::string_view{"%.*s"};
68
+ constexpr static auto pass(std::string_view value) {
69
+ return std::tuple{static_cast<int>(value.size()), value.data()};
70
+ }
69
71
  };
70
72
 
71
73
  template <>
@@ -73,8 +75,8 @@ struct printf_arg<std::string> : printf_arg<std::string_view> {};
73
75
 
74
76
  template <>
75
77
  struct printf_arg<const void*> {
76
- constexpr static auto spec = std::string_view{"%p"};
77
- constexpr static auto pass(const void* value) { return std::tuple{value}; }
78
+ constexpr static auto spec = std::string_view{"%p"};
79
+ constexpr static auto pass(const void* value) { return std::tuple{value}; }
78
80
  };
79
81
 
80
82
  template <>
@@ -82,8 +84,8 @@ struct printf_arg<void*> : printf_arg<const void*> {};
82
84
 
83
85
  template <>
84
86
  struct printf_arg<std::nullptr_t> {
85
- constexpr static auto spec = std::string_view{"%p"};
86
- constexpr static auto pass(std::nullptr_t /*value*/) { return std::tuple{static_cast<const void*>(nullptr)}; }
87
+ constexpr static auto spec = std::string_view{"%p"};
88
+ constexpr static auto pass(std::nullptr_t /*value*/) { return std::tuple{static_cast<const void*>(nullptr)}; }
87
89
  };
88
90
 
89
91
  // Checks the format string against the argument types and rewrites `{}` replacement fields into
@@ -160,7 +162,8 @@ export template <class... Args>
160
162
  std::snprintf(result.data(), result.size() + 1, format.get(), values...);
161
163
  return result;
162
164
  },
163
- std::tuple_cat(printf_arg<std::decay_t<Args>>::pass(args)...));
165
+ std::tuple_cat(printf_arg<std::decay_t<Args>>::pass(args)...)
166
+ );
164
167
  }
165
168
 
166
169
  #else