Data update

This commit is contained in:
Ingy döt Net 2023-09-16 17:28:03 -07:00
parent 5af6d93694
commit 796d366b97
455 changed files with 7413 additions and 1900 deletions

View file

@ -1,31 +1,38 @@
const std = @import("std");
const debug = std.debug;
const unicode = std.unicode;
test "character codes" {
debug.warn("\n", .{});
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
// Zig's string is just an array of bytes (u8).
const message = "ABCabc";
for (message) |val| {
debug.warn(" '{c}' code: {} [hexa: 0x{x}]\n", .{ val, val, val });
}
try characterAsciiCodes(stdout);
try characterUnicodeCodes(stdout);
}
test "character (uni)codes" {
debug.warn("\n", .{});
fn characterAsciiCodes(writer: anytype) !void {
try writer.writeAll("Sample ASCII characters and codes:\n");
const message = "あいうえお";
// Zig's string is just an array of bytes (u8).
const message: []const u8 = "ABCabc";
for (message) |val| {
try writer.print(" '{c}' code: {d} [hexa: 0x{x}]\n", .{ val, val, val });
}
try writer.writeByte('\n');
}
fn characterUnicodeCodes(writer: anytype) !void {
try writer.writeAll("Sample Unicode characters and codes:\n");
const message: []const u8 = "あいうえお";
const utf8_view = unicode.Utf8View.initUnchecked(message);
var iter = utf8_view.iterator();
while (iter.nextCodepoint()) |val| {
var array: [4]u8 = undefined;
var slice = array[0..try unicode.utf8Encode(val, &array)];
const slice = array[0..try unicode.utf8Encode(val, &array)];
debug.warn(" '{}' code: {} [hexa: U+{x}]\n", .{ slice, val, val });
try writer.print(" '{s}' code: {d} [hexa: U+{x}]\n", .{ slice, val, val });
}
try writer.writeByte('\n');
}