Implements a Formatter according to the formatting standards of the Java language .
In general, the original specification is covered quite well. The differences and specialties are:
'.'
and the grouping character ','
. As the syntax specification does not provide a feature to switch between standard and locale setting, the corresponding fields of AlternativeNumberFormat are not used with this formatter. Instead, to enable localized output, method NumberFormat::SetFromLocale has to be invoked on field FormatterStdImpl::DefaultNumberFormat. Alternatively, attributes of this object may be changed manually or by other means to reflect a desired locale.'a'
and 'A'
) is not supported.'('
, used to write negative numbers in round brackets, is not supported.'%<'
is already allowed with the first placeholder. This Chooses the first argument. (In Java a MissingFormatArgumentException would be thrown.)'^'
is an extension to the standard and denotes center-alignment - just like '-'
in the standard denotes left-alignment. Right-alignment is the default.p>
's'
is given together with a precision, the field is cut, even if it cuts the number somewhere. (This is just a warning and same behavior as in original specification.)'f'
, 'g'
and 'e'
), the values specified in attributes ExponentSeparator, NANLiteral and INFLiteral of object FormatterStdImpl::AlternativeNumberFormat are used. For upper case types ('G'
and 'E'
), the corresponding attributes in FormatterStdImpl::DefaultNumberFormat apply.'f'
) is not supported to use arbitrary length. See class NumberFormat for the limits. Due to this limitation, the default number of fractional digits is not set with type 'f'
, while in Java it is set to 6
. This is to allow higher numbers up to 1.e13
to be printed in non-scientific formatp>
','
) can also be used with binary, hexadecimal and octal output. The types support different grouping separators for nibbles, bytes, 16-bit and 32-bit words. Changing the separator symbols, is not possible with the format fields of the format strings (if it was, this would become very incompatible to Java standards). Changes have to be made before the format operation by modifying field FormatterStdImpl::AlternativeNumberFormat which is provided through parent class FormatterStdImpl.Alternative form ('#'
) adds prefixes as specified in members
For upper case formats, those are taken from field FormatterStdImpl::DefaultNumberFormat, for lower case formats from FormatterStdImpl::AlternativeNumberFormat. All defaults may be changed by the user.
p>
't'
.'H'
, 'k'
, 'I'
, 'l'
, 'M'
, 'S'
, 'B'
, 'b'
, 'h'
, 'A'
, 'a'
, 'Y'
, 'y'
, 'm'
, 'd'
, 'e'
, 'R'
, 'T'
, 'D'
and 'F'
'L'
, 'N'
, 'p'
, 'z'
, 'Z'
, 's'
, 'Q'
, 'C'
, 'j'
, 'r'
and 'c'
. <b>alib::format::FMTExceptions</b> |
Definition at line 117 of file formatterjavastyle.inl.
Inner Type Index: | |
struct | PlaceholderAttributesJS |
Public Method Index: | |
ALIB_DLL | FormatterJavaStyle () |
virtual ALIB_DLL SPFormatter | Clone () override |
![]() | |
FormatterStdImpl (const String &formatterClassName) | |
![]() | |
Formatter () | |
Default Constructor. | |
virtual | ~Formatter () |
virtual ALIB_DLL void | CloneSettings (Formatter &reference) |
template<typename... TArgs> | |
Formatter & | Format (AString &target, TArgs &&... args) |
Formatter & | FormatArgs (AString &target) |
template<typename TAllocator> | |
Formatter & | FormatArgs (AString &target, const boxing::TBoxes< TAllocator > &args) |
virtual BoxesMA & | GetArgContainer () |
virtual BoxesMA & | Reset () |
![]() | |
DbgCriticalSections (const char *name) | |
~DbgCriticalSections () | |
Destructor. Checks that this instance is unused. | |
ALIB_DLL void | Acquire (const CallerInfo &ci) const |
ALIB_DLL void | AcquireShared (const CallerInfo &ci) const |
ALIB_DLL void | doAssert (bool cond, const CallerInfo &ciAssert, const CallerInfo &ci, const char *headline) const |
ALIB_DLL void | Release (const CallerInfo &ci) const |
ALIB_DLL void | ReleaseShared (const CallerInfo &ci) const |
void | yieldOrSleep () const |
Protected Field Index: | |
PlaceholderAttributesJS | placeholderJS |
The extended placeholder attributes. | |
![]() | |
int | argOffset |
The offset of the first argument to use. Provided with method Format. | |
int | argsConsumed |
The number of arguments consumed by the current format string. | |
bool | argumentCountStartsWith1 |
const BoxesMA * | arguments |
The list of arguments provided with method Format. | |
AString | fieldBuffer |
A string buffer, used for example, when writing aligned fields. | |
String | formatString |
The format string as provided with method Format. | |
const String | formatterName |
int | nextAutoIdx |
Counter for auto-indexed arguments. | |
Substring | parser |
The current (remaining) format string. | |
PlaceholderAttributes | placeholder |
AString * | targetString |
The target string as provided with method Format. | |
integer | targetStringStartLength |
The length of the target string before adding the formatted contents. | |
![]() | |
MonoAllocator | allocator |
This allocator is (exclusively) used for field boxes. | |
BoxesMA | boxes |
AString | formatStringBuffer |
A buffer used for conversion of the next argument if it is not of a string-type. | |
Protected Method Index: | |
virtual ALIB_DLL bool | checkStdFieldAgainstArgument () override |
virtual ALIB_DLL integer | findPlaceholder () override |
virtual ALIB_DLL bool | parsePlaceholder () override |
virtual bool | parseStdFormatSpec () override |
virtual ALIB_DLL bool | preAndPostProcess (integer startIdx, AString *target) override |
virtual ALIB_DLL void | resetPlaceholder () override |
virtual ALIB_DLL void | writeStringPortion (integer length) override |
![]() | |
virtual ALIB_DLL int | format (AString &targetString, const String &formatString, const BoxesMA &arguments, int argOffset) override |
virtual bool | setArgument (int pos) |
virtual bool | writeCustomFormat () |
virtual void | writeStdArgument () |
![]() | |
template<typename TAllocator> | |
Formatter & | formatLoop (AString &target, const boxing::TBoxes< TAllocator > &args) |
virtual void | initializeFormat () |
Additional Inherited Members | |
![]() | |
enum class | PHTypes { NotGiven , String , Character , IntBase10 , IntBinary , IntOctal , IntHex , Float , Bool , HashCode , Fill } |
Denotes the type of placeholders (respectively the values they represent). More... | |
![]() | |
static ALIB_DLL SPFormatter | Default |
static ALIB_DLL threads::RecursiveLock | DefaultLock |
![]() | |
static ALIB_DLL const char * | ASSERTION_FORMAT |
![]() | |
NumberFormat | AlternativeNumberFormat |
NumberFormat | DefaultNumberFormat |
SharedPtr< Formatter > | Next |
![]() | |
CallerInfo | DCSAcq |
Source location of acquirement. | |
AssociatedLock * | DCSLock {nullptr} |
const char * | DCSName |
The name of this DCS. Used for debug-output. | |
std::atomic< int > | DCSReaderCnt {0} |
Tracks enter/exit calls of readers. | |
CallerInfo | DCSRel |
Source location of the last "reader" seen. | |
CallerInfo | DCSSAcq |
Source location of acquirement. | |
CallerInfo | DCSSRel |
Source location of the last "reader" seen. | |
std::atomic< int > | DCSWriterCnt {0} |
Tracks enter/exit calls (including readers) | |
int | DCSYieldOrSleepTimeInNS = -1 |
|
protected |
The extended placeholder attributes.
Definition at line 146 of file formatterjavastyle.inl.
alib::format::FormatterJavaStyle::FormatterJavaStyle | ( | ) |
Constructs this formatter. Inherited field DefaultNumberFormat is initialized to meet the formatting defaults of Java.
Definition at line 38 of file formatterjavastyle.cpp.
|
overrideprotectedvirtual |
Makes some attribute adjustments and invokes standard implementation
true
if OK, false
if replacement should be aborted. Reimplemented from alib::format::FormatterStdImpl.
Definition at line 426 of file formatterjavastyle.cpp.
|
overridevirtual |
Clones and returns a copy of this formatter.
If the formatter attached to field Formatter::Next is of type FormatterStdImpl, then that formatter is copied as well.
Implements alib::format::Formatter.
Definition at line 61 of file formatterjavastyle.cpp.
|
overrideprotectedvirtual |
Searches for '%'
which is not '%' or 'n'.
Implements alib::format::FormatterStdImpl.
Definition at line 97 of file formatterjavastyle.cpp.
|
overrideprotectedvirtual |
Parses placeholder field in Java syntax. The portion format_spec is not set as this is not supported by the syntax.
true
on success, false
on errors. Implements alib::format::FormatterStdImpl.
Definition at line 168 of file formatterjavastyle.cpp.
|
inlineoverrideprotectedvirtual |
Does nothing. Java does not support custom format specifications.
true
to indicate success. Implements alib::format::FormatterStdImpl.
Definition at line 208 of file formatterjavastyle.inl.
|
overrideprotectedvirtual |
All that this formatter does with this overridden method is to convert strings to upper case.
startIdx | The index of the start of the field written in targetString. -1 indicates pre-phase. |
target | The target string, only if different from field targetString, which indicates intermediate phase. |
false
, if the placeholder should be skipped (nothing is written for it). true
otherwise. Reimplemented from alib::format::FormatterStdImpl.
Definition at line 418 of file formatterjavastyle.cpp.
|
overrideprotectedvirtual |
Invokes parent implementation and then applies some changes to reflect what is defined as default in the Java string format specification.
Reimplemented from alib::format::FormatterStdImpl.
Definition at line 78 of file formatterjavastyle.cpp.
|
overrideprotectedvirtual |
Implementation of abstract method FormatterStdImpl::writeStringPortion.
Replaces "%%"
with '%'
and "%n"
with ascii 0x0a
. In addition applies Escape on target which replaces standard codes like "\\n"
, "\\r"
or "\\t"
with corresponding ascii codes. (The latter is an extension to the standard behavior of Java formatter.)
length | The number of characters to write. |
Implements alib::format::FormatterStdImpl.
Definition at line 111 of file formatterjavastyle.cpp.