diff options
Diffstat (limited to 'src/utils.zig')
| -rw-r--r-- | src/utils.zig | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/utils.zig b/src/utils.zig index b739f6f..b5d9f19 100644 --- a/src/utils.zig +++ b/src/utils.zig | |||
| @@ -2,8 +2,8 @@ const std = @import("std"); | |||
| 2 | 2 | ||
| 3 | const Allocator = std.mem.Allocator; | 3 | const Allocator = std.mem.Allocator; |
| 4 | const ArrayList = std.ArrayList; | 4 | const ArrayList = std.ArrayList; |
| 5 | const CaseData = @import("CaseData"); | 5 | const GeneralCategories = @import("GeneralCategories"); |
| 6 | const GenCatData = @import("GenCatData"); | 6 | const LetterCasing = @import("LetterCasing"); |
| 7 | const Utf8View = std.unicode.Utf8View; | 7 | const Utf8View = std.unicode.Utf8View; |
| 8 | 8 | ||
| 9 | pub fn escapeXml(writer: anytype, text: []const u8) !void { | 9 | pub fn escapeXml(writer: anytype, text: []const u8) !void { |
| @@ -18,41 +18,41 @@ pub fn escapeXml(writer: anytype, text: []const u8) !void { | |||
| 18 | } | 18 | } |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | var gcd_global: ?GenCatData = null; | 21 | var gc_global: ?GeneralCategories = null; |
| 22 | 22 | ||
| 23 | pub fn getGCD() !GenCatData { | 23 | pub fn getGC() !GeneralCategories { |
| 24 | if (gcd_global) |gcd| { | 24 | if (gc_global) |gc| { |
| 25 | return gcd; | 25 | return gc; |
| 26 | } | 26 | } |
| 27 | gcd_global = try GenCatData.init(std.heap.page_allocator); | 27 | gc_global = try GeneralCategories.init(std.heap.page_allocator); |
| 28 | return gcd_global.?; | 28 | return gc_global.?; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | var cd_global: ?CaseData = null; | 31 | var lc_global: ?LetterCasing = null; |
| 32 | 32 | ||
| 33 | pub fn getCD() !CaseData { | 33 | pub fn getLetterCasing() !LetterCasing { |
| 34 | if (cd_global) |cd| { | 34 | if (lc_global) |lc| { |
| 35 | return cd; | 35 | return lc; |
| 36 | } | 36 | } |
| 37 | cd_global = try CaseData.init(std.heap.page_allocator); | 37 | lc_global = try LetterCasing.init(std.heap.page_allocator); |
| 38 | return cd_global.?; | 38 | return lc_global.?; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | pub inline fn isNull(value: anytype) bool { | 41 | pub inline fn isNull(value: anytype) bool { |
| 42 | return switch (@typeInfo(@TypeOf(value))) { | 42 | return switch (@typeInfo(@TypeOf(value))) { |
| 43 | .Null => true, | 43 | .null => true, |
| 44 | .Optional => value == null, | 44 | .optional => value == null, |
| 45 | else => false, | 45 | else => false, |
| 46 | }; | 46 | }; |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | pub fn isTgWhitespaceStr(str: []const u8) !bool { | 49 | pub fn isTgWhitespaceStr(str: []const u8) !bool { |
| 50 | const view = try Utf8View.init(str); | 50 | const view = try Utf8View.init(str); |
| 51 | const gcd = try getGCD(); | 51 | const gc = try getGC(); |
| 52 | 52 | ||
| 53 | var it = view.iterator(); | 53 | var it = view.iterator(); |
| 54 | while (it.nextCodepoint()) |cp| { | 54 | while (it.nextCodepoint()) |cp| { |
| 55 | if (!isTgWhitespace(gcd, cp)) { | 55 | if (!isTgWhitespace(gc, cp)) { |
| 56 | return false; | 56 | return false; |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| @@ -60,7 +60,7 @@ pub fn isTgWhitespaceStr(str: []const u8) !bool { | |||
| 60 | return true; | 60 | return true; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | inline fn isTgWhitespace(gcd: GenCatData, cp: u21) bool { | 63 | inline fn isTgWhitespace(gc: GeneralCategories, cp: u21) bool { |
| 64 | return gcd.isSeparator(cp) or gcd.isControl(cp) or cp == 0x2800 // BRAILLE PATTERN BLANK, telegram treats messages with just this as invalid messages | 64 | return gc.isSeparator(cp) or gc.isControl(cp) or cp == 0x2800 // BRAILLE PATTERN BLANK, telegram treats messages with just this as invalid messages |
| 65 | ; | 65 | ; |
| 66 | } | 66 | } |