ALib C++ Library
Library Version: 2511 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 ALIB_DBG( int tableSize= 0; )
48 int resourceNo= -1; // disable number parsing
49
50 Substring parser= resourcePool.Get( resourceCategory, resourceName ALIB_DBG(, false ) );
51 if( parser.IsNull() )
52 resourceNo= 0; // enable number parsing
53
54 for( ;; ) {
55 if (resourceNo >= 0)
56 parser= resourcePool.Get( resourceCategory, NString256() << resourceName << resourceNo++
57 ALIB_DBG(, false ) );
58
59 ALIB_ASSERT_ERROR( resourceNo != 1 || parser.IsNotNull(), "STRINGS/TOK",
60 "Resource string(s) \"{}/{}(nn)\" not found when parsing token.",
61 resourceCategory, resourceName )
62
63 if( parser.IsEmpty() )
64 break;
65
66 while( parser.IsNotEmpty() ) {
67 String actValue= parser.ConsumeToken( outerSeparator );
68 token->Define( actValue, innerSeparator );
69
70 #if ALIB_DEBUG
71 NCString errorMessage(nullptr);
72 switch( token->DbgGetError() ) {
74 break;
76 errorMessage= "No token name found.";
77 break;
79 errorMessage= "Sensitivity value not found.";
80 break;
82 errorMessage= "Error parsing the list of minimum lengths.";
83 break;
85 errorMessage= " A maximum of 7 minimum length values was exceeded.";
86 break;
88 errorMessage= "The number of given minimum length values is greater than 1 "
89 "but does not match the number of segments in the identifier.";
90 break;
92 errorMessage= "More than one minimum length value was given but no "
93 "segmentation scheme could be detected." ;
94 break;
96 errorMessage= "A minimum length is specified to be higher than the token "
97 "name, respectively the according segment name.";
98 break;
100 errorMessage= "The definition string was not completely consumed.";
101 break;
103 errorMessage= "Zero minimum length provided for segment which is not the last\n"
104 "of a camel case token.";
105 break;
106
107 default: ALIB_ERROR( "RESOURCES", "Illegal switch state." ) break;
108 }
109
110 if( errorMessage.IsNotEmpty() ) {
111 ALIB_ERROR( "STRINGS", errorMessage,
112 "\n(While reading token table.)\n"
113 " Resource category (module name): \"{}\"\n"
114 " Resource name: \"{}\"\n"
115 " Token value parsed: \"{}\"",
116 resourceCategory, resourceName, actValue )
117 }
118
119 #endif
120
121
122 ++token;
123 ALIB_DBG( tableSize++; )
124 } }
125
126 // check if there are more coming (a gap in numbered definition)
127 #if ALIB_DEBUG
128 if( resourceNo > 1 )
129 for( int i= 0 ; i < 35 ; ++i ) {
130 if( resourcePool.Get( resourceCategory, NString256() << resourceName << (resourceNo + i)
131 ALIB_DBG(, false ) ).IsNotNull() )
132 {
133 ALIB_ERROR( "STRINGS",
134 "Detected a \"gap\" in numbering of resource strings while parsing "
135 "resource token table: "
136 "From index {} to {}.\n"
137 " Resource category/name: {} / {}",
138 resourceNo - 1, resourceNo + i - 1, resourceCategory, resourceName )
139 } }
140 #endif
141
142
143 ALIB_ASSERT_ERROR( dbgSizeVerifier == tableSize, "STRINGS/TOK",
144 "Size mismatch in resourced token table:\n"
145 " Resource category (module name): \"{}\"\n"
146 " Resource name: \"{}\"\n"
147 " Resourced table size: [{}]\n"
148 " Expected table size: [{}]",
149 resourceCategory, resourceName, tableSize, dbgSizeVerifier )
150}
151#endif // !DOXYGEN
152
153# include "ALib.Lang.CIMethods.H"
154
155} // namespace [alib::strings::util]
156
157#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:1062
#define ALIB_DBG(...)
Definition alib.inl:853
#define ALIB_ASSERT_ERROR(cond, domain,...)
Definition alib.inl:1066
constexpr bool IsNotNull(const T &t)
Definition tmp.inl: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.inl:2198
resources::ResourcePool ResourcePool
Type alias in namespace alib.
strings::TCString< nchar > NCString
Type alias in namespace alib.
Definition cstring.inl:484
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189
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.