27namespace alib {
namespace strings {
namespace util {
30: definitionName (pName)
31, exportName (pExportName)
33 + int8_t(sensitivity == lang::Case::Sensitive ?
Formats(0) : ignoreCase) ) )
47 int8_t minLength1, int8_t minLength2, int8_t minLength3, int8_t minLength4, int8_t minLength5,
48 int8_t minLength6, int8_t minLength7 )
49: definitionName(definitionSrc)
50, minLengths { minLength1, minLength2, minLength3, minLength4, minLength5, minLength6, minLength7 }
71 for(
int i= 0 ; i < 7 ; ++i )
102 size_t qtyMinLengths= 0;
115 if( qtyMinLengths >= 7 )
148 if( qtyMinLengths == 0 )
151 if( qtyMinLengths > 0 && qtyMinLengths < 7 )
180 while( qtyMinLength < 7 &&
minLengths[qtyMinLength] >= 0 )
186 if( qtyMinLength > 1 )
190 int qtyUpperCases= 0;
191 int qtyUnderscores= 0;
196 if( c ==
'_' ) ++qtyUnderscores;
197 else if( c ==
'-' ) ++qtyHyphens;
198 else if( isalpha(c) )
210 if( qtyUnderscores > 0 )
214 if( (qtyUnderscores >= 7 && qtyMinLength != 7 )
215 || (qtyUnderscores < 7 && qtyMinLength != qtyUnderscores + 1 ) )
221 else if( qtyHyphens > 0 )
225 if( (qtyHyphens >= 7 && qtyMinLength != 7 )
226 || (qtyHyphens < 7 && qtyMinLength != qtyHyphens + 1 ) )
232 else if( hasLowerCases && ( qtyUpperCases > 0 ) )
236 if( (qtyUpperCases >= 7 && qtyMinLength != 7 )
237 || (qtyUpperCases < 7 && qtyMinLength != qtyUpperCases + 1 ) )
270 int segmentLength= 0;
276 bool segmentEnd= c ==
'\0'
284 if( segmentNo < 7 &&
minLengths[segmentNo] > segmentLength )
297 for(
int minLenIdx= 0 ; minLenIdx < 7 && minLengths[minLenIdx] >= 0 ; ++minLenIdx )
301 || !( minLenIdx == 6 ||
minLengths[minLenIdx + 1] == -1 ) ) )
317 "STRINGS/TOK",
"Empty search string in when matching function name." )
332 bool isSegOK =
false;
351 if( n ==
'\0' && segMinLen == 0)
357 if( segLen == 1 && rollbackLen > 0)
372 else if( same && isSegOK )
378 || (isSnake && h ==
'_' )
379 || (isKebab && h ==
'-' )
386 isSegOK= ( ( segMinLen >= 0 && segLen >= segMinLen )
387 || ( segMinLen < 0 && isSegEnd ) );
391 else if( segLen == 1 && segMinLen != 0 )
396 if( isSegEnd && n !=
'\0')
410 && ( ( isCamel && (!isalpha(h) || !isupper(h) ) )
411 || ( isSnake && h !=
'_' )
412 || ( isKebab && h !=
'-' ) ) )
420 if( !same || isSegEnd )
425 segMinLen = segNo < 7 ?
minLengths[segNo] : -2;
429 if( n ==
'\0' && (!isCamel || h ==
'\0' || rollbackLen == 0) )
430 return h ==
'\0' || isNormal || segMinLen == 0;
434 return same && isSegOK && (nIdx == needle.
Length());
437#if ALIB_CAMP && !DOXYGEN
443 const NString& resourceCategory,
455 if( parser.IsNull() )
461 parser= resourcePool.
Get( resourceCategory,
NString256() << resourceName << resourceNo++
465 NString256() <<
"Resource string(s) \"" << resourceCategory
466 <<
"/" << resourceName
467 <<
"(nn)\" not found when parsing token." )
469 if( parser.IsEmpty() )
472 while( parser.IsNotEmpty() )
474 String actValue= parser.ConsumeToken( outerSeparator );
475 token->
Define( actValue, innerSeparator );
481 case Token::DbgDefinitionError::OK:
483 case Token::DbgDefinitionError::EmptyName:
484 errorMessage=
"No token name found.";
486 case Token::DbgDefinitionError::ErrorReadingSensitivity:
487 errorMessage=
"Sensitivity value not found.";
489 case Token::DbgDefinitionError::ErrorReadingMinLengths:
490 errorMessage=
"Error parsing the list of minimum lengths.";
492 case Token::DbgDefinitionError::TooManyMinLengthsGiven:
493 errorMessage=
" A maximum of 7 minimum length values was exceeded.";
495 case Token::DbgDefinitionError::InconsistentMinLengths:
496 errorMessage=
"The number of given minimum length values is greater than 1 "
497 "but does not match the number of segments in the identifier.";
499 case Token::DbgDefinitionError::NoCaseSchemeFound:
500 errorMessage=
"More than one minimum length value was given but no "
501 "segmentation scheme could be detected." ;
503 case Token::DbgDefinitionError::MinLenExceedsSegmentLength:
504 errorMessage=
"A minimum length is specified to be higher than the token "
505 "name, respectively the according segment name.";
507 case Token::DbgDefinitionError::DefinitionStringNotConsumed:
508 errorMessage=
"The definition string was not completely consumed.";
510 case Token::DbgDefinitionError::ZeroMinLengthAndNotLastCamelHump:
511 errorMessage=
"Zero minimum length provided for segment which is not the last\n"
512 "of a camel case token.";
515 default: ALIB_ERROR(
"Illegal switch state.") break;
520 ALIB_ERROR(
"STRINGS", errorMessage, NString512() <<
521 "\n(While reading token table.)\n"
522 " Resource category (module name): \"" << resourceCategory <<
"\"\n"
523 " Resource name: \"" << resourceName <<
"\"\n"
524 " Token value parsed: \"" << actValue <<
"\"" )
538 for(
int i= 0 ; i < 35 ; ++i )
540 if( resourcePool.
Get( resourceCategory,
NString256() << resourceName << (resourceNo + i)
544 <<
"Detected a \"gap\" in numbering of resource strings while parsing "
545 "resource token table: "
546 "From index " << resourceNo - 1 <<
" to " << resourceNo + i - 1 <<
".\n"
547 "Resource category/name: " << resourceCategory <<
'/' << resourceName <<
"." )
554 "Size mismatch in resourced token table:\n"
555 " Resource category (module name): \"" << resourceCategory <<
"\"\n"
556 " Resource name: \"" << resourceName <<
"\"\n"
557 " Resourced table size: [" << tableSize <<
"]\n"
558 " Expected table size: [" << dbgSizeVerifier <<
"]" )
virtual const String & Get(const NString &category, const NString &name, bool dbgAssert)=0
constexpr bool IsEmpty() const
TChar CharAt(integer idx) const
constexpr bool IsNotEmpty() const
constexpr integer Length() const
TChar CharAtStart() const
constexpr bool IsNotNull() const
bool ConsumeDecDigits(TIntegral &result)
TString< TChar > ConsumeToken(TChar separator=',', lang::Inclusion includeSeparator=lang::Inclusion::Include)
TSubstring & Trim(const TCString< TChar > &whiteSpaces=TT_CStringConstants< TChar >::DefaultWhitespaces())
ALIB_API void detectFormat()
Detects snake_case, kebab-case or CamelCase.
Token()
Parameterless constructor. Creates an "undefined" token.
DbgDefinitionError DbgGetError()
const String & GetDefinitionName() const
ALIB_API void GetExportName(AString &target) const
lang::Case Sensitivity() const
String definitionName
The tokens' definition string part.
static constexpr Formats ignoreCase
Letter case sensitivity. This is combined with the format bits.
Formats GetFormat() const
ALIB_API void Define(const String &definition, character separator=';')
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.
static ALIB_API void LoadResourcedTokens(lang::resources::ResourcePool &resourcePool, const NString &resourceCategory, const NString &resourceName, strings::util::Token *target, int dbgSizeVerifier, character outerSeparator=',', character innerSeparator=' ')
Formats format
Defines the "case type" as well as the letter case sensitivity of this token.
@ 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
String exportName
The tokens' optional explicit export name.
int8_t GetMinLength(int idx) const
ALIB_API bool Match(const String &needle)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_WARNINGS_RESTORE
#define ALIB_ASSERT_ERROR(cond,...)
#define ALIB_WARNINGS_ALLOW_UNSAFE_BUFFER_USAGE
#define ALIB_REL_DBG(releaseCode,...)
bool Parse(strings::TSubstring< TChar > &input, TEnum &result)
@ Exclude
Chooses exclusion.
Case
Denotes upper and lower case character treatment.
NLocalString< 128 > NString128
Type alias name for TLocalString<nchar,128>.
strings::TSubstring< character > Substring
Type alias in namespace alib.
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
characters::character character
Type alias in namespace alib.
NLocalString< 512 > NString512
Type alias name for TLocalString<nchar,512>.
lang::integer integer
Type alias in namespace alib.