ALib C++ Framework
by
Library Version: 2605 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
strings_loadtokens.cpp
1#if ALIB_ENUMRECORDS
2// Windows.h might bring in max/min macros
3#if defined( max )
4 #undef max
5 #undef min
6#endif
7
8
9namespace alib::strings::util {
10
11
13#if !DOXYGEN
14void LoadResourcedTokens( ResourcePool& resourcePool,
15 const NString& resourceCategory,
16 const NString& resourceName,
17 strings::util::Token* token,
18 ALIB_DBG( int dbgSizeVerifier, )
19 character outerSeparator,
20 character innerSeparator ) {
21 ALIB_DBG( int tableSize= 0; )
22 int resourceNo= -1; // disable number parsing
23
24 Substring parser= resourcePool.Get( resourceCategory, resourceName ALIB_DBG(, false ) );
25 if( parser.IsNull() )
26 resourceNo= 0; // enable number parsing
27
28 for( ;; ) {
29 if (resourceNo >= 0)
30 parser= resourcePool.Get( resourceCategory, NString256() << resourceName << resourceNo++
31 ALIB_DBG(, false ) );
32
33 ALIB_ASSERT_ERROR( resourceNo != 1 || parser.IsNotNull(), "STRINGS/TOK",
34 "Resource string(s) \"{}/{}(nn)\" not found when parsing token.",
35 resourceCategory, resourceName )
36
37 if( parser.IsEmpty() )
38 break;
39
40 while( parser.IsNotEmpty() ) {
41 String actValue= parser.ConsumeToken( outerSeparator );
42 token->Define( actValue, innerSeparator );
43
44 #if ALIB_DEBUG
45 NCString errorMessage(nullptr);
46 switch( token->DbgGetError() ) {
48 break;
50 errorMessage= "No token name found.";
51 break;
53 errorMessage= "Sensitivity value not found.";
54 break;
56 errorMessage= "Error parsing the list of minimum lengths.";
57 break;
59 errorMessage= " A maximum of 7 minimum length values was exceeded.";
60 break;
62 errorMessage= "The number of given minimum length values is greater than 1 "
63 "but does not match the number of segments in the identifier.";
64 break;
66 errorMessage= "More than one minimum length value was given but no "
67 "segmentation scheme could be detected." ;
68 break;
70 errorMessage= "A minimum length is specified to be higher than the token "
71 "name, respectively the according segment name.";
72 break;
74 errorMessage= "The definition string was not completely consumed.";
75 break;
77 errorMessage= "Zero minimum length provided for segment which is not the last\n"
78 "of a camel case token.";
79 break;
80
81 default: ALIB_ERROR( "RESOURCES", "Illegal switch state." ) break;
82 }
83
84 if( errorMessage.IsNotEmpty() ) {
85 ALIB_ERROR( "STRINGS", errorMessage,
86 "\n(While reading token table.)\n"
87 " Resource category (module name): \"{}\"\n"
88 " Resource name: \"{}\"\n"
89 " Token value parsed: \"{}\"",
90 resourceCategory, resourceName, actValue )
91 }
92
93 #endif
94
95
96 ++token;
97 ALIB_DBG( tableSize++; )
98 } }
99
100 // check if there are more coming (a gap in numbered definition)
101 #if ALIB_DEBUG
102 if( resourceNo > 1 )
103 for( int i= 0 ; i < 35 ; ++i ) {
104 if( resourcePool.Get( resourceCategory, NString256() << resourceName << (resourceNo + i)
105 ALIB_DBG(, false ) ).IsNotNull() )
106 {
107 ALIB_ERROR( "STRINGS",
108 "Detected a \"gap\" in numbering of resource strings while parsing "
109 "resource token table: "
110 "From index {} to {}.\n"
111 " Resource category/name: {} / {}",
112 resourceNo - 1, resourceNo + i - 1, resourceCategory, resourceName )
113 } }
114 #endif
115
116
117 ALIB_ASSERT_ERROR( dbgSizeVerifier == tableSize, "STRINGS/TOK",
118 "Size mismatch in resourced token table:\n"
119 " Resource category (module name): \"{}\"\n"
120 " Resource name: \"{}\"\n"
121 " Resourced table size: [{}]\n"
122 " Expected table size: [{}]",
123 resourceCategory, resourceName, tableSize, dbgSizeVerifier )
124}
125#endif // !DOXYGEN
126
127# include "ALib.Lang.CIMethods.H"
128
129} // namespace [alib::strings::util]
130
131#endif // ALIB_ENUMRECORDS
#define ALIB_ERROR(domain,...)
#define ALIB_DBG(...)
#define ALIB_ASSERT_ERROR(cond, domain,...)
@ ErrorReadingSensitivity
Sensitivity value not found.
Definition token.hpp:149
@ TooManyMinLengthsGiven
A maximum of 7 minimum length values was exceeded.
Definition token.hpp:151
@ ErrorReadingMinLengths
Error parsing the list of minimum lengths.
Definition token.hpp:150
@ DefinitionStringNotConsumed
The definition string was not completely consumed.
Definition token.hpp:158
constexpr bool IsNotNull(const T &t)
Definition tmp.hpp:55
void LoadResourcedTokens(camp::Camp &module, const NString &resourceName, strings::util::Token *target, int dbgSizeVerifier, character outerSeparator=',', character innerSeparator=' ')
strings::TString< nchar > NString
Type alias in namespace #"%alib".
Definition string.hpp:2174
resources::ResourcePool ResourcePool
Type alias in namespace #"%alib".
strings::TCString< nchar > NCString
Type alias in namespace #"%alib".
Definition cstring.hpp:408
strings::TString< character > String
Type alias in namespace #"%alib".
Definition string.hpp:2165
strings::TSubstring< character > Substring
Type alias in namespace #"%alib".
NLocalString< 256 > NString256
Type alias name for #"TLocalString;TLocalString<nchar,256>".
characters::character character
Type alias in namespace #"%alib".