summaryrefslogtreecommitdiff
path: root/src/utils.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.zig')
-rw-r--r--src/utils.zig40
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
3const Allocator = std.mem.Allocator; 3const Allocator = std.mem.Allocator;
4const ArrayList = std.ArrayList; 4const ArrayList = std.ArrayList;
5const CaseData = @import("CaseData"); 5const GeneralCategories = @import("GeneralCategories");
6const GenCatData = @import("GenCatData"); 6const LetterCasing = @import("LetterCasing");
7const Utf8View = std.unicode.Utf8View; 7const Utf8View = std.unicode.Utf8View;
8 8
9pub fn escapeXml(writer: anytype, text: []const u8) !void { 9pub 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
21var gcd_global: ?GenCatData = null; 21var gc_global: ?GeneralCategories = null;
22 22
23pub fn getGCD() !GenCatData { 23pub 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
31var cd_global: ?CaseData = null; 31var lc_global: ?LetterCasing = null;
32 32
33pub fn getCD() !CaseData { 33pub 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
41pub inline fn isNull(value: anytype) bool { 41pub 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
49pub fn isTgWhitespaceStr(str: []const u8) !bool { 49pub 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
63inline fn isTgWhitespace(gcd: GenCatData, cp: u21) bool { 63inline 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}