mirror of
https://github.com/ziglang/zig.git
synced 2024-11-30 09:02:32 +00:00
e3424332d3
* `doc/langref` formatting * upgrade `.{ .path = "..." }` to `b.path("...")` * avoid using arguments named `self` * make `Build.Step.Id` usage more consistent * add `Build.pathResolve` * use `pathJoin` and `pathResolve` everywhere * make sure `Build.LazyPath.getPath2` returns an absolute path
22 lines
924 B
Zig
22 lines
924 B
Zig
const print = @import("std").debug.print;
|
|
const mem = @import("std").mem; // will be used to compare bytes
|
|
|
|
pub fn main() void {
|
|
const bytes = "hello";
|
|
print("{}\n", .{@TypeOf(bytes)}); // *const [5:0]u8
|
|
print("{d}\n", .{bytes.len}); // 5
|
|
print("{c}\n", .{bytes[1]}); // 'e'
|
|
print("{d}\n", .{bytes[5]}); // 0
|
|
print("{}\n", .{'e' == '\x65'}); // true
|
|
print("{d}\n", .{'\u{1f4a9}'}); // 128169
|
|
print("{d}\n", .{'💯'}); // 128175
|
|
print("{u}\n", .{'⚡'});
|
|
print("{}\n", .{mem.eql(u8, "hello", "h\x65llo")}); // true
|
|
print("{}\n", .{mem.eql(u8, "💯", "\xf0\x9f\x92\xaf")}); // also true
|
|
const invalid_utf8 = "\xff\xfe"; // non-UTF-8 strings are possible with \xNN notation.
|
|
print("0x{x}\n", .{invalid_utf8[1]}); // indexing them returns individual bytes...
|
|
print("0x{x}\n", .{"💯"[1]}); // ...as does indexing part-way through non-ASCII characters
|
|
}
|
|
|
|
// exe=succeed
|