00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00036 #ifndef _CTTL_XTL_CONTAINER_IMPL_H_INCLUDED_
00037 #define _CTTL_XTL_CONTAINER_IMPL_H_INCLUDED_
00038
00039 #include "coreutils.h"
00040 #include "xtl_bitflags.h"
00041 #include <vector>
00042
00043 namespace cttl_impl {
00044
00046 const int xtl_identity_vector_default_size = 0;
00047
00057 template< typename StringT = CTTL_STD_STRING >
00058 class xtl_text_container_impl
00059 {
00060 protected:
00062 typedef StringT string_T;
00063
00065 typedef typename string_T::value_type char_T;
00066
00068 StringT m_client_str;
00069
00071 std::vector< size_t > m_offset_stack;
00072
00074 std::vector< size_t > m_identity_vector;
00075
00077
00079 protected:
00085 explicit xtl_text_container_impl( size_t vector_size_ )
00086 :
00087 m_identity_vector( vector_size_ )
00088 {
00089 identity_zero_all();
00090 }
00091
00093 explicit xtl_text_container_impl(
00094 char_T const* pchar_,
00095 size_t vector_size_
00096 )
00097 :
00098 m_identity_vector( vector_size_ )
00099 {
00100 identity_zero_all();
00101
00102 if ( pchar_ )
00103 m_client_str = pchar_;
00104 }
00105
00107 explicit xtl_text_container_impl(
00108 StringT const& str_,
00109 size_t vector_size_
00110 )
00111 :
00112 m_client_str( str_ ),
00113 m_identity_vector( vector_size_ )
00114 {
00115 identity_zero_all();
00116 }
00117
00118 protected:
00120 void identity_zero_all()
00121 {
00122 for ( size_t i = 0; i < m_identity_vector.size(); ++i )
00123 m_identity_vector[ i ] = 0;
00124 }
00125
00127
00129 protected:
00130
00146 size_t line_2_offset( int line_ ) const
00147 {
00148 size_t offset = 0;
00149 while ( --line_ ) {
00150 offset = m_client_str.find( char_T( '\n' ), offset );
00151 if ( offset == StringT::npos )
00152 return m_client_str.length();
00153 ++offset;
00154 }
00155 return offset;
00156 }
00157
00164 size_t offset_2_line( size_t offset_ ) const
00165 {
00166 if ( !m_client_str.length() )
00167 return 1;
00168 return 1 + std::count( m_client_str.begin(), m_client_str.begin() + offset_, char_T( '\n' ) );
00169 }
00170
00177 size_t offset_2_next_line_offset( size_t offset_ ) const
00178 {
00179 offset_ = m_client_str.find( char_T( '\n' ), offset_ );
00180 if ( offset_ == StringT::npos )
00181 return m_client_str.length();
00182
00183 return ++offset_;
00184 }
00185
00197 size_t offset_2_line_home_offset( size_t offset_ ) const
00198 {
00199 if ( m_client_str[ offset_ ] == char_T( '\n' ) )
00200 return offset_;
00201
00202 offset_ = m_client_str.rfind( char_T( '\n' ), offset_ );
00203 if ( offset_ == StringT::npos )
00204 return 0;
00205
00206 return ++offset_;
00207 }
00208
00220 size_t offset_2_line_end_offset( size_t offset_ ) const
00221 {
00222 static const char_T end_of_line[] = { '\r', '\n', 0x00 };
00223 offset_ = m_client_str.find_first_of( end_of_line, offset_ );
00224 if ( offset_ == StringT::npos )
00225 return m_client_str.length();
00226
00227 return offset_;
00228 }
00229
00230 };
00231
00232 }
00233
00234 #endif // _CTTL_XTL_CONTAINER_IMPL_H_INCLUDED_
00235
00236