refactor: move all zg LetterCasing usage to Buffer.unicode
This commit is contained in:
parent
57c5066451
commit
2ff0521040
3 changed files with 26 additions and 10 deletions
|
|
@ -90,12 +90,32 @@ pub const LetterCasing = @import("LetterCasing");
|
|||
var letter_casing: ?LetterCasing = null;
|
||||
var letter_casing_arena = std.heap.ArenaAllocator.init(std.heap.c_allocator);
|
||||
|
||||
pub fn get_letter_casing() *LetterCasing {
|
||||
fn get_letter_casing() *LetterCasing {
|
||||
if (letter_casing) |*cd| return cd;
|
||||
letter_casing = LetterCasing.init(letter_casing_arena.allocator()) catch @panic("LetterCasing.init");
|
||||
return &letter_casing.?;
|
||||
}
|
||||
|
||||
pub fn to_upper(allocator: std.mem.Allocator, text: []const u8) error{ OutOfMemory, Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }![]u8 {
|
||||
return get_letter_casing().toUpperStr(allocator, text);
|
||||
}
|
||||
|
||||
pub fn to_lower(allocator: std.mem.Allocator, text: []const u8) error{ OutOfMemory, Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }![]u8 {
|
||||
return get_letter_casing().toLowerStr(allocator, text);
|
||||
}
|
||||
|
||||
pub fn case_fold(allocator: std.mem.Allocator, text: []const u8) error{ OutOfMemory, Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }![]u8 {
|
||||
return get_letter_casing().toLowerStr(allocator, text);
|
||||
}
|
||||
|
||||
pub fn switch_case(allocator: std.mem.Allocator, text: []const u8) error{ OutOfMemory, Utf8CannotEncodeSurrogateHalf, CodepointTooLarge }![]u8 {
|
||||
const letter_casing_ = get_letter_casing();
|
||||
return if (letter_casing_.isLowerStr(text))
|
||||
letter_casing_.toUpperStr(allocator, text)
|
||||
else
|
||||
letter_casing_.toLowerStr(allocator, text);
|
||||
}
|
||||
|
||||
const spinner = [_][]const u8{
|
||||
"⠋",
|
||||
"⠙",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue