1 /**
2     C Universal Identifiers
3     
4     Copyright:
5         Copyright © 2023-2025, Kitsunebi Games
6         Copyright © 2023-2025, Inochi2D Project
7     
8     License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
9     Authors:   Luna Nielsen
10 */
11 module nulib.text.uni;
12 import nulib.text.ascii;
13 
14 @nogc nothrow:
15 
16 /**
17     Gets whether the character is a universal alpha or numeric.
18 
19     Standards: 
20         Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard.
21         Additionally accepts digits.
22 */
23 bool isUniAlphaNumeric(char c) {
24     return 
25         (c >= 'a' && c <= 'z') || 
26         (c >= 'A' && c <= 'Z') || 
27         (c >= '0' && c <= '9') || 
28         c == '_';
29 }
30 
31 /**
32     Gets whether the character is a C universal alpha character.
33     
34     Standards: 
35         Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard.
36 */
37 bool isUniAlpha(char c) {
38     return 
39         (c >= 'a' && c <= 'z') || 
40         (c >= 'A' && c <= 'Z') || 
41         c == '_';
42 }
43 
44 /**
45     Gets whether the given string is a universal C identifier.
46 
47     Standards: 
48         Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard.
49 */
50 bool isUniIdentifier(inout(char)[] iden) {
51     if (iden.length == 0)
52         return false;
53     
54     if (!iden[0].isUniAlpha())
55         return false;
56 
57     foreach(i; 1..iden.length) {
58     
59         if (!iden[i].isUniAlphaNumeric())
60             return false;
61     }
62 
63     return true;
64 }
65 
66 /**
67     Gets whether the given string is integral.
68 */
69 bool isIntegral(inout(char)[] str) {
70     foreach(i; 0..str.length) {
71         if (!isDigit(str[i])) 
72             return false;
73     }
74     return true;
75 }