ALib C++ Library
Library Version: 2510 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
strings_loadtokens.cpp
1// #################################################################################################
2// ALib C++ Library
3//
4// Copyright 2013-2025 A-Worx GmbH, Germany
5// Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6// #################################################################################################
7#include "alib_precompile.hpp"
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"
10#endif
11#if ALIB_C20_MODULES
12 module;
13#endif
14// ====================================== Global Fragment ======================================
16// =========================================== Module ==========================================
17#if ALIB_C20_MODULES
18 module ALib.Resources;
19# if ALIB_ENUMRECORDS
20 import ALib.EnumRecords;
21# endif
22#else
24# include "ALib.Resources.H"
25#endif
26// ====================================== Implementation =======================================
27#if ALIB_ENUMRECORDS
28// Windows.h might bring in max/min macros
29#if defined( max )
30 #undef max
31 #undef min
32#endif
33
34
35namespace alib::strings::util {
36
37
39#if !DOXYGEN
40void LoadResourcedTokens( ResourcePool& resourcePool,
41 const NString& resourceCategory,
42 const NString& resourceName,
43 strings::util::Token* token,
44 ALIB_DBG( int dbgSizeVerifier, )
45 character outerSeparator,
46 character innerSeparator )
47{
48 ALIB_DBG( int tableSize= 0; )
49 int resourceNo= -1; // disable number parsing
50
51 Substring parser= resourcePool.Get( resourceCategory, resourceName ALIB_DBG(, false ) );
52 if( parser.IsNull() )
53 resourceNo= 0; // enable number parsing
54
55 for( ;; )
56 {
57 if (resourceNo >= 0)
58 parser= resourcePool.Get( resourceCategory, NString256() << resourceName << resourceNo++
59 ALIB_DBG(, false ) );
60
61 ALIB_ASSERT_ERROR( resourceNo != 1 || parser.IsNotNull(), "STRINGS/TOK",
62 "Resource string(s) \"{}/{}(nn)\" not found when parsing token.",
63 resourceCategory, resourceName )
64
65 if( parser.IsEmpty() )
66 break;
67
68 while( parser.IsNotEmpty() )
69 {
70 String actValue= parser.ConsumeToken( outerSeparator );
71 token->Define( actValue, innerSeparator );
72
73 #if ALIB_DEBUG
74 NCString errorMessage(nullptr);
75 switch( token->DbgGetError() )
76 {
78 break;
80 errorMessage= "No token name found.";
81 break;
83 errorMessage= "Sensitivity value not found.";
84 break;
86 errorMessage= "Error parsing the list of minimum lengths.";
87 break;
89 errorMessage= " A maximum of 7 minimum length values was exceeded.";
90 break;
92 errorMessage= "The number of given minimum length values is greater than 1 "
93 "but does not match the number of segments in the identifier.";
94 break;
96 errorMessage= "More than one minimum length value was given but no "
97 "segmentation scheme could be detected." ;
98 break;
100 errorMessage= "A minimum length is specified to be higher than the token "
101 "name, respectively the according segment name.";
102 break;
104 errorMessage= "The definition string was not completely consumed.";
105 break;
107 errorMessage= "Zero minimum length provided for segment which is not the last\n"
108 "of a camel case token.";
109 break;
110
111 default: ALIB_ERROR( "RESOURCES", "Illegal switch state." ) break;
112 }
113
114 if( errorMessage.IsNotEmpty() )
115 {
116 ALIB_ERROR( "STRINGS", errorMessage,
117 "\n(While reading token table.)\n"
118 " Resource category (module name): \"{}\"\n"
119 " Resource name: \"{}\"\n"
120 " Token value parsed: \"{}\"",
121 resourceCategory, resourceName, actValue )
122 }
123
124 #endif
125
126
127 ++token;
128 ALIB_DBG( tableSize++; )
129 }
130 }
131
132 // check if there are more coming (a gap in numbered definition)
133 #if ALIB_DEBUG
134 if( resourceNo > 1 )
135 for( int i= 0 ; i < 35 ; ++i )
136 {
137 if( resourcePool.Get( resourceCategory, NString256() << resourceName << (resourceNo + i)
138 ALIB_DBG(, false ) ).IsNotNull() )
139 {
140 ALIB_ERROR( "STRINGS",
141 "Detected a \"gap\" in numbering of resource strings while parsing "
142 "resource token table: "
143 "From index {} to {}.\n"
144 " Resource category/name: {} / {}",
145 resourceNo - 1, resourceNo + i - 1, resourceCategory, resourceName )
146 }
147 }
148 #endif
149
150
151 ALIB_ASSERT_ERROR( dbgSizeVerifier == tableSize, "STRINGS/TOK",
152 "Size mismatch in resourced token table:\n"
153 " Resource category (module name): \"{}\"\n"
154 " Resource name: \"{}\"\n"
155 " Resourced table size: [{}]\n"
156 " Expected table size: [{}]",
157 resourceCategory, resourceName, tableSize, dbgSizeVerifier )
158}
159#endif // !DOXYGEN
160
161# include "ALib.Lang.CIMethods.H"
162
163} // namespace [alib::strings::util]
164
165#endif // ALIB_ENUMRECORDS
@ ErrorReadingSensitivity
Sensitivity value not found.
Definition token.inl:151
@ TooManyMinLengthsGiven
A maximum of 7 minimum length values was exceeded.
Definition token.inl:153
@ ErrorReadingMinLengths
Error parsing the list of minimum lengths.
Definition token.inl:152
@ DefinitionStringNotConsumed
The definition string was not completely consumed.
Definition token.inl:160
#define ALIB_ERROR(domain,...)
Definition alib.inl:1045
#define ALIB_DBG(...)
Definition alib.inl:836
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1049
constexpr bool IsNotNull(const T &t)
Definition tmp.inl:56
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.inl:2390
resources::ResourcePool ResourcePool
Type alias in namespace alib.
strings::TCString< nchar > NCString
Type alias in namespace alib.
Definition cstring.inl:512
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2381
NLocalString< 256 > NString256
Type alias name for TLocalString<nchar,256>.
characters::character character
Type alias in namespace alib.
strings::TSubstring< character > Substring
Type alias in namespace alib.