Compare commits
No commits in common. "a81f5c61d09b6faea3683410b5d73c4c431c785a" and "80429f6055222eb286a85e784dff944d52c1dcc5" have entirely different histories.
a81f5c61d0
...
80429f6055
2 changed files with 21 additions and 32 deletions
|
|
@ -30,8 +30,8 @@
|
|||
.hash = "fuzzig-0.1.1-Ji0xivxIAQBD0g8O_NV_0foqoPf3elsg9Sc3pNfdVH4D",
|
||||
},
|
||||
.vaxis = .{
|
||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#4fc5a651a85574c3dfdddebc1d9038fd6bb4e067",
|
||||
.hash = "vaxis-0.5.1-BWNV_EBKCQDqoQZvUE22SBMKYTlZtIIEdLx2X8CfRDHf",
|
||||
.url = "git+https://github.com/neurocyte/libvaxis?ref=main#95034c7114601178467b42e69588cdd4c1d39eb1",
|
||||
.hash = "vaxis-0.5.1-BWNV_PJJCQArtOy_n76jGWoqoBpnM5FKElA_i1IaYYcF",
|
||||
},
|
||||
.zeit = .{
|
||||
.url = "git+https://github.com/rockorager/zeit?ref=zig-0.15#ed2ca60db118414bda2b12df2039e33bad3b0b88",
|
||||
|
|
|
|||
|
|
@ -112,8 +112,8 @@ pub const TransformError = error{
|
|||
WriteFailed,
|
||||
};
|
||||
|
||||
fn utf8_write_transform_T(comptime View: anytype, comptime field: uucode.FieldEnum, writer: *std.Io.Writer, text: []const u8) TransformError!@typeInfo(@TypeOf(View.iterator)).@"fn".return_type.? {
|
||||
const view: View = .initUnchecked(text);
|
||||
fn utf8_write_transform(comptime field: uucode.FieldEnum, writer: *std.Io.Writer, text: []const u8) TransformError!void {
|
||||
const view: Utf8View = .initUnchecked(text);
|
||||
var it = view.iterator();
|
||||
while (it.nextCodepoint()) |cp| {
|
||||
const cp_ = switch (field) {
|
||||
|
|
@ -125,15 +125,21 @@ fn utf8_write_transform_T(comptime View: anytype, comptime field: uucode.FieldEn
|
|||
const size = try utf8Encode(cp_, &utf8_buf);
|
||||
try writer.writeAll(utf8_buf[0..size]);
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
fn utf8_write_transform(comptime field: uucode.FieldEnum, writer: *std.Io.Writer, text: []const u8) TransformError!void {
|
||||
_ = try utf8_write_transform_T(Utf8View, field, writer, text);
|
||||
}
|
||||
|
||||
fn utf8_partial_write_transform(comptime field: uucode.FieldEnum, writer: *std.Io.Writer, text: []const u8) TransformError![]const u8 {
|
||||
const it = try utf8_write_transform_T(Utf8PartialView, field, writer, text);
|
||||
const view: Utf8PartialView = .initUnchecked(text);
|
||||
var it = view.iterator();
|
||||
while (it.nextCodepoint()) |cp| {
|
||||
const cp_ = switch (field) {
|
||||
.simple_uppercase_mapping, .simple_lowercase_mapping => uucode.get(field, cp) orelse cp,
|
||||
.case_folding_simple => uucode.get(field, cp),
|
||||
else => @compileError(@tagName(field) ++ " is not a unicode transformation"),
|
||||
};
|
||||
var utf8_buf: [6]u8 = undefined;
|
||||
const size = try utf8Encode(cp_, &utf8_buf);
|
||||
try writer.writeAll(utf8_buf[0..size]);
|
||||
}
|
||||
return text[0..it.end];
|
||||
}
|
||||
|
||||
|
|
@ -144,14 +150,12 @@ fn utf8_transform(comptime field: uucode.FieldEnum, allocator: std.mem.Allocator
|
|||
return result.toOwnedSlice();
|
||||
}
|
||||
|
||||
fn utf8_predicate_all(comptime field: uucode.FieldEnum, text: []const u8) bool {
|
||||
fn utf8_predicate(comptime field: uucode.FieldEnum, text: []const u8) bool {
|
||||
const view: Utf8View = .initUnchecked(text);
|
||||
var it = view.iterator();
|
||||
while (it.nextCodepoint()) |cp| {
|
||||
const result = switch (field) {
|
||||
.is_lowercase => uucode.get(field, cp),
|
||||
.changes_when_casefolded => uucode.get(field, cp),
|
||||
.changes_when_lowercased => uucode.get(field, cp),
|
||||
else => @compileError(@tagName(field) ++ " is not a unicode predicate"),
|
||||
};
|
||||
if (!result) return false;
|
||||
|
|
@ -159,21 +163,6 @@ fn utf8_predicate_all(comptime field: uucode.FieldEnum, text: []const u8) bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
fn utf8_predicate_any(comptime field: uucode.FieldEnum, text: []const u8) bool {
|
||||
const view: Utf8View = .initUnchecked(text);
|
||||
var it = view.iterator();
|
||||
while (it.nextCodepoint()) |cp| {
|
||||
const result = switch (field) {
|
||||
.is_lowercase => uucode.get(field, cp),
|
||||
.changes_when_casefolded => uucode.get(field, cp),
|
||||
.changes_when_lowercased => uucode.get(field, cp),
|
||||
else => @compileError(@tagName(field) ++ " is not a unicode predicate"),
|
||||
};
|
||||
if (result) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn to_upper(allocator: std.mem.Allocator, text: []const u8) TransformError![]u8 {
|
||||
return utf8_transform(.simple_uppercase_mapping, allocator, text);
|
||||
}
|
||||
|
|
@ -195,14 +184,14 @@ pub fn case_folded_write_partial(writer: *std.Io.Writer, text: []const u8) Trans
|
|||
}
|
||||
|
||||
pub fn switch_case(allocator: std.mem.Allocator, text: []const u8) TransformError![]u8 {
|
||||
return if (utf8_predicate_any(.changes_when_lowercased, text))
|
||||
to_lower(allocator, text)
|
||||
return if (utf8_predicate(.is_lowercase, text))
|
||||
to_upper(allocator, text)
|
||||
else
|
||||
to_upper(allocator, text);
|
||||
to_lower(allocator, text);
|
||||
}
|
||||
|
||||
pub fn is_lowercase(text: []const u8) bool {
|
||||
return utf8_predicate_all(.is_lowercase, text);
|
||||
return utf8_predicate(.is_lowercase, text);
|
||||
}
|
||||
|
||||
const std = @import("std");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue