LibreOffice Module unotools (master) 1
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
utl::DigitGroupingIterator Class Reference

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)
 
DigitGroupingIteratoradvance ()
 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_BoolcreateForwardSequence (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
 
DigitGroupingIteratoroperator= (const DigitGroupingIterator &)=delete
 

Private Attributes

const css::uno::Sequence< sal_Int32 > maGroupings
 
sal_Int32 mnGroup
 
sal_Int32 mnDigits
 
sal_Int32 mnNextPos
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ DigitGroupingIterator() [1/2]

utl::DigitGroupingIterator::DigitGroupingIterator ( const DigitGroupingIterator )
privatedelete

◆ DigitGroupingIterator() [2/2]

utl::DigitGroupingIterator::DigitGroupingIterator ( const css::uno::Sequence< sal_Int32 > &  rGroupings)
inlineexplicit

Definition at line 124 of file digitgroupingiterator.hxx.

References initGrouping().

Member Function Documentation

◆ advance()

DigitGroupingIterator & utl::DigitGroupingIterator::advance ( )
inline

Advance iterator to next grouping.

Definition at line 131 of file digitgroupingiterator.hxx.

References isInfinite(), mnGroup, setDigits(), and setPos().

Referenced by createForwardSequence().

◆ createForwardSequence()

static css::uno::Sequence< sal_Bool > utl::DigitGroupingIterator::createForwardSequence ( sal_Int32  nIntegerDigits,
const css::uno::Sequence< sal_Int32 > &  rGroupings 
)
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().

◆ get()

sal_Int32 utl::DigitGroupingIterator::get ( ) const
inline

Obtain current grouping.

Always > 0.

Definition at line 144 of file digitgroupingiterator.hxx.

References mnDigits.

◆ getGrouping()

sal_Int32 utl::DigitGroupingIterator::getGrouping ( ) const
inlineprivate

Definition at line 79 of file digitgroupingiterator.hxx.

References maGroupings, mnGroup, n, and SAL_WARN_IF.

Referenced by setDigits().

◆ getPos()

sal_Int32 utl::DigitGroupingIterator::getPos ( ) const
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().

◆ initGrouping()

void utl::DigitGroupingIterator::initGrouping ( )
inlineprivate

Definition at line 111 of file digitgroupingiterator.hxx.

References mnDigits, mnGroup, mnNextPos, and setDigits().

Referenced by DigitGroupingIterator(), and reset().

◆ isInfinite()

bool utl::DigitGroupingIterator::isInfinite ( ) const
inlineprivate

Definition at line 74 of file digitgroupingiterator.hxx.

References maGroupings, and mnGroup.

Referenced by advance().

◆ operator=()

DigitGroupingIterator & utl::DigitGroupingIterator::operator= ( const DigitGroupingIterator )
privatedelete

◆ reset()

void utl::DigitGroupingIterator::reset ( )
inline

Reset iterator to start again from the right beginning.

Definition at line 157 of file digitgroupingiterator.hxx.

References initGrouping().

◆ setDigits()

void utl::DigitGroupingIterator::setDigits ( )
inlineprivate

Definition at line 99 of file digitgroupingiterator.hxx.

References getGrouping(), mnDigits, setInfinite(), and setPos().

Referenced by advance(), and initGrouping().

◆ setInfinite()

void utl::DigitGroupingIterator::setInfinite ( )
inlineprivate

Definition at line 69 of file digitgroupingiterator.hxx.

References maGroupings, and mnGroup.

Referenced by setDigits().

◆ setPos()

void utl::DigitGroupingIterator::setPos ( )
inlineprivate

Definition at line 92 of file digitgroupingiterator.hxx.

References mnDigits, mnNextPos, and SAL_MAX_INT32.

Referenced by advance(), and setDigits().

Member Data Documentation

◆ maGroupings

const css::uno::Sequence< sal_Int32 > utl::DigitGroupingIterator::maGroupings
private

Definition at line 63 of file digitgroupingiterator.hxx.

Referenced by getGrouping(), isInfinite(), and setInfinite().

◆ mnDigits

sal_Int32 utl::DigitGroupingIterator::mnDigits
private

Definition at line 66 of file digitgroupingiterator.hxx.

Referenced by get(), initGrouping(), setDigits(), and setPos().

◆ mnGroup

sal_Int32 utl::DigitGroupingIterator::mnGroup
private

Definition at line 65 of file digitgroupingiterator.hxx.

Referenced by advance(), getGrouping(), initGrouping(), isInfinite(), and setInfinite().

◆ mnNextPos

sal_Int32 utl::DigitGroupingIterator::mnNextPos
private

Definition at line 67 of file digitgroupingiterator.hxx.

Referenced by getPos(), initGrouping(), and setPos().


The documentation for this class was generated from the following file: