ALib C++ Library
Library Version: 2312 R0
Documentation generated by doxygen
text.cpp
1 // #################################################################################################
2 // ALib C++ Library
3 //
4 // Copyright 2013-2023 A-Worx GmbH, Germany
5 // Published under 'Boost Software License' (a free software license, see LICENSE.txt)
6 // #################################################################################################
8 
9 #if !defined(ALIB_DOX)
10 # if !defined(HPP_ALIB_TEXT_TEXT)
11 # include "alib/text/text.hpp"
12 # endif
13 # if !defined(HPP_ALIB_ENUMS_SERIALIZATION)
15 # endif
16 # if !defined (HPP_ALIB_ENUMS_RECORDBOOTSTRAP)
18 # endif
19 # if ALIB_THREADS && !defined(HPP_ALIB_THREADS_THREAD)
20 # include "alib/threads/thread.hpp"
21 # endif
22 # if !defined (HPP_ALIB_RESOURCES_RESOURCES)
24 # endif
25 
26 # if !defined (HPP_ALIB_TEXT_FORMATTER_PYTHONSTYLE)
28 # endif
29 # if !defined (HPP_ALIB_TEXT_FORMATTER_JAVASTYLE)
31 # endif
32 
33 # if ALIB_SYSTEM && !defined(HPP_ALIB_SYSTEM_CALENDAR)
34 # include "alib/system/calendar.hpp"
35 # endif
36 # if !defined (HPP_ALIB_FS_MODULES_DISTRIBUTION)
38 # endif
39 #endif // !defined(ALIB_DOX)
40 
41 
42 using namespace aworx::lib::strings;
43 
45 
46 namespace aworx { namespace lib {
47 
49 
50 /**
51  * This \alibmod implements string formatting based on "placeholder format strings" similar to
52  * good old \c printf function and similar to what is given with many modern programming language's
53  * core libraries.
54  *
55  * Please consult \ref alib_mod_text "ALib Module Text - Programmer's Manual"
56  * for further information.
57  */
58 namespace text {
59 
60 
61 Text::Text()
62 : Module( ALIB_VERSION, ALIB_REVISION, "TEXT" )
63 {
64  ALIB_ASSERT_ERROR( this == &TEXT, "TEXT",
65  "Instances of class Text must not be created. Use singleton aworx::lib::TEXT" )
66 }
67 
68 
69 void Text::bootstrap( BootstrapPhases phase, int, const char**, const wchar_t** )
70 {
72  {
74  ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER( vt_text_exceptions )
75 
76 
77 #if !ALIB_RESOURCES_OMIT_DEFAULTS
79 
80  "E<", A_CHAR("format::"),
81 
82 // general formatter errors
83 
84  "E0" , A_CHAR( "11,ArgumentIndexIs0" ",FMG11" ),
85  "E1" , A_CHAR( "12,ArgumentIndexOutOfBounds" ",FMG12" ),
86  "E2" , A_CHAR( "13,IncompatibleTypeCode" ",FMG13" ),
87 
88  // Formatter Python Style
89  "E3" , A_CHAR( "101,MissingClosingBracket" ",FPS101" ),
90  //...
91  //...
92  "E4" , A_CHAR( "102,MissingPrecisionValuePS" ",FPS102" ),
93  "E5" , A_CHAR( "103,DuplicateTypeCode" ",FPS103" ),
94  "E6" , A_CHAR( "104,UnknownTypeCode" ",FPS104" ),
95  "E7" , A_CHAR( "105,ExclamationMarkExpected" ",FPS105" ),
96  "E8" , A_CHAR( "106,UnknownConversionPS" ",FPS106" ),
97  "E9" , A_CHAR( "107,PrecisionSpecificationWithInteger" ",FPS107" ),
98  "E10", A_CHAR( "108,MissingReplacementStrings" ",FPS108" ),
99 
100  // Formatter Java Style
101  "E11" , A_CHAR( "201,NegativeValuesInBracketsNotSupported" ",FJS101" ),
102  "E12" , A_CHAR( "202,MissingPrecisionValueJS" ",FJS102" ),
103  "E13" , A_CHAR( "203,HexadecimalFloatFormatNotSupported" ",FJS103" ),
104  "E14" , A_CHAR( "204,NoAlternateFormOfConversion" ",FJS104" ),
105  "E15" , A_CHAR( "205,NoPrecisionWithConversion" ",FJS105" ),
106  "E16" , A_CHAR( "206,UnknownDateTimeConversionSuffix" ",FJS106" ),
107  "E17" , A_CHAR( "207,UnknownConversionJS" ",FJS107" ),
108 
109  // PropertyFormatter and PropertyFormatters
110  "E18" , A_CHAR( "501,UnknownPropertyInFormatString" ",PFM501" ),
111  "E19" , A_CHAR( "502,ErrorInResultingFormatString" ",PFM502" ),
112  "E20" , A_CHAR( "510,MissingConfigurationVariable" ",PFM510" ),
113 
114  // class Paragraphs
115  "E21" , A_CHAR( "601,UnknownMarker" ",ST601" ),
116  "E22" , A_CHAR( "602,EndmarkerWithoutStart" ",ST602" ),
117 
118  // general formatter errors
119  "FMG11" , A_CHAR( "Argument index 0 not allowed.\n"
120  "In: {!Q}\n {!Fill}^" ),
121  "FMG12" , A_CHAR( "Argument index #{} is out of bounds. {} arguments are available.\n"
122  "In: {!Q}\n {!Fill}^" ),
123  "FMG13" , A_CHAR( "Incompatible type code {!Q'} for argument #{} which is of type {!Q}.\n"
124  "In: {!Q}\n {!Fill}^" ),
125 
126  // Formatter Python Style
127  "FPS101" , A_CHAR( "Closing bracket '}}' of placeholder not found (or syntax error).\n"
128  "In: {!Q}\n {!Fill}^" ),
129  //...
130  //...
131  //...
132  "FPS102" , A_CHAR( "Missing precision value after '.' character."
133  "\nIn: {!Q}\n {!Fill}^" ),
134  "FPS103" , A_CHAR( "Duplicate type code {!Q'} given (previous was {!Q'})."
135  "\nIn: {!Q}\n {!Fill}^" ),
136  "FPS104" , A_CHAR( "Unknown type code {!Q'} given."
137  "\nIn: {!Q}\n {!Fill}^" ),
138  "FPS105" , A_CHAR( "Expected '!' in continuation of placeholder."
139  "\nIn: {!Q}\n {!Fill}^" ),
140  "FPS106" , A_CHAR( "Unknown conversion \"!{}\"."
141  "\nIn: {!Q}\n {!Fill}^" ),
142  "FPS107" , A_CHAR( "Precision not allowed with integer format."
143  "\nIn: {!Q}\n {!Fill}^" ),
144  "FPS108" , A_CHAR( "Missing pair of replacement strings \")<src><repl>\" after \"!Replace\"."
145  "\nIn: {!Q}\n {!Fill}^" ),
146 
147 
148  // Formatter Java Style
149  "FJS101" , A_CHAR( "Brackets for negative values not implemented/supported."
150  "\nIn: {!Q}\n {!Fill}^" ),
151  "FJS102" , A_CHAR( "Missing precision value after '.' character."
152  "\nIn: {!Q}\n {!Fill}^" ),
153  "FJS103" , A_CHAR( "Hexadecimal float format not implemented/supported."
154  "\nIn: {!Q}\n {!Fill}^" ),
155  "FJS104" , A_CHAR( "Alternate form '#' not supported with conversion {!Q}."
156  "\nIn: {!Q}\n {!Fill}^" ),
157  "FJS105" , A_CHAR( "Precision specification (\".{}\") is not supported with conversion {!Q}."
158  "\nIn: {!Q}\n {!Fill}^" ),
159  "FJS106" , A_CHAR( "Unknown date/time conversion suffix {!Q'}."
160  "\nIn: {!Q}\n {!Fill}^" ),
161  "FJS107" , A_CHAR( "Unknown conversion character {!Q'}."
162  "\nIn: {!Q}\n {!Fill}^" ),
163 
164 
165  // PropertyFormatter and PropertyFormatters
166  "PFM501" , A_CHAR( "Unknown property identifier \"{}{}\" in format string.\n"
167  "Format string: {!Q}.\n"
168  "Allowed identifiers: " ),
169  "PFM502" , A_CHAR( "Error in resulting format string.\nSource format: {!Q}." ),
170  "PFM510" , A_CHAR( "Missing or empty configuration variable {!Q} containing user defined format string." ),
171 
172  // class Paragraphs
173  "ST601" , A_CHAR( "Unknown marker at position {}.\n"
174  " Marked text: {!Q}.\n"
175  " {!Fill}^\n" ),
176  "ST602" , A_CHAR( "Found an end-marker without a start marker at position {}.\n"
177  " Marked text: {!Q}.\n"
178  " {!Fill}^\n" ),
179 
180 // end of BootstrapBulk()
181 nullptr );
182 #endif // !ALIB_RESOURCES_OMIT_DEFAULTS
183 
184 
186 
187 
188  // create formatters. This has to be done very early, so that they can be used during
189  // initialization.
191  Formatter::defaultFormatter->Next.reset( new FormatterJavaStyle() ) ;
192 
193  } // phase == BootstrapPhases::PrepareResources
194 
195  else if( phase == BootstrapPhases::PrepareConfig )
196  {
198  }
199 
200 }
201 
203 {
204  if( phase != ShutdownPhases::Destruct )
205  return;
206 
208  "TEXT", "DefaultFormatter still shared more than once: ",
209  int(Formatter::defaultFormatter.use_count()) )
210 
212 }
213 
214 
215 
216 
217 }}} // namespace [aworx::lib::text]
aworx::lib::Module::ShutdownPhases::Destruct
The main phase of termination that destructs everything.
aworx::lib::Module::resourcePool
resources::ResourcePool * resourcePool
Definition: module.hpp:114
aworx::lib::ALibDistribution::CheckDistribution
ALIB_API void CheckDistribution(int alibVersion=ALIB_VERSION, uint64_t compilationFlags=ALIB_COMPILATION_FLAGS)
Definition: distribution.cpp:612
aworx::lib::text::Text::shutdown
virtual void shutdown(ShutdownPhases phase) override
Definition: text.cpp:202
aworx::lib::Module::ShutdownPhases
ShutdownPhases
Definition: module.hpp:88
aworx::lib::text::Text::bootstrap
virtual void bootstrap(BootstrapPhases phase, int argc, const char **argv, const wchar_t **wargv) override
Definition: text.cpp:69
resources.hpp
aworx::lib::enums::EnumRecords::Bootstrap
static void Bootstrap(TEnum element, TArgs &&... args) noexcept
aworx::lib::Module::BootstrapPhases
BootstrapPhases
Definition: module.hpp:78
recordbootstrap.hpp
aworx::FormatterPythonStyle
lib::text::FormatterPythonStyle FormatterPythonStyle
Type alias in namespace aworx.
Definition: text/fwds.hpp:68
aworx::lib::Module::BootstrapPhases::PrepareResources
serialization.hpp
aworx::lib::Module::ResourceCategory
NCString ResourceCategory
Definition: module.hpp:172
aworx::lib::text::Exceptions
Exceptions
Definition: text.hpp:37
alib_precompile.hpp
thread.hpp
ALIB_REVISION
#define ALIB_REVISION
Definition: modules.hpp:21
aworx
Definition: alox/alox.hpp:40
aworx::ALIB
lib::ALibDistribution ALIB
Definition: distribution.cpp:125
formatterpythonstyle.hpp
aworx::lib::TEXT
text::Text TEXT
Definition: text.cpp:48
ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE
#define ALIB_BOXING_BOOTSTRAP_REGISTER_FAPPEND_FOR_APPENDABLE_TYPE(TAppendable)
Definition: functions.inl:502
aworx::lib::resources::ResourcePool::BootstrapBulk
virtual void BootstrapBulk(const nchar *category,...)=0
A_CHAR
#define A_CHAR(STR)
ALIB_ASSERT_ERROR
#define ALIB_ASSERT_ERROR(cond,...)
Definition: tools.hpp:185
aworx::FormatterJavaStyle
lib::text::FormatterJavaStyle FormatterJavaStyle
Type alias in namespace aworx.
Definition: text/fwds.hpp:71
formatterjavastyle.hpp
ALIB_ASSERT_WARNING
#define ALIB_ASSERT_WARNING(cond,...)
Definition: tools.hpp:186
ALIB_BOXING_VTABLE_DEFINE
#define ALIB_BOXING_VTABLE_DEFINE(TMapped, Identifier)
Definition: vtable.inl:490
text.hpp
aworx::lib::text::Text
Definition: text.hpp:158
ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER
#define ALIB_BOXING_BOOTSTRAP_VTABLE_DBG_REGISTER(Identifier)
Definition: vtable.inl:506
distribution.hpp
ALIB_VERSION
#define ALIB_VERSION
Definition: modules.hpp:20
aworx::lib::Module::BootstrapPhases::PrepareConfig
aworx::lib::Module
Definition: module.hpp:74
calendar.hpp
aworx::lib::text::Formatter::defaultFormatter
static ALIB_API SPFormatter defaultFormatter
Definition: formatter.hpp:324
aworx::lib::strings
Definition: logger.hpp:205