@@ -38,7 +38,7 @@ pub const FileType = enum {
3838
3939 pub fn isTomlFile (self : FileType ) bool {
4040 return self == .cargo_toml or self == .pyproject_toml or
41- self == .ion_toml or self == .generic_toml ;
41+ self == .ion_toml or self == .generic_toml ;
4242 }
4343};
4444
@@ -130,17 +130,17 @@ fn updateVersionInJson(allocator: Allocator, content: []const u8, old_version: [
130130 try obj .put ("version" , .{ .string = version_str });
131131
132132 // Serialize back to JSON with pretty printing
133- var output : std .ArrayList (u8 ) = .empty ;
134- defer output .deinit (allocator );
133+ var output = std .ArrayList (u8 ). init ( allocator ) ;
134+ defer output .deinit ();
135135
136136 try std .json .stringify (root , .{
137137 .whitespace = .indent_2 ,
138- }, output .writer (allocator ));
138+ }, output .writer ());
139139
140140 // Add newline at end
141- try output .append (allocator , '\n ' );
141+ try output .append ('\n ' );
142142
143- return try output .toOwnedSlice (allocator );
143+ return try output .toOwnedSlice ();
144144}
145145
146146fn findVersionInToml (allocator : Allocator , content : []const u8 ) ! ? []u8 {
@@ -174,8 +174,8 @@ fn findVersionInToml(allocator: Allocator, content: []const u8) !?[]u8 {
174174fn updateVersionInToml (allocator : Allocator , content : []const u8 , old_version : []const u8 , new_version : []const u8 ) ! []u8 {
175175 _ = old_version ;
176176
177- var output : std .ArrayList (u8 ) = .empty ;
178- defer output .deinit (allocator );
177+ var output = std .ArrayList (u8 ). init ( allocator ) ;
178+ defer output .deinit ();
179179
180180 var lines = std .mem .splitScalar (u8 , content , '\n ' );
181181 var line_index : usize = 0 ;
@@ -186,38 +186,36 @@ fn updateVersionInToml(allocator: Allocator, content: []const u8, old_version: [
186186 if (std .mem .startsWith (u8 , trimmed , "version" )) {
187187 // Check if this is a version field assignment
188188 const eq_index = std .mem .indexOfScalar (u8 , trimmed , '=' ) orelse {
189- try output .appendSlice (allocator , line );
190- if (lines .rest ().len > 0 ) try output .append (allocator , '\n ' );
189+ try output .appendSlice (line );
190+ if (lines .rest ().len > 0 ) try output .append ('\n ' );
191191 continue ;
192192 };
193193
194194 const value_part = std .mem .trim (u8 , trimmed [eq_index + 1 .. ], & std .ascii .whitespace );
195195 if (value_part .len >= 2 and (value_part [0 ] == '"' or value_part [0 ] == '\' ' )) {
196196 // This is a version field, replace it
197197 const leading_space = std .mem .indexOfScalar (u8 , line , 'v' ) orelse 0 ;
198- try output .appendSlice (allocator , line [0.. leading_space ]);
199- const replacement = try std .fmt .allocPrint (allocator , "version = \" {s}\" " , .{new_version });
200- defer allocator .free (replacement );
201- try output .appendSlice (allocator , replacement );
198+ try output .appendSlice (line [0.. leading_space ]);
199+ try output .writer ().print ("version = \" {s}\" " , .{new_version });
202200 } else {
203- try output .appendSlice (allocator , line );
201+ try output .appendSlice (line );
204202 }
205203 } else {
206- try output .appendSlice (allocator , line );
204+ try output .appendSlice (line );
207205 }
208206
209- if (lines .rest ().len > 0 ) try output .append (allocator , '\n ' );
207+ if (lines .rest ().len > 0 ) try output .append ('\n ' );
210208 }
211209
212- return try output .toOwnedSlice (allocator );
210+ return try output .toOwnedSlice ();
213211}
214212
215213fn findVersionInText (allocator : Allocator , content : []const u8 ) ! ? []u8 {
216214 // Look for semantic version patterns in text
217215 // Pattern: \bX.Y.Z\b (word boundaries)
218216 const semver_pattern = std .mem .indexOf (u8 , content , "0." ) orelse
219- std .mem .indexOf (u8 , content , "1." ) orelse
220- return null ;
217+ std .mem .indexOf (u8 , content , "1." ) orelse
218+ return null ;
221219
222220 // Extract the version starting from this position
223221 var end = semver_pattern ;
@@ -240,8 +238,8 @@ fn findVersionInText(allocator: Allocator, content: []const u8) !?[]u8 {
240238
241239fn updateVersionInText (allocator : Allocator , content : []const u8 , old_version : []const u8 , new_version : []const u8 ) ! []u8 {
242240 // Simple find and replace with word boundary consideration
243- var output : std .ArrayList (u8 ) = .empty ;
244- defer output .deinit (allocator );
241+ var output = std .ArrayList (u8 ). init ( allocator ) ;
242+ defer output .deinit ();
245243
246244 var pos : usize = 0 ;
247245 while (pos < content .len ) {
@@ -258,20 +256,20 @@ fn updateVersionInText(allocator: Allocator, content: []const u8, old_version: [
258256
259257 // Only replace if we have word boundaries on both sides
260258 if (has_boundary_before and has_boundary_after ) {
261- try output .appendSlice (allocator , content [pos .. abs_index ]);
262- try output .appendSlice (allocator , new_version );
259+ try output .appendSlice (content [pos .. abs_index ]);
260+ try output .appendSlice (new_version );
263261 pos = end_index ;
264262 } else {
265- try output .appendSlice (allocator , content [pos .. abs_index + 1 ]);
263+ try output .appendSlice (content [pos .. abs_index + 1 ]);
266264 pos = abs_index + 1 ;
267265 }
268266 } else {
269- try output .appendSlice (allocator , remaining );
267+ try output .appendSlice (remaining );
270268 break ;
271269 }
272270 }
273271
274- return try output .toOwnedSlice (allocator );
272+ return try output .toOwnedSlice ();
275273}
276274
277275fn isVersionChar (c : u8 ) bool {
@@ -281,12 +279,12 @@ fn isVersionChar(c: u8) bool {
281279pub fn findFiles (allocator : Allocator , dir_path : []const u8 , recursive : bool , pattern : ? []const u8 ) ! [][]u8 {
282280 _ = pattern ;
283281
284- var files : std .ArrayList ([]u8 ) = .empty ;
282+ var files = std .ArrayList ([]u8 ). init ( allocator ) ;
285283 errdefer {
286284 for (files .items ) | file | {
287285 allocator .free (file );
288286 }
289- files .deinit (allocator );
287+ files .deinit ();
290288 }
291289
292290 if (recursive ) {
@@ -297,13 +295,13 @@ pub fn findFiles(allocator: Allocator, dir_path: []const u8, recursive: bool, pa
297295 defer allocator .free (package_json_path );
298296
299297 std .fs .cwd ().access (package_json_path , .{}) catch {
300- return files .toOwnedSlice (allocator );
298+ return files .toOwnedSlice ();
301299 };
302300
303- try files .append (allocator , try allocator .dupe (u8 , package_json_path ));
301+ try files .append (try allocator .dupe (u8 , package_json_path ));
304302 }
305303
306- return try files .toOwnedSlice (allocator );
304+ return try files .toOwnedSlice ();
307305}
308306
309307fn findFilesRecursive (allocator : Allocator , files : * std .ArrayList ([]u8 ), dir_path : []const u8 ) ! void {
@@ -334,7 +332,7 @@ fn findFilesRecursive(allocator: Allocator, files: *std.ArrayList([]u8), dir_pat
334332 .file = > {
335333 const file_type = FileType .fromPath (entry .name );
336334 if (file_type == .package_json or file_type .isTomlFile ()) {
337- try files .append (allocator , try allocator .dupe (u8 , full_path ));
335+ try files .append (try allocator .dupe (u8 , full_path ));
338336 }
339337 },
340338 else = > {},
0 commit comments