|
From: <bl...@us...> - 2003-04-26 21:10:32
|
Update of /cvsroot/cpptool/rfta/include/xtl
In directory sc8-pr-cvs1:/tmp/cvs-serv9038/include/xtl
Modified Files:
CStringView.h
Log Message:
* changed the BackEnumerator to use the iterator_helper instead of the reverse iterator (incorrect type were returned by the implementation)
Index: CStringView.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/include/xtl/CStringView.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CStringView.h 26 Apr 2003 13:13:36 -0000 1.2
--- CStringView.h 26 Apr 2003 21:10:27 -0000 1.3
***************
*** 18,21 ****
--- 18,25 ----
{
public:
+ enum {
+ unlimited = 0x7ffffff
+ };
+
CStringView()
: start_( 0 )
***************
*** 32,35 ****
--- 36,59 ----
}
+ CStringView( const CStringEnumerator &enumerator );
+
+ CStringView( const CStringBackEnumerator &enumerator );
+
+ void setStart( const char *start )
+ {
+ if ( start >= end_ )
+ start_ = start;
+ else
+ start_ = end_;
+ }
+
+ void setEnd( const char *end )
+ {
+ if ( end >= start_ )
+ end_ = end;
+ else
+ end_ = start_;
+ }
+
CStringView getSlice( int startIndex,
int endIndex = -1 ) const
***************
*** 48,51 ****
--- 72,90 ----
}
+ CStringView getSubString( int startIndex,
+ int length = unlimited )
+ {
+ if ( startIndex < 0 )
+ startIndex = 0;
+ else if ( startIndex > getLength() )
+ return CStringView();
+
+ if ( length == unlimited
+ || startIndex + length > getLength() )
+ length = getLength() - startIndex;
+
+ return CStringView( start_, start_ + length );
+ }
+
CStringEnumerator enumerate() const;
***************
*** 92,96 ****
bool operator ==( const std::string &other ) const
{
! return (start_ && other == std::string( start_, getLength() ) ) ||
other.empty();
}
--- 131,135 ----
bool operator ==( const std::string &other ) const
{
! return (start_ && other == str() ) ||
other.empty();
}
***************
*** 101,104 ****
--- 140,148 ----
}
+ const std::string str() const
+ {
+ return std::string( start_, getLength() );
+ }
+
private:
const char *start_;
***************
*** 107,114 ****
! class CStringEnumerator : public boost::random_access_iterator_helper<CStringEnumerator
, char
, std::ptrdiff_t
--- 151,213 ----
+ class CStringEnumeratorBase
+ {
+ public:
+ typedef char Reference;
+ typedef std::ptrdiff_t Distance;
+ CStringEnumeratorBase()
+ : current_( 0 )
+ {
+ }
+
+ CStringEnumeratorBase( const CStringView &string,
+ const char *current )
+ : string_( string )
+ , current_( current )
+ {
+ }
+ const char *getCurrentPos() const
+ {
+ return current_;
+ }
! int getCurrentIndex() const
! {
! return current_ - string_.getStart();
! }
!
! const CStringView &getString() const
! {
! return string_;
! }
!
! bool operator ==( const CStringEnumeratorBase &other ) const
! {
! return current_ == other.current_;
! }
!
! bool operator <( const CStringEnumeratorBase &other ) const
! {
! return current_ < other.current_;
! }
!
! bool withinString() const
! {
! return current_ >= string_.getStart() && current_ < string_.getEnd();
! }
!
! protected:
! CStringView string_;
! const char *current_;
! };
!
!
!
!
!
! class CStringEnumerator : public CStringEnumeratorBase
! , public boost::random_access_iterator_helper<CStringEnumerator
, char
, std::ptrdiff_t
***************
*** 118,127 ****
public:
typedef CStringEnumerator self;
- typedef char Reference;
- typedef std::ptrdiff_t Distance;
-
CStringEnumerator()
- : current_( 0 )
{
}
--- 217,222 ----
***************
*** 129,143 ****
CStringEnumerator( const char *current,
const char *end )
! : string_( current, end )
! , current_( string_.isEmpty() ? 0 : current )
{
}
CStringEnumerator( const CStringView &string )
! : string_( string )
! , current_( string_.getStart() )
{
}
char operator*() const
{
--- 224,239 ----
CStringEnumerator( const char *current,
const char *end )
! : CStringEnumeratorBase( CStringView( current, end ),
! string_.isEmpty() ? 0 : current )
{
}
CStringEnumerator( const CStringView &string )
! : CStringEnumeratorBase( string, string.getStart() )
{
}
+ CStringEnumerator( const CStringBackEnumerator &other );
+
char operator*() const
{
***************
*** 171,184 ****
}
- bool operator ==( const self &other ) const
- {
- return current_ == other.current_;
- }
-
- bool operator <( const self &other ) const
- {
- return current_ < other.current_;
- }
-
bool hasPrevious() const
{
--- 267,270 ----
***************
*** 190,212 ****
return current_ < string_.getEnd();
}
-
- const char *getCurrentPos() const
- {
- return current_;
- }
-
- const CStringView &getString() const
- {
- return string_;
- }
-
- private:
- CStringView string_;
- const char *current_;
};
! inline CStringEnumerator::Distance
! operator -( const CStringEnumerator &x, const CStringEnumerator &y )
{
return x.getCurrentPos() - y.getCurrentPos();
--- 276,284 ----
return current_ < string_.getEnd();
}
};
! inline CStringEnumeratorBase::Distance
! operator -( const CStringEnumeratorBase &x, const CStringEnumeratorBase &y )
{
return x.getCurrentPos() - y.getCurrentPos();
***************
*** 216,224 ****
! class CStringBackEnumerator : public std::reverse_iterator<CStringEnumerator, char, char>
{
- private:
- typedef std::reverse_iterator<CStringEnumerator, char, char> SuperClass;
public:
CStringBackEnumerator()
{
--- 288,301 ----
! class CStringBackEnumerator : public CStringEnumeratorBase
! , public boost::random_access_iterator_helper<CStringBackEnumerator
! , char
! , std::ptrdiff_t
! , const char *
! , char>
{
public:
+ typedef CStringBackEnumerator self;
+
CStringBackEnumerator()
{
***************
*** 226,256 ****
CStringBackEnumerator( const CStringEnumerator &other )
! : SuperClass( other )
{
}
! char getNext()
{
! return *(*this)++;
}
! bool hasPrevious() const
{
! return current.hasNext();
}
! bool hasNext() const
{
! return current.hasPrevious();
}
! const char *getCurrentPos() const
{
! return current.getCurrentPos();
}
! const CStringView &getString() const
{
! return current.getString();
}
};
--- 303,349 ----
CStringBackEnumerator( const CStringEnumerator &other )
! : CStringEnumeratorBase( other.getString(), other.getCurrentPos() )
{
}
! char operator*() const
{
! if ( current_ > string_.getStart() )
! return current_[-1];
! return 0;
}
! self &operator ++()
{
! --current_;
! return *this;
}
! self &operator --()
{
! ++current_;
! return *this;
}
! self &operator +=( Distance n )
{
! current_ -= n;
! return *this;
}
! self &operator -=( Distance n )
{
! current_ += n;
! return *this;
! }
!
! bool hasNext() const
! {
! return current_ > string_.getStart();
! }
!
! bool hasPrevious() const
! {
! return current_ < string_.getEnd();
}
};
***************
*** 272,275 ****
--- 365,383 ----
+ inline CStringView::CStringView( const CStringEnumerator &enumerator )
+ : start_( enumerator.getCurrentPos() )
+ , end_( enumerator.getString().end_ )
+ {
+
+ }
+
+
+ inline CStringView::CStringView( const CStringBackEnumerator &enumerator )
+ : start_( enumerator.getString().start_ )
+ , end_( enumerator.getCurrentPos() )
+ {
+ }
+
+
inline CStringEnumerator
CStringView::enumerate() const
***************
*** 302,305 ****
--- 410,419 ----
{
return CStringBackEnumerator( enumerate( startIndex, endIndex ) );
+ }
+
+
+ inline CStringEnumerator::CStringEnumerator( const CStringBackEnumerator &other )
+ : CStringEnumeratorBase( other.getString(), other.getCurrentPos() )
+ {
}
|