Skip to content

Commit

Permalink
numem.text cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
LunaTheFoxgirl committed Dec 21, 2024
1 parent c22d8f1 commit 141533d
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/numem/text/ascii.d
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions source/numem/text/encoding.d
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
64 changes: 64 additions & 0 deletions source/numem/text/uni.d
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 141533d

Please sign in to comment.