"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSTL/Src/String/LSTLStringListBase.h

00001 
00016 #ifndef __LSTL_STRINGLISTBASE_H__
00017 #define __LSTL_STRINGLISTBASE_H__
00018 
00019 #include "../LSTLib.h"
00020 #include "../Vector/LSTLVector.h"
00021 
00022 namespace lstl {
00023 
00030         template <typename _tStringType>
00031         class CStringListBase : public CVector<_tStringType, LSUINT32, 32UL> {
00032         public :
00033                 // == Various constructors.
00034                 LSE_CALL                                                                                                                        CStringListBase() {
00035                 }
00036 
00037 
00038                 // == Functions.
00049                 LSBOOL LSE_CALL                                                                                                         MakeFromUtf8( const char * _pcText, LSUINT32 _ui32Len,
00050                         LSBOOL _bKeepNewLines = false ) {
00051                         if ( !this->Push( _tStringType() ) ) { return false; }
00052 
00053                         LSUINT32 ui32Size = 0UL;
00054                         LSUINT32 ui32Char = CStd::NextUtf8Char( reinterpret_cast<const LSUTF8 *>(_pcText), _ui32Len, &ui32Size );
00055                         while ( _ui32Len ) {
00056                                 if ( _bKeepNewLines || (ui32Char != '\r' && ui32Char != '\n') ) {
00057                                         // Either we are keeping new lines or this is not a new-line character.
00058                                         // Add the characters that make up this UTF-8 code.
00059                                         for ( LSUINT32 I = 0UL; I < ui32Size; ++I ) {
00060                                                 if ( !(*this)[Parent::Length()-1UL].Append( (*_pcText++) ) ) {
00061                                                         return false;
00062                                                 }
00063                                         }
00064                                 }
00065                                 else {
00066                                         // Discarding new-line characters.
00067                                         _pcText += ui32Size;
00068                                 }
00069                                 if ( ui32Char == '\n' ) {
00070                                         if ( !this->Push( _tStringType() ) ) { return false; }
00071                                 }
00072 
00073                                 _ui32Len -= ui32Size;
00074                                 ui32Char = CStd::NextUtf8Char( reinterpret_cast<const LSUTF8 *>(_pcText), _ui32Len, &ui32Size );
00075                         }
00076 
00077                         return true;
00078                 }
00079 
00090                 _tStringType LSE_CALL                                                                                           ToString( LSBOOL _bAddNewLines ) {
00091                         _tStringType tRet;
00092 
00093                         for ( LSUINT32 I = 0UL; I < Parent::Length(); ++I ) {
00094                                 if ( !tRet.Append( (*this)[I].CStr(), (*this)[I].Length() ) ) {
00095                                         tRet.Reset();
00096                                         return tRet;
00097                                 }
00098                                 if ( _bAddNewLines ) {
00099                                         if ( !tRet.Append( '\r' ) ) {
00100                                                 tRet.Reset();
00101                                                 return tRet;
00102                                         }
00103                                         if ( !tRet.Append( '\n' ) ) {
00104                                                 tRet.Reset();
00105                                                 return tRet;
00106                                         }
00107                                 }
00108                         }
00109                         return tRet;
00110                 }
00111                 
00122                  template <typename _tCharType>
00123                  LSBOOL LSE_CALL                                                                                                        MakeByTokenizing( const _tCharType * _ptString,
00124                         LSUINT32 _ui32Length, _tCharType _tTokenizer ) {
00125                         if ( !_ptString ) { return false; }
00126                         
00127                         // The string holding the temporary result.
00128                         _tStringType tTempString;
00129                         for ( LSUINT32 I = 0UL; I < _ui32Length; ++I ) {
00130                                 if ( _ptString[I] == _tTokenizer ) {    // It is the tokenizer.
00131                                         if ( !Parent::Push( tTempString ) ) { return false; }
00132                                         tTempString.ResetNoDealloc();
00133                                 }
00134                                 else {                                                                  // Any other character.
00135                                         if ( !tTempString.Append( _ptString[I] ) ) { return false; }
00136                                 }
00137                         }
00138                         if ( tTempString.Length() ) {
00139                                 if ( !Parent::Push( tTempString ) ) { return false; }
00140                         }
00141                         return true;
00142                 }
00143 
00144 
00145         protected :
00146                 // == Members.
00147                 
00148         private :
00149                 typedef CVector<_tStringType, LSUINT32, 32UL>                                           Parent;
00150         };
00151 
00152 }       // namespace lstl
00153 
00154 #endif  // __LSTL_STRINGLISTBASE_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator