提问人:Simon Berens 提问时间:10/22/2023 最后编辑:FObersteinerSimon Berens 更新时间:10/26/2023 访问量:70
zig 中的大写 ascii 字符
Uppercase ascii character in zig
答:
2赞
Simon Berens
10/22/2023
#1
通常,标准库提供以下功能:
以及小写字母的相应函数:
以下是一些用法示例:
const std = @import("std")
const expect = std.testing.expect;
const upper_a: u8 = 'A';
const lower_a: u8 = 'a';
const mixed_str: []const u8 = "AbCd";
var out_str = [_]u8{'0', '0', '0', '0'};
try expect(std.ascii.isUpper(upper_a));
try expect(std.ascii.toUpper(lower_a) == upper_a);
try expect(std.mem.eql(u8, std.ascii.upperString(&out_str, mixed_str), "ABCD"));
try expect(std.mem.eql(u8, &out_str, "ABCD")); // upperString writes to out_str
try expect(std.ascii.isLower(lower_a));
try expect(std.ascii.toLower(upper_a) == lower_a);
try expect(std.mem.eql(u8, std.ascii.lowerString(&out_str, mixed_str), "abcd"));
try expect(std.mem.eql(u8, &out_str, "abcd")); // lowerString writes to out_str
评论