LibreOffice Module unotools (master) 1
|
Iterator to be used with a digit grouping as obtained through LocaleDataWrapper::getDigitGrouping(). More...
#include <digitgroupingiterator.hxx>
Public Member Functions | |
DigitGroupingIterator (const css::uno::Sequence< sal_Int32 > &rGroupings) | |
DigitGroupingIterator & | advance () |
Advance iterator to next grouping. More... | |
sal_Int32 | get () const |
Obtain current grouping. More... | |
sal_Int32 | getPos () const |
The next position (in integer digits) from the right where to insert a group separator. More... | |
void | reset () |
Reset iterator to start again from the right beginning. More... | |
Static Public Member Functions | |
static css::uno::Sequence< sal_Bool > | createForwardSequence (sal_Int32 nIntegerDigits, const css::uno::Sequence< sal_Int32 > &rGroupings) |
Create a sequence of bool values containing positions where to add a separator when iterating forward over a string and copying digit per digit. More... | |
Private Member Functions | |
void | setInfinite () |
bool | isInfinite () const |
sal_Int32 | getGrouping () const |
void | setPos () |
void | setDigits () |
void | initGrouping () |
DigitGroupingIterator (const DigitGroupingIterator &)=delete | |
DigitGroupingIterator & | operator= (const DigitGroupingIterator &)=delete |
Private Attributes | |
const css::uno::Sequence< sal_Int32 > | maGroupings |
sal_Int32 | mnGroup |
sal_Int32 | mnDigits |
sal_Int32 | mnNextPos |
Iterator to be used with a digit grouping as obtained through LocaleDataWrapper::getDigitGrouping().
The iterator advances over the digit groupings, returning the number of digits per group. If the last group was encountered the iterator will always return the last grouping.
Grouping values are sanitized to be >= 0, even if originally signed sal_Int32.
Usage example with a string buffer containing a decimal representation of an integer number. Note that of course this loop could be optimized to not count single characters but hunks of groups instead using the get() method, this is just for illustrating usage. Anyway, for double values it is highly more efficient to use ::rtl::math::doubleToString() and pass the grouping sequence, instead of using this iterator and inserting characters into strings.
DigitGroupingIterator aGrouping(...) sal_Int32 nCount = 0; sal_Int32 n = aBuffer.getLength(); >1 because we don't want to insert a separator if there is no leading digit. while (n– > 1) { if (++nCount >= aGrouping.getPos()) { aBuffer.insert( n, cSeparator); nGroupDigits = aGrouping.advance(); } }
Definition at line 61 of file digitgroupingiterator.hxx.
|
privatedelete |
|
inlineexplicit |
Definition at line 124 of file digitgroupingiterator.hxx.
References initGrouping().
|
inline |
Advance iterator to next grouping.
Definition at line 131 of file digitgroupingiterator.hxx.
References isInfinite(), mnGroup, setDigits(), and setPos().
Referenced by createForwardSequence().
|
inlinestatic |
Create a sequence of bool values containing positions where to add a separator when iterating forward over a string and copying digit per digit.
For example, for grouping in thousands and nIntegerDigits==7 the sequence returned would be {1,0,0,1,0,0,0} so the caller would add a separator after the 1st and the 4th digit.
Definition at line 167 of file digitgroupingiterator.hxx.
References advance(), aSeq, and getPos().
Referenced by LocaleDataWrapper::ImplAddFormatNum().
|
inline |
Obtain current grouping.
Always > 0.
Definition at line 144 of file digitgroupingiterator.hxx.
References mnDigits.
|
inlineprivate |
Definition at line 79 of file digitgroupingiterator.hxx.
References maGroupings, mnGroup, n, and SAL_WARN_IF.
Referenced by setDigits().
|
inline |
The next position (in integer digits) from the right where to insert a group separator.
Definition at line 151 of file digitgroupingiterator.hxx.
References mnNextPos.
Referenced by createForwardSequence().
|
inlineprivate |
Definition at line 111 of file digitgroupingiterator.hxx.
References mnDigits, mnGroup, mnNextPos, and setDigits().
Referenced by DigitGroupingIterator(), and reset().
|
inlineprivate |
Definition at line 74 of file digitgroupingiterator.hxx.
References maGroupings, and mnGroup.
Referenced by advance().
|
privatedelete |
|
inline |
Reset iterator to start again from the right beginning.
Definition at line 157 of file digitgroupingiterator.hxx.
References initGrouping().
|
inlineprivate |
Definition at line 99 of file digitgroupingiterator.hxx.
References getGrouping(), mnDigits, setInfinite(), and setPos().
Referenced by advance(), and initGrouping().
|
inlineprivate |
Definition at line 69 of file digitgroupingiterator.hxx.
References maGroupings, and mnGroup.
Referenced by setDigits().
|
inlineprivate |
Definition at line 92 of file digitgroupingiterator.hxx.
References mnDigits, mnNextPos, and SAL_MAX_INT32.
Referenced by advance(), and setDigits().
|
private |
Definition at line 63 of file digitgroupingiterator.hxx.
Referenced by getGrouping(), isInfinite(), and setInfinite().
|
private |
Definition at line 66 of file digitgroupingiterator.hxx.
Referenced by get(), initGrouping(), setDigits(), and setPos().
|
private |
Definition at line 65 of file digitgroupingiterator.hxx.
Referenced by advance(), getGrouping(), initGrouping(), isInfinite(), and setInfinite().
|
private |
Definition at line 67 of file digitgroupingiterator.hxx.
Referenced by getPos(), initGrouping(), and setPos().