aboutsummaryrefslogtreecommitdiff
path: root/std/cstr.zig
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-01-25 04:10:11 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-01-25 04:10:11 -0500
commit3671582c15235e5f79a84936ea2f834f6968ff8c (patch)
tree7fa2c7f06331feaad43ba63b0969add120633d49 /std/cstr.zig
parente5bc5873d74713bedbc32817ed31370c3256418d (diff)
downloadzig-3671582c15235e5f79a84936ea2f834f6968ff8c.tar.gz
zig-3671582c15235e5f79a84936ea2f834f6968ff8c.zip
syntax: functions require return type. remove `->`
The purpose of this is: * Only one way to do things * Changing a function with void return type to return a possible error becomes a 1 character change, subtly encouraging people to use errors. See #632 Here are some imperfect sed commands for performing this update: remove arrow: ``` sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig") ``` add void: ``` sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig") ``` Some cleanup may be necessary, but this should do the bulk of the work.
Diffstat (limited to 'std/cstr.zig')
-rw-r--r--std/cstr.zig16
1 files changed, 8 insertions, 8 deletions
diff --git a/std/cstr.zig b/std/cstr.zig
index 31fb4ccca7..987c6d3341 100644
--- a/std/cstr.zig
+++ b/std/cstr.zig
@@ -3,13 +3,13 @@ const debug = std.debug;
const mem = std.mem;
const assert = debug.assert;
-pub fn len(ptr: &const u8) -> usize {
+pub fn len(ptr: &const u8) usize {
var count: usize = 0;
while (ptr[count] != 0) : (count += 1) {}
return count;
}
-pub fn cmp(a: &const u8, b: &const u8) -> i8 {
+pub fn cmp(a: &const u8, b: &const u8) i8 {
var index: usize = 0;
while (a[index] == b[index] and a[index] != 0) : (index += 1) {}
if (a[index] > b[index]) {
@@ -21,11 +21,11 @@ pub fn cmp(a: &const u8, b: &const u8) -> i8 {
}
}
-pub fn toSliceConst(str: &const u8) -> []const u8 {
+pub fn toSliceConst(str: &const u8) []const u8 {
return str[0..len(str)];
}
-pub fn toSlice(str: &u8) -> []u8 {
+pub fn toSlice(str: &u8) []u8 {
return str[0..len(str)];
}
@@ -34,7 +34,7 @@ test "cstr fns" {
testCStrFnsImpl();
}
-fn testCStrFnsImpl() {
+fn testCStrFnsImpl() void {
assert(cmp(c"aoeu", c"aoez") == -1);
assert(len(c"123456789") == 9);
}
@@ -42,7 +42,7 @@ fn testCStrFnsImpl() {
/// Returns a mutable slice with exactly the same size which is guaranteed to
/// have a null byte after it.
/// Caller owns the returned memory.
-pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) -> %[]u8 {
+pub fn addNullByte(allocator: &mem.Allocator, slice: []const u8) %[]u8 {
const result = try allocator.alloc(u8, slice.len + 1);
mem.copy(u8, result, slice);
result[slice.len] = 0;
@@ -56,7 +56,7 @@ pub const NullTerminated2DArray = struct {
/// Takes N lists of strings, concatenates the lists together, and adds a null terminator
/// Caller must deinit result
- pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) -> %NullTerminated2DArray {
+ pub fn fromSlices(allocator: &mem.Allocator, slices: []const []const []const u8) %NullTerminated2DArray {
var new_len: usize = 1; // 1 for the list null
var byte_count: usize = 0;
for (slices) |slice| {
@@ -96,7 +96,7 @@ pub const NullTerminated2DArray = struct {
};
}
- pub fn deinit(self: &NullTerminated2DArray) {
+ pub fn deinit(self: &NullTerminated2DArray) void {
const buf = @ptrCast(&u8, self.ptr);
self.allocator.free(buf[0..self.byte_count]);
}