-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: support zig master * update README
- Loading branch information
1 parent
53562ec
commit 7c6cb83
Showing
12 changed files
with
83 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
zig 0.11.0 | ||
# zig master | ||
# zig 0.11.0 | ||
zig master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# String Parsing | ||
|
||
## String to number/enum | ||
|
||
```zig | ||
{{#include ../src/15-02.zig }} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const std = @import("std"); | ||
const expectEqual = std.testing.expectEqual; | ||
const expectError = std.testing.expectError; | ||
const parseInt = std.fmt.parseInt; | ||
const parseFloat = std.fmt.parseFloat; | ||
const stringToEnum = std.meta.stringToEnum; | ||
|
||
pub fn main() !void { | ||
try expectEqual(parseInt(i32, "123", 10), 123); | ||
try expectEqual(parseInt(i32, "-123", 10), -123); | ||
try expectError(error.Overflow, parseInt(u4, "123", 10)); | ||
|
||
// 0 means auto detect the base. | ||
// base = 16 | ||
try expectEqual(parseInt(i32, "0xF", 0), 15); | ||
// base = 2 | ||
try expectEqual(parseInt(i32, "0b1111", 0), 15); | ||
// base = 8 | ||
try expectEqual(parseInt(i32, "0o17", 0), 15); | ||
|
||
try expectEqual(parseFloat(f32, "1.23"), 1.23); | ||
try expectEqual(parseFloat(f32, "-1.23"), -1.23); | ||
|
||
const Color = enum { | ||
Red, | ||
Blue, | ||
Green, | ||
}; | ||
try expectEqual(stringToEnum(Color, "Red").?, Color.Red); | ||
try expectEqual(stringToEnum(Color, "Yello"), null); | ||
} |