Skip to content

Commit ec325a3

Browse files
committed
update usage of some deprecated standard library functions
1 parent 98d6bed commit ec325a3

5 files changed

Lines changed: 10 additions & 10 deletions

File tree

examples/hello_server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn main(init: std.process.Init) !void {
113113
try transport.writeResponse(io, gpa, request.id, void, {}, .{});
114114
continue;
115115
};
116-
const source_z = try gpa.dupeZ(u8, source);
116+
const source_z = try gpa.dupeSentinel(u8, source, 0);
117117
defer gpa.free(source_z);
118118

119119
var tree: std.zig.Ast = try .parse(gpa, source_z, .zig);

examples/my_first_server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub const Handler = struct {
3838
fn init(allocator: std.mem.Allocator) Handler {
3939
return .{
4040
.allocator = allocator,
41-
.files = .{},
41+
.files = .empty,
4242
// The default position encoding is UTF-16.
4343
// The agreed upon encoding between server client is actually decided during `initialize`.
4444
.offset_encoding = .@"utf-16",

src/codegen/codegen.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn main(init: std.process.Init.Minimal) !u8 {
2929
var zig_tree: std.zig.Ast = try .parse(gpa, source, .zig);
3030
defer zig_tree.deinit(gpa);
3131

32-
std.Io.Dir.cwd().createDirPath(io, std.fs.path.dirname(out_file_path) orelse ".") catch {};
32+
std.Io.Dir.cwd().createDirPath(io, std.Io.Dir.path.dirname(out_file_path) orelse ".") catch {};
3333

3434
var out_file = try std.Io.Dir.cwd().createFile(io, out_file_path, .{});
3535
defer out_file.close(io);
@@ -750,7 +750,7 @@ const SymbolNamespaceIterator = struct {
750750
switch (it.direction) {
751751
.forward => {
752752
if (it.index == it.name.len) return null;
753-
const new_index = std.mem.indexOfScalarPos(u8, it.name, it.index, '.') orelse {
753+
const new_index = std.mem.findScalarPos(u8, it.name, it.index, '.') orelse {
754754
defer it.index = it.name.len;
755755
return it.name[it.index..];
756756
};
@@ -760,7 +760,7 @@ const SymbolNamespaceIterator = struct {
760760
.reverse => {
761761
if (it.index == 0) return null;
762762
const name = it.name[0..it.index];
763-
const new_index = std.mem.lastIndexOfScalar(u8, name, '.') orelse {
763+
const new_index = std.mem.findScalarLast(u8, name, '.') orelse {
764764
it.index = 0;
765765
return name;
766766
};

src/lsp.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ pub const BaseProtocolHeader = struct {
982982

983983
if (header.len == 0) break;
984984

985-
const colon_index = std.mem.indexOf(u8, header, ": ") orelse return error.InvalidHeaderField;
985+
const colon_index = std.mem.find(u8, header, ": ") orelse return error.InvalidHeaderField;
986986

987987
const header_name = header[0..colon_index];
988988
const header_value = header[colon_index + 2 ..];

src/offsets.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub const Position = types.Position;
3232
pub const Range = types.Range;
3333

3434
pub fn indexToPosition(text: []const u8, index: usize, encoding: Encoding) Position {
35-
const last_line_start = if (std.mem.lastIndexOfScalar(u8, text[0..index], '\n')) |line| line + 1 else 0;
35+
const last_line_start = if (std.mem.findScalarLast(u8, text[0..index], '\n')) |line| line + 1 else 0;
3636
const line_count = std.mem.count(u8, text[0..last_line_start], "\n");
3737

3838
return .{
@@ -248,8 +248,8 @@ test rangeToSlice {
248248

249249
pub fn lineLocAtIndex(text: []const u8, index: usize) Loc {
250250
return .{
251-
.start = if (std.mem.lastIndexOfScalar(u8, text[0..index], '\n')) |idx| idx + 1 else 0,
252-
.end = std.mem.indexOfScalarPos(u8, text, index, '\n') orelse text.len,
251+
.start = if (std.mem.findScalarLast(u8, text[0..index], '\n')) |idx| idx + 1 else 0,
252+
.end = std.mem.findScalarPos(u8, text, index, '\n') orelse text.len,
253253
};
254254
}
255255

@@ -296,7 +296,7 @@ test lineSliceAtPosition {
296296

297297
pub fn lineLocUntilIndex(text: []const u8, index: usize) Loc {
298298
return .{
299-
.start = if (std.mem.lastIndexOfScalar(u8, text[0..index], '\n')) |idx| idx + 1 else 0,
299+
.start = if (std.mem.findScalarLast(u8, text[0..index], '\n')) |idx| idx + 1 else 0,
300300
.end = index,
301301
};
302302
}

0 commit comments

Comments
 (0)