| ... | ... | @@ -128,6 +128,7 @@ pub const EnvMap = struct { |
| 128 | 128 | /// Same as `put` but the key and value become owned by the EnvMap rather |
| 129 | 129 | /// than being copied. |
| 130 | 130 | /// If `putMove` fails, the ownership of key and value does not transfer. |
| 131 | /// On Windows `key` must be a valid UTF-8 string. |
| 131 | 132 | pub fn putMove(self: *EnvMap, key: []u8, value: []u8) !void { |
| 132 | 133 | const get_or_put = try self.hash_map.getOrPut(key); |
| 133 | 134 | if (get_or_put.found_existing) { |
| ... | ... | @@ -139,6 +140,7 @@ pub const EnvMap = struct { |
| 139 | 140 | } |
| 140 | 141 | |
| 141 | 142 | /// `key` and `value` are copied into the EnvMap. |
| 143 | /// On Windows `key` must be a valid UTF-8 string. |
| 142 | 144 | pub fn put(self: *EnvMap, key: []const u8, value: []const u8) !void { |
| 143 | 145 | const value_copy = try self.copy(value); |
| 144 | 146 | errdefer self.free(value_copy); |
| ... | ... | @@ -156,6 +158,7 @@ pub const EnvMap = struct { |
| 156 | 158 | |
| 157 | 159 | /// Find the address of the value associated with a key. |
| 158 | 160 | /// The returned pointer is invalidated if the map resizes. |
| 161 | /// On Windows `key` must be a valid UTF-8 string. |
| 159 | 162 | pub fn getPtr(self: EnvMap, key: []const u8) ?*[]const u8 { |
| 160 | 163 | return self.hash_map.getPtr(key); |
| 161 | 164 | } |
| ... | ... | @@ -163,12 +166,14 @@ pub const EnvMap = struct { |
| 163 | 166 | /// Return the map's copy of the value associated with |
| 164 | 167 | /// a key. The returned string is invalidated if this |
| 165 | 168 | /// key is removed from the map. |
| 169 | /// On Windows `key` must be a valid UTF-8 string. |
| 166 | 170 | pub fn get(self: EnvMap, key: []const u8) ?[]const u8 { |
| 167 | 171 | return self.hash_map.get(key); |
| 168 | 172 | } |
| 169 | 173 | |
| 170 | 174 | /// Removes the item from the map and frees its value. |
| 171 | 175 | /// This invalidates the value returned by get() for this key. |
| 176 | /// On Windows `key` must be a valid UTF-8 string. |
| 172 | 177 | pub fn remove(self: *EnvMap, key: []const u8) void { |
| 173 | 178 | const kv = self.hash_map.fetchRemove(key) orelse return; |
| 174 | 179 | self.free(kv.key); |