10# if !defined(HPP_ALIB_STRINGS_UTIL_TOKEN)
15# if !defined(HPP_ALIB_ENUMS_SERIALIZATION)
18# if !defined(HPP_ALIB_LANG_COMMONENUMS)
40namespace alib {
namespace strings {
namespace util {
45 + int8_t(sensitivity == lang::Case::Sensitive ?
Formats(0) : ignoreCase) ) )
46, minLengths { minLength, 0,0,0,0,0,0 }
49 if( minLength < 0 || minLength >
name.
Length() )
59 int8_t minLength1, int8_t minLength2, int8_t minLength3, int8_t minLength4, int8_t minLength5,
60 int8_t minLength6, int8_t minLength7 )
62, minLengths { minLength1, minLength2, minLength3, minLength4, minLength5, minLength6, minLength7 }
86 size_t qtyMinLengths= 0;
99 if( qtyMinLengths >= 7 )
118 if( qtyMinLengths == 0 )
121 if( qtyMinLengths > 0 && qtyMinLengths < 7 )
150 while( qtyMinLength < 7 &&
minLengths[qtyMinLength] >= 0 )
156 if( qtyMinLength > 1 )
159 bool hasLowerCases= isalpha(
name[0]) && islower(
name[0]);
160 int qtyUpperCases= 0;
161 int qtyUnderscores= 0;
166 if( c ==
'_' ) ++qtyUnderscores;
167 else if( c ==
'-' ) ++qtyHyphens;
168 else if( isalpha(c) )
180 if( qtyUnderscores > 0 )
184 if( (qtyUnderscores >= 7 && qtyMinLength != 7 )
185 || (qtyUnderscores < 7 && qtyMinLength != qtyUnderscores + 1 ) )
191 else if( qtyHyphens > 0 )
195 if( (qtyHyphens >= 7 && qtyMinLength != 7 )
196 || (qtyHyphens < 7 && qtyMinLength != qtyHyphens + 1 ) )
202 else if( hasLowerCases && ( qtyUpperCases > 0 ) )
206 if( (qtyUpperCases >= 7 && qtyMinLength != 7 )
207 || (qtyUpperCases < 7 && qtyMinLength != qtyUpperCases + 1 ) )
240 int segmentLength= 0;
246 bool segmentEnd= c ==
'\0'
254 if( segmentNo < 7 &&
minLengths[segmentNo] > segmentLength )
267 for(
int minLenIdx= 0 ; minLenIdx < 7 && minLengths[minLenIdx] >= 0 ; ++minLenIdx )
271 || !( minLenIdx == 6 ||
minLengths[minLenIdx + 1] == -1 ) ) )
287 "STRINGS/TOK",
"Empty search string in when matching function name." )
302 bool isSegOK =
false;
321 if( n ==
'\0' && segMinLen == 0)
327 if( segLen == 1 && rollbackLen > 0)
342 else if( same && isSegOK )
348 || (isSnake && h ==
'_' )
349 || (isKebab && h ==
'-' )
356 isSegOK= ( ( segMinLen >= 0 && segLen >= segMinLen )
357 || ( segMinLen < 0 && isSegEnd ) );
361 else if( segLen == 1 && segMinLen != 0 )
366 if( isSegEnd && n !=
'\0')
380 && ( ( isCamel && (!isalpha(h) || !isupper(h) ) )
381 || ( isSnake && h !=
'_' )
382 || ( isKebab && h !=
'-' ) ) )
390 if( !same || isSegEnd )
395 segMinLen = segNo < 7 ?
minLengths[segNo] : -2;
399 if( n ==
'\0' && (!isCamel || h ==
'\0' || rollbackLen == 0) )
400 return h ==
'\0' || isNormal || segMinLen == 0;
404 return same && isSegOK && (nIdx == needle.
Length());
407#if ALIB_CAMP && !defined(ALIB_DOX)
411 const NString& resourceCategory,
423 if( parser.IsNull() )
429 parser= resourcePool.
Get( resourceCategory,
NString256() << resourceName << resourceNo++
433 NString256() <<
"Resource string(s) \"" << resourceCategory
434 <<
"/" << resourceName
435 <<
"(nn)\" not found when parsing token." )
437 if( parser.IsEmpty() )
440 while( parser.IsNotEmpty() )
442 String actValue= parser.ConsumeToken( outerSeparator );
443 token->
Define( actValue, innerSeparator );
452 errorMessage=
"No token name found.";
455 errorMessage=
"Sensitivity value not found.";
458 errorMessage=
"Error parsing the list of minimum lengths.";
461 errorMessage=
" A maximum of 7 minimum length values was exceeded.";
464 errorMessage=
"The number of given minimum length values is greater than 1 "
465 "but does not match the number of segments in the identifier.";
468 errorMessage=
"More than one minimum length value was given but no "
469 "segmentation scheme could be detected." ;
472 errorMessage=
"A minimum length is specified to be higher than the token "
473 "name, respectively the according segment name.";
476 errorMessage=
"The definition string was not completely consumed.";
479 errorMessage=
"Zero minimum length provided for segment which is not the last\n"
480 "of a camel case token.";
487 "\n(While reading token table.)\n"
488 " Resource category (module name): \"" << resourceCategory <<
"\"\n"
489 " Resource name: \"" << resourceName <<
"\"\n"
490 " Token value parsed: \"" << actValue <<
"\"" )
504 for(
int i= 0 ; i < 35 ; ++i )
506 if( resourcePool.
Get( resourceCategory,
NString256() << resourceName << (resourceNo + i)
510 <<
"Detected a \"gap\" in numbering of resource strings while parsing "
511 "resource token table: "
512 "From index " << resourceNo - 1 <<
" to " << resourceNo + i - 1 <<
".\n"
513 "Resource category/name: " << resourceCategory <<
'/' << resourceName <<
"." )
520 "Size mismatch in resourced token table:\n"
521 " Resource category (module name): \"" << resourceCategory <<
"\"\n"
522 " Resource name: \"" << resourceName <<
"\"\n"
523 " Resourced table size: [" << tableSize <<
"]\n"
524 " Expected table size: [" << dbgSizeVerifier <<
"]" )
540 for(
int i= 0 ; i < 7 ; ++i )
545 target[target.Length()-1]= characters::CharArray<character>::ToLower(target[target.Length()-1]);
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
TSubstring & Trim(const TCString< TChar > &whiteSpaces=TT_StringConstants< TChar >::DefaultWhitespaces())
TString< TChar > ConsumeToken(TChar separator=',')
bool ConsumeDecDigits(TIntegral &result)
ALIB_API void detectFormat()
DbgDefinitionError DbgGetError()
lang::Case Sensitivity() const
static constexpr Formats ignoreCase
const String & GetRawName() const
Formats GetFormat() const
ALIB_API void Define(const String &definition, character separator=';')
@ 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=' ')
@ 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
int8_t GetMinLength(int idx) const
ALIB_API bool Match(const String &needle)
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
#define ALIB_ENUMS_MAKE_BITWISE(TEnum)
#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)
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.
static TChar ToUpper(TChar c)