8#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
9# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
18 module ALib.Strings.Token;
19 import ALib.Characters.Functions;
22 import ALib.Resources;
25 import ALib.EnumRecords;
60 int8_t minLength1, int8_t minLength2, int8_t minLength3, int8_t minLength4,
61 int8_t minLength5, int8_t minLength6, int8_t minLength7 )
63,
minLengths {minLength1, minLength2, minLength3, minLength4, minLength5, minLength6, minLength7} {
80 for(
int i= 0 ; i < 7 ; ++i ) {
104 size_t qtyMinLengths= 0;
114 if( qtyMinLengths >= 7 ) {
139 if( qtyMinLengths == 0 )
142 if( qtyMinLengths > 0 && qtyMinLengths < 7 )
167 while( qtyMinLength < 7 &&
minLengths[qtyMinLength] >= 0 )
172 if( qtyMinLength > 1 ) {
175 int qtyUpperCases= 0;
176 int qtyUnderscores= 0;
180 if( c ==
'_' ) ++qtyUnderscores;
181 else if( c ==
'-' ) ++qtyHyphens;
182 else if( isalpha(c) ) {
193 if( qtyUnderscores > 0 ) {
196 if( (qtyUnderscores >= 7 && qtyMinLength != 7 )
197 || (qtyUnderscores < 7 && qtyMinLength != qtyUnderscores + 1 ) )
203 else if( qtyHyphens > 0 ) {
206 if( (qtyHyphens >= 7 && qtyMinLength != 7 )
207 || (qtyHyphens < 7 && qtyMinLength != qtyHyphens + 1 ) )
213 else if( hasLowerCases && ( qtyUpperCases > 0 ) ) {
216 if( (qtyUpperCases >= 7 && qtyMinLength != 7 )
217 || (qtyUpperCases < 7 && qtyMinLength != qtyUpperCases + 1 ) )
245 int segmentLength= 0;
250 bool segmentEnd= c ==
'\0'
256 if( segmentNo < 7 &&
minLengths[segmentNo] > segmentLength ) {
265 for(
int minLenIdx= 0 ; minLenIdx < 7 && minLengths[minLenIdx] >= 0 ; ++minLenIdx ) {
268 || !( minLenIdx == 6 ||
minLengths[minLenIdx + 1] == -1 ) ) )
280 "Empty search string in when matching function name." )
295 bool isSegOK =
false;
312 if( n ==
'\0' && segMinLen == 0)
317 if( segLen == 1 && rollbackLen > 0) {
331 else if( same && isSegOK )
337 || (isSnake && h ==
'_' )
338 || (isKebab && h ==
'-' )
344 isSegOK= ( ( segMinLen >= 0 && segLen >= segMinLen )
345 || ( segMinLen < 0 && isSegEnd ) );
349 else if( segLen == 1 && segMinLen != 0 )
354 if( isSegEnd && n !=
'\0') {
366 && ( ( isCamel && (!isalpha(h) || !isupper(h) ) )
367 || ( isSnake && h !=
'_' )
368 || ( isKebab && h !=
'-' ) ) )
376 if( !same || isSegEnd ) {
379 segMinLen = segNo < 7 ?
minLengths[segNo] : -2;
382 if( n ==
'\0' && (!isCamel || h ==
'\0' || rollbackLen == 0) )
383 return h ==
'\0' || isNormal || segMinLen == 0;
386 return same && isSegOK && (nIdx == needle.
Length());
constexpr integer Length() const
TChar CharAtStart() const
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
bool ConsumeDecDigits(std::integral auto &result)
TSubstring & Trim(const TCString< TChar > &whiteSpaces=CStringConstantsTraits< TChar >::DefaultWhitespaces())
TString< TChar > ConsumeToken(TChar separator=',', lang::Inclusion includeSeparator=lang::Inclusion::Include)
@ ErrorReadingSensitivity
Sensitivity value not found.
@ TooManyMinLengthsGiven
A maximum of 7 minimum length values was exceeded.
@ EmptyName
No token name found.
@ ZeroMinLengthAndNotLastCamelHump
@ ErrorReadingMinLengths
Error parsing the list of minimum lengths.
@ DefinitionStringNotConsumed
The definition string was not completely consumed.
@ MinLenExceedsSegmentLength
ALIB_DLL void detectFormat()
Detects snake_case, kebab-case or CamelCase.
int8_t GetMinLength(int idx) const
String definitionName
The tokens' definition string part.
const String & GetDefinitionName() const
lang::Case Sensitivity() const
Formats
Format types detected with detectFormat.
@ CamelCase
UpperCamelCase or lowerCamelCase.
@ SnakeCase
snake_case using underscores.
@ Normal
Normal, optionally abbreviated words.
@ KebabCase
kebab-case using hyphens.
Token()
Parameterless constructor. Creates an "undefined" token.
Formats format
Defines the "case type" as well as the letter case sensitivity of this token.
String exportName
The tokens' optional explicit export name.
static constexpr Formats ignoreCase
Letter case sensitivity. This is combined with the format bits.
Formats GetFormat() const
ALIB_DLL void Define(const String &definition, character separator=';')
ALIB_DLL bool Match(const String &needle)
ALIB_DLL void GetExportName(AString &target) const
#define ALIB_ASSERT_ERROR(cond, domain,...)
#define ALIB_REL_DBG(releaseCode,...)
bool Parse(strings::TSubstring< TChar > &input, TEnum &result)
Case
Denotes upper and lower case character treatment.
@ Exclude
Chooses exclusion.
strings::TAString< character, lang::HeapAllocator > AString
Type alias in namespace alib.
lang::integer integer
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
characters::character character
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.