diff options
author | Mike FABIAN <mike.fabian@basyskom.de> | 2010-07-14 22:56:36 +0300 |
---|---|---|
committer | Mike FABIAN <mike.fabian@basyskom.de> | 2010-07-15 14:16:09 +0300 |
commit | 5cb7be8e294c89b645c9515fecc711e517450f90 (patch) | |
tree | ef197cee112ed1221d2cd84dc9a318920cfadb4f | |
parent | 0677c615ad502448ce080965c2da6559324af543 (diff) |
Changes: add index() method to MBreakIterator
RevBy: John Tapsell
-rw-r--r-- | src/corelib/i18n/mbreakiterator.cpp | 38 | ||||
-rw-r--r-- | src/corelib/i18n/mbreakiterator.h | 1 | ||||
-rw-r--r-- | src/corelib/i18n/mbreakiteratorif.h | 1 | ||||
-rw-r--r-- | src/corelib/i18n/micubreakiterator.cpp | 7 | ||||
-rw-r--r-- | src/corelib/i18n/micubreakiterator.h | 1 | ||||
-rw-r--r-- | src/corelib/i18n/mnullbreakiterator.cpp | 50 | ||||
-rw-r--r-- | src/corelib/i18n/mnullbreakiterator.h | 1 |
7 files changed, 22 insertions, 77 deletions
diff --git a/src/corelib/i18n/mbreakiterator.cpp b/src/corelib/i18n/mbreakiterator.cpp index c1e4175c..cedbce71 100644 --- a/src/corelib/i18n/mbreakiterator.cpp +++ b/src/corelib/i18n/mbreakiterator.cpp @@ -40,7 +40,6 @@ public: MBreakIteratorIf *impl; }; - MBreakIteratorPrivate::MBreakIteratorPrivate() : impl(0) { @@ -53,7 +52,6 @@ MBreakIteratorPrivate::~MBreakIteratorPrivate() delete impl; } - void MBreakIteratorPrivate::init(const MLocale &locale, const QString &text, MBreakIterator::Type type) { @@ -68,7 +66,6 @@ void MBreakIteratorPrivate::init(const MLocale &locale, const QString &text, #endif } - /////////////////////////////////// @@ -114,7 +111,6 @@ MBreakIterator::MBreakIterator(const MLocale &locale, const QString &text, Type d->init(locale, text, type); } - ///! Creates a MBreakIterator using default locale MBreakIterator::MBreakIterator(const QString &text, Type type) : d_ptr(new MBreakIteratorPrivate) @@ -124,86 +120,69 @@ MBreakIterator::MBreakIterator(const QString &text, Type type) d->init(locale, text, type); } - //! Destructor MBreakIterator::~MBreakIterator() { delete d_ptr; } - //! returns true if a boundary exists after current index bool MBreakIterator::hasNext() const { Q_D(const MBreakIterator); - return d->impl->hasNext(); } - //! returns true if boundary exists before current index bool MBreakIterator::hasPrevious() const { Q_D(const MBreakIterator); - return d->impl->hasPrevious(); } - //! returns the next boundary index after the current index or -1 if none exists. //! current index is updated to the resulting value. int MBreakIterator::next() { Q_D(const MBreakIterator); - return d->impl->next(); } - //! returns the next boundary after the given index. Returns the boundary or -1 //! if none exists. Updates the current index to the resulting value. int MBreakIterator::next(int index) { Q_D(const MBreakIterator); - return d->impl->next(index); } - //! returns the next boundary index value. The current index is not updated. int MBreakIterator::peekNext() { Q_D(const MBreakIterator); - return d->impl->peekNext(); } - //! returns the previous boundary index value. The current index is not updated. int MBreakIterator::peekPrevious() { Q_D(const MBreakIterator); - return d->impl->peekPrevious(); } - //! returns the previous boundary index or -1 if none exists. //! The current index is updated to the resulting value. int MBreakIterator::previous() { Q_D(const MBreakIterator); - return d->impl->previous(); } - //! returns the previous boundary from the given index value or -1 if none exists. //! The current index is updated to the resulting value. int MBreakIterator::previous(int index) { Q_D(const MBreakIterator); - return d->impl->previous(index); } @@ -214,7 +193,6 @@ int MBreakIterator::previous(int index) int MBreakIterator::previousInclusive() { Q_D(const MBreakIterator); - return d->impl->previousInclusive(); } @@ -224,51 +202,47 @@ int MBreakIterator::previousInclusive() int MBreakIterator::previousInclusive(int index) { Q_D(const MBreakIterator); - return d->impl->previousInclusive(index); } +//! returns the current index +int MBreakIterator::index() const +{ + Q_D(const MBreakIterator); + return d->impl->index(); +} //! Sets the current index to the given value void MBreakIterator::setIndex(int index) { Q_D(MBreakIterator); - d->impl->setIndex(index); } - //! Sets the current index to the end of the string void MBreakIterator::toBack() { Q_D(MBreakIterator); - d->impl->toBack(); } - //! Sets the current index to the beginning of the string void MBreakIterator::toFront() { Q_D(MBreakIterator); - d->impl->toFront(); } - //! Checks if current index is a boundary. bool MBreakIterator::isBoundary() { Q_D(MBreakIterator); - return d->impl->isBoundary(); } - //! Checks if given index is a boundary. bool MBreakIterator::isBoundary(int index) { Q_D(MBreakIterator); - return d->impl->isBoundary(index); } diff --git a/src/corelib/i18n/mbreakiterator.h b/src/corelib/i18n/mbreakiterator.h index d085f05e..b00e7984 100644 --- a/src/corelib/i18n/mbreakiterator.h +++ b/src/corelib/i18n/mbreakiterator.h @@ -49,6 +49,7 @@ public: int previousInclusive(int index); void toBack(); void toFront(); + int index() const; void setIndex(int index); bool isBoundary(); bool isBoundary(int index); diff --git a/src/corelib/i18n/mbreakiteratorif.h b/src/corelib/i18n/mbreakiteratorif.h index aa501f10..b10781d0 100644 --- a/src/corelib/i18n/mbreakiteratorif.h +++ b/src/corelib/i18n/mbreakiteratorif.h @@ -49,6 +49,7 @@ public: virtual int previousInclusive(int index) = 0; virtual void toBack() = 0; virtual void toFront() = 0; + virtual int index() const = 0; virtual void setIndex(int index) = 0; virtual bool isBoundary() = 0; virtual bool isBoundary(int index) = 0; diff --git a/src/corelib/i18n/micubreakiterator.cpp b/src/corelib/i18n/micubreakiterator.cpp index 6a706cb8..f9cb8af3 100644 --- a/src/corelib/i18n/micubreakiterator.cpp +++ b/src/corelib/i18n/micubreakiterator.cpp @@ -260,6 +260,13 @@ int MIcuBreakIterator::previousInclusive(int index) } } +//! returns the current index +int MIcuBreakIterator::index() const +{ + Q_D(const MIcuBreakIterator); + return d->current; +} + //! Sets the current index to the given value void MIcuBreakIterator::setIndex(int index) { diff --git a/src/corelib/i18n/micubreakiterator.h b/src/corelib/i18n/micubreakiterator.h index 4cbc12d3..ed273026 100644 --- a/src/corelib/i18n/micubreakiterator.h +++ b/src/corelib/i18n/micubreakiterator.h @@ -53,6 +53,7 @@ public: int previousInclusive(int index); void toBack(); void toFront(); + int index() const; void setIndex(int index); bool isBoundary(); bool isBoundary(int index); diff --git a/src/corelib/i18n/mnullbreakiterator.cpp b/src/corelib/i18n/mnullbreakiterator.cpp index 62791246..24edca07 100644 --- a/src/corelib/i18n/mnullbreakiterator.cpp +++ b/src/corelib/i18n/mnullbreakiterator.cpp @@ -32,19 +32,16 @@ public: QString string; }; - MNullBreakIteratorPrivate::MNullBreakIteratorPrivate() : current(-1) { // nothing } - MNullBreakIteratorPrivate::~MNullBreakIteratorPrivate() { } - MNullBreakIterator::MNullBreakIterator(const MLocale &locale, const QString &text, MBreakIterator::Type type) @@ -56,7 +53,6 @@ MNullBreakIterator::MNullBreakIterator(const MLocale &locale, d->string = text; } - MNullBreakIterator::MNullBreakIterator(const QString &text, MBreakIterator::Type type) : d_ptr(new MNullBreakIteratorPrivate) @@ -66,148 +62,116 @@ MNullBreakIterator::MNullBreakIterator(const QString &text, d->string = text; } - MNullBreakIterator::~MNullBreakIterator() { delete d_ptr; } - bool MNullBreakIterator::hasNext() const { Q_D(const MNullBreakIterator); - int next = d->current + 1; - if (next >= d->string.length()) { return false; } - return true; } - bool MNullBreakIterator::hasPrevious() const { Q_D(const MNullBreakIterator); - int prev = d->current - 1; - if (prev < 0) { return false; } - return true; } - int MNullBreakIterator::next() { Q_D(MNullBreakIterator); - int next = d->current + 1; - if (next >= d->string.length()) { next = -1; toBack(); } else { d->current = next; } - return next; } - int MNullBreakIterator::next(int index) { Q_D(MNullBreakIterator); - int next = index + 1; - if (next >= d->string.length()) { next = -1; toBack(); } else { d->current = next; } - return next; } - int MNullBreakIterator::peekNext() { Q_D(MNullBreakIterator); - int next = d->current + 1; - if (next >= d->string.length()) { next = -1; } - return next; } - int MNullBreakIterator::peekPrevious() { Q_D(MNullBreakIterator); - int previous = d->current - 1; - if (previous < 0) { previous = -1; } - return previous; } - int MNullBreakIterator::previous() { Q_D(MNullBreakIterator); - int previous = d->current - 1; - if (previous < 0) { previous = -1; toFront(); } - d->current = previous; - return previous; } - int MNullBreakIterator::previous(int index) { Q_D(MNullBreakIterator); - int previous = index - 1; - if (previous < 0) { previous = -1; toFront(); } - d->current = previous; - return previous; } - int MNullBreakIterator::previousInclusive() { return previous(); } - int MNullBreakIterator::previousInclusive(int index) { return previous(index); } +int MNullBreakIterator::index() const +{ + Q_D(MNullBreakIterator); + return d->current; +} void MNullBreakIterator::setIndex(int index) { @@ -215,28 +179,24 @@ void MNullBreakIterator::setIndex(int index) d->current = index; } - void MNullBreakIterator::toBack() { Q_D(MNullBreakIterator); d->current = d->string.length(); } - void MNullBreakIterator::toFront() { Q_D(MNullBreakIterator); d->current = -1; } - bool MNullBreakIterator::isBoundary() { Q_D(MNullBreakIterator); return isBoundary(d->current); } - bool MNullBreakIterator::isBoundary(int index) { Q_UNUSED(index); diff --git a/src/corelib/i18n/mnullbreakiterator.h b/src/corelib/i18n/mnullbreakiterator.h index cea91bd6..5eeda39f 100644 --- a/src/corelib/i18n/mnullbreakiterator.h +++ b/src/corelib/i18n/mnullbreakiterator.h @@ -52,6 +52,7 @@ public: int previousInclusive(int index); void toBack(); void toFront(); + int index() const; void setIndex(int index); bool isBoundary(); bool isBoundary(int index); |