diff --git a/source/numem/text/ascii.d b/source/numem/text/ascii.d index 11d6564..69bfa8e 100644 --- a/source/numem/text/ascii.d +++ b/source/numem/text/ascii.d @@ -30,9 +30,9 @@ bool isHex(char c) { } /** - Gets whether the character is alphabetic. + Gets whether the character is numeric. */ -bool isNumeric(char c) { +bool isDigit(char c) { return (c >= '0' && c <= '9'); } @@ -46,7 +46,7 @@ bool isAlpha(char c) { } /** - Gets whether the character is alphabetic. + Gets whether the character is alpha-numeric. */ bool isAlphaNumeric(char c) { return diff --git a/source/numem/text/encoding.d b/source/numem/text/encoding.d index 1d56dc6..6b2b92b 100644 --- a/source/numem/text/encoding.d +++ b/source/numem/text/encoding.d @@ -1,3 +1,10 @@ +/* + Copyright © 2024, Inochi2D Project + Distributed under the 2-Clause BSD License, see LICENSE file. + + Authors: Luna the Foxgirl +*/ + module numem.text.encoding; import numem.string; import numem.text.ascii; diff --git a/source/numem/text/uni.d b/source/numem/text/uni.d new file mode 100644 index 0000000..1a9c7bd --- /dev/null +++ b/source/numem/text/uni.d @@ -0,0 +1,64 @@ +/* + Copyright © 2024, Inochi2D Project + Distributed under the 2-Clause BSD License, see LICENSE file. + + Authors: Luna the Foxgirl +*/ + +/** + Numem "Universal" utilities +*/ +module numem.text.uni; +import numem.text.ascii; + +@nogc nothrow: + +/** + Gets whether the character is a universal alpha or numeric. + + Standards: + Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard. + Additionally accepts digits. +*/ +bool isUniAlphaNumeric(char c) { + return + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + (c >= '0' && c <= '9') || + c == '_'; +} + +/** + Gets whether the character is a C universal alpha character. + + Standards: + Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard. +*/ +bool isUniAlpha(char c) { + return + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') || + c == '_'; +} + +/** + Gets whether the given string is a universal C identifier. + + Standards: + Conforms to ISO/IEC 9899:1999(E) Appendix D of the C99 Standard. +*/ +bool isUniIdentifier(inout(char)[] iden) { + if (iden.length == 0) + return false; + + if (!iden[0].isUniAlpha()) + return false; + + foreach(i; 1..iden.length) { + + if (!iden[i].isUniAlphaNumeric()) + return false; + } + + return true; +} \ No newline at end of file