@shd101wyy/yo 0.1.22 → 0.1.23

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shd101wyy/yo",
3
3
  "displayName": "Yo",
4
- "version": "0.1.22",
4
+ "version": "0.1.23",
5
5
  "main": "./out/cjs/index.cjs",
6
6
  "module": "./out/esm/index.mjs",
7
7
  "types": "./out/types/src/index.d.ts",
@@ -4,11 +4,11 @@
4
4
  //! Mirrors the layout of Rust's `std::env`. Platform/architecture detection
5
5
  //! and child-process spawning live in `std/process`.
6
6
 
7
- open import "../collections/array_list";
8
- open import "../string";
9
- open import "../path";
10
- { platform, Platform } :: import "../process";
11
- { GlobalAllocator } :: import "../allocator";
7
+ open import "./collections/array_list";
8
+ open import "./string";
9
+ open import "./path";
10
+ { platform, Platform } :: import "./process";
11
+ { GlobalAllocator } :: import "./allocator";
12
12
  { malloc, free } :: GlobalAllocator;
13
13
 
14
14
  // === Low-level C interface ===
@@ -63,7 +63,7 @@ export args;
63
63
 
64
64
  /// Environment variable access and manipulation.
65
65
  env :: impl {
66
- { getenv, setenv } :: import "../libc/stdlib";
66
+ { getenv, setenv } :: import "./libc/stdlib";
67
67
 
68
68
  /// Get the value of an environment variable by name.
69
69
  /// Returns `.None` if the variable is not set.
@@ -85,7 +85,7 @@ env :: impl {
85
85
 
86
86
  result := cond(
87
87
  (platform == Platform.Windows) => {
88
- { _putenv_s } :: import "../libc/windows";
88
+ { _putenv_s } :: import "./libc/windows";
89
89
 
90
90
  cond(
91
91
  overwrite =>
@@ -119,7 +119,7 @@ export env;
119
119
  cwd :: (fn() -> Result(Path, String))(
120
120
  cond(
121
121
  (platform == Platform.Windows) => {
122
- { GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import "../libc/windows";
122
+ { GetCurrentDirectoryW, WideCharToMultiByte, CP_UTF8, WCHAR, DWORD } :: import "./libc/windows";
123
123
 
124
124
  required_size := GetCurrentDirectoryW(ulong(0), .None);
125
125
  cond(
@@ -187,7 +187,7 @@ cwd :: (fn() -> Result(Path, String))(
187
187
  )
188
188
  },
189
189
  true => {
190
- { getcwd } :: import "../libc/unistd";
190
+ { getcwd } :: import "./libc/unistd";
191
191
 
192
192
  buf_size := usize(4096);
193
193
  buf := *(char)(malloc(buf_size).unwrap());
@@ -215,7 +215,7 @@ export cwd;
215
215
  chdir :: (fn(path: Path) -> Result(unit, String))(
216
216
  cond(
217
217
  (platform == Platform.Windows) => {
218
- { SetCurrentDirectoryA, BOOL } :: import "../libc/windows";
218
+ { SetCurrentDirectoryA, BOOL } :: import "./libc/windows";
219
219
 
220
220
  path_str := path.to_string();
221
221
  path_cstr := path_str.to_cstr().ptr().unwrap();
@@ -227,7 +227,7 @@ chdir :: (fn(path: Path) -> Result(unit, String))(
227
227
  )
228
228
  },
229
229
  true => {
230
- { chdir : unix_chdir } :: import "../libc/unistd";
230
+ { chdir : unix_chdir } :: import "./libc/unistd";
231
231
 
232
232
  path_str := path.to_string();
233
233
  path_cstr := path_str.to_cstr().ptr().unwrap();
@@ -1,7 +1,7 @@
1
1
  //! Glob pattern matching for file paths.
2
2
 
3
- open import "../string";
4
- { ArrayList } :: import "../collections/array_list";
3
+ open import "./string";
4
+ { ArrayList } :: import "./collections/array_list";
5
5
 
6
6
  // Recursive byte-level glob pattern matching
7
7
  _glob_match_impl :: (fn(pb: ArrayList(u8), pi: usize, tb: ArrayList(u8), ti: usize) -> bool)({
@@ -1,8 +1,8 @@
1
1
  //! Structured logging with configurable level and output destination.
2
2
 
3
- open import "../string";
4
- { ToString } :: import "../fmt";
5
- { fwrite, stdout, stderr, FILE } :: import "../libc/stdio";
3
+ open import "./string";
4
+ { ToString } :: import "./fmt";
5
+ { fwrite, stdout, stderr, FILE } :: import "./libc/stdio";
6
6
 
7
7
  /// Log severity level.
8
8
  Level :: enum(Trace, Debug, Info, Warn, Error);
@@ -1,6 +1,7 @@
1
1
  //! Mutable UTF-8 string builder for efficient incremental construction.
2
2
 
3
3
  { ArrayList } :: import "../collections/array_list.yo";
4
+ { rune } :: import "./rune.yo";
4
5
  { String } :: import "./string.yo";
5
6
 
6
7
  /**
@@ -93,6 +94,40 @@ impl(StringBuilder,
93
94
  self._buf.push(b);
94
95
  }),
95
96
 
97
+ /**
98
+ * Append a single Unicode code point, encoded as UTF-8.
99
+ *
100
+ * ## Example
101
+ * ```rust
102
+ * sb := StringBuilder.new();
103
+ * sb.write_rune(rune(0x1F600)); // 😀
104
+ * sb.write_rune(rune(0x41)); // 'A'
105
+ * ```
106
+ */
107
+ write_rune : (fn(self: *(Self), r: rune) -> unit)({
108
+ cp := r.char;
109
+ cond(
110
+ (cp < u32(0x80)) => {
111
+ self._buf.push(u8(cp));
112
+ },
113
+ (cp < u32(0x800)) => {
114
+ self._buf.push(u8((u32(0xC0) | (cp >> u32(6)))));
115
+ self._buf.push(u8((u32(0x80) | (cp & u32(0x3F)))));
116
+ },
117
+ (cp < u32(0x10000)) => {
118
+ self._buf.push(u8((u32(0xE0) | (cp >> u32(12)))));
119
+ self._buf.push(u8((u32(0x80) | ((cp >> u32(6)) & u32(0x3F)))));
120
+ self._buf.push(u8((u32(0x80) | (cp & u32(0x3F)))));
121
+ },
122
+ true => {
123
+ self._buf.push(u8((u32(0xF0) | (cp >> u32(18)))));
124
+ self._buf.push(u8((u32(0x80) | ((cp >> u32(12)) & u32(0x3F)))));
125
+ self._buf.push(u8((u32(0x80) | ((cp >> u32(6)) & u32(0x3F)))));
126
+ self._buf.push(u8((u32(0x80) | (cp & u32(0x3F)))));
127
+ }
128
+ );
129
+ }),
130
+
96
131
  /**
97
132
  * Append a `String` followed by a newline byte (`\n`).
98
133
  */