aboutsummaryrefslogtreecommitdiff
path: root/lib/std/leb128.zig
diff options
context:
space:
mode:
authorMichael Bradshaw <github@mjb.io>2024-06-10 07:43:22 -0600
committerMatthew Lugg <mlugg@mlugg.co.uk>2024-06-23 04:30:12 +0100
commit642093e04bf10f6a9a7c23dfcf219bbbc7d51b54 (patch)
treea3945fb11a5a6f71834b9aae2d163dd67f14fa46 /lib/std/leb128.zig
parent0fcd59eadae468284943895f50bc9fc6d1924154 (diff)
downloadzig-642093e04bf10f6a9a7c23dfcf219bbbc7d51b54.tar.gz
zig-642093e04bf10f6a9a7c23dfcf219bbbc7d51b54.zip
Rename *[UI]LEB128 functions to *[UI]leb128
Diffstat (limited to 'lib/std/leb128.zig')
-rw-r--r--lib/std/leb128.zig36
1 files changed, 24 insertions, 12 deletions
diff --git a/lib/std/leb128.zig b/lib/std/leb128.zig
index f649dd6519..087df559fe 100644
--- a/lib/std/leb128.zig
+++ b/lib/std/leb128.zig
@@ -3,7 +3,7 @@ const testing = std.testing;
/// Read a single unsigned LEB128 value from the given reader as type T,
/// or error.Overflow if the value cannot fit.
-pub fn readULEB128(comptime T: type, reader: anytype) !T {
+pub fn readUleb128(comptime T: type, reader: anytype) !T {
const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
const ShiftT = std.math.Log2Int(U);
@@ -32,8 +32,11 @@ pub fn readULEB128(comptime T: type, reader: anytype) !T {
return @as(T, @truncate(value));
}
+/// Deprecated: use `readUleb128`
+pub const readULEB128 = readUleb128;
+
/// Write a single unsigned integer as unsigned LEB128 to the given writer.
-pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
+pub fn writeUleb128(writer: anytype, uint_value: anytype) !void {
const T = @TypeOf(uint_value);
const U = if (@typeInfo(T).Int.bits < 8) u8 else T;
var value: U = @intCast(uint_value);
@@ -50,9 +53,12 @@ pub fn writeULEB128(writer: anytype, uint_value: anytype) !void {
}
}
+/// Deprecated: use `writeUleb128`
+pub const writeULEB128 = writeUleb128;
+
/// Read a single signed LEB128 value from the given reader as type T,
/// or error.Overflow if the value cannot fit.
-pub fn readILEB128(comptime T: type, reader: anytype) !T {
+pub fn readIleb128(comptime T: type, reader: anytype) !T {
const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
const ShiftU = std.math.Log2Int(U);
@@ -108,8 +114,11 @@ pub fn readILEB128(comptime T: type, reader: anytype) !T {
return @as(T, @truncate(result));
}
+/// Deprecated: use `readIleb128`
+pub const readILEB128 = readIleb128;
+
/// Write a single signed integer as signed LEB128 to the given writer.
-pub fn writeILEB128(writer: anytype, int_value: anytype) !void {
+pub fn writeIleb128(writer: anytype, int_value: anytype) !void {
const T = @TypeOf(int_value);
const S = if (@typeInfo(T).Int.bits < 8) i8 else T;
const U = std.meta.Int(.unsigned, @typeInfo(S).Int.bits);
@@ -151,6 +160,9 @@ pub fn writeUnsignedFixed(comptime l: usize, ptr: *[l]u8, int: std.meta.Int(.uns
ptr[i] = @truncate(value);
}
+/// Deprecated: use `writeIleb128`
+pub const writeILEB128 = writeIleb128;
+
test writeUnsignedFixed {
{
var buf: [4]u8 = undefined;
@@ -236,23 +248,23 @@ test writeSignedFixed {
// tests
fn test_read_stream_ileb128(comptime T: type, encoded: []const u8) !T {
var reader = std.io.fixedBufferStream(encoded);
- return try readILEB128(T, reader.reader());
+ return try readIleb128(T, reader.reader());
}
fn test_read_stream_uleb128(comptime T: type, encoded: []const u8) !T {
var reader = std.io.fixedBufferStream(encoded);
- return try readULEB128(T, reader.reader());
+ return try readUleb128(T, reader.reader());
}
fn test_read_ileb128(comptime T: type, encoded: []const u8) !T {
var reader = std.io.fixedBufferStream(encoded);
- const v1 = try readILEB128(T, reader.reader());
+ const v1 = try readIleb128(T, reader.reader());
return v1;
}
fn test_read_uleb128(comptime T: type, encoded: []const u8) !T {
var reader = std.io.fixedBufferStream(encoded);
- const v1 = try readULEB128(T, reader.reader());
+ const v1 = try readUleb128(T, reader.reader());
return v1;
}
@@ -260,7 +272,7 @@ fn test_read_ileb128_seq(comptime T: type, comptime N: usize, encoded: []const u
var reader = std.io.fixedBufferStream(encoded);
var i: usize = 0;
while (i < N) : (i += 1) {
- _ = try readILEB128(T, reader.reader());
+ _ = try readIleb128(T, reader.reader());
}
}
@@ -268,7 +280,7 @@ fn test_read_uleb128_seq(comptime T: type, comptime N: usize, encoded: []const u
var reader = std.io.fixedBufferStream(encoded);
var i: usize = 0;
while (i < N) : (i += 1) {
- _ = try readULEB128(T, reader.reader());
+ _ = try readUleb128(T, reader.reader());
}
}
@@ -364,8 +376,8 @@ fn test_write_leb128(value: anytype) !void {
const signedness = @typeInfo(T).Int.signedness;
const t_signed = signedness == .signed;
- const writeStream = if (t_signed) writeILEB128 else writeULEB128;
- const readStream = if (t_signed) readILEB128 else readULEB128;
+ const writeStream = if (t_signed) writeIleb128 else writeUleb128;
+ const readStream = if (t_signed) readIleb128 else readUleb128;
// decode to a larger bit size too, to ensure sign extension
// is working as expected