-
Notifications
You must be signed in to change notification settings - Fork 1
/
dunicode.pas
70 lines (59 loc) · 1.43 KB
/
dunicode.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// RFC 5198 https://tools.ietf.org/html/rfc5198
{$MODE FPC}
{$MODESWITCH OUT}
{$MODESWITCH RESULT}
unit dunicode;
interface
const
// Highest possible code point
HIGH_UNICODE_CODE_POINT = $0010FFFF;
// Some constants for unicode characters
U_BOM = $FEFF;
U_CR = $0D;
U_LF = $0A;
U_NEL = $85;
U_LINE_SEPARATOR = $2028;
U_PARAGRAPH_SEPARATOR = $2029;
//
// IsUnicodeNewLineFunction
//
// Checks if specified Unicode character is NLF.
//
// It returns True if U is one of:
// U+000D CR - CARRIAGE RETURN
// U+000A LF - LINE FEED
// U+0085 NEL - NEXT LINE
// U+2028 LS - LINE SEPARATOR
// U+2029 PS - PARAGRAPH SEPARATOR
//
function IsUnicodeNewLineFunction(U: Cardinal): Boolean; inline;
//
// GetUnicodePlane
//
// Returns plane of specified Unicode character
//
function GetUnicodePlane(U: Cardinal): Cardinal; inline;
//
// IsUnicodeBMP
//
// Checks if U is in Unicode BMP
//
function IsUnicodeBMP(U: Cardinal): Boolean; inline;
implementation
function IsUnicodeNewLineFunction(U: Cardinal): Boolean;
begin
if U < 128 then begin
Exit(U in [10, 13, $85]);
end else begin
Exit((U = $2028) or (U = $2029));
end;
end;
function GetUnicodePlane(U: Cardinal): Cardinal;
begin
Result := U shr 16;
end;
function IsUnicodeBMP(U: Cardinal): Boolean;
begin
Result := (U shr 16) = 0;
end;
end.