diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-05 22:41:51 +0000 |
| commit | ec05778d5718a7912e506764d443a78d6a6179e3 (patch) | |
| tree | 78a9a01532180030c095acefc45763f07c14edb8 /src/stable/string.cpp | |
| parent | b20414ac1fe80a71a90601f4cd1767fa7014a9ba (diff) | |
| download | libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.gz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.bz2 libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.tar.xz libbu++-ec05778d5718a7912e506764d443a78d6a6179e3.zip | |
Converted tabs to spaces with tabconv.
Diffstat (limited to 'src/stable/string.cpp')
| -rw-r--r-- | src/stable/string.cpp | 1778 |
1 files changed, 889 insertions, 889 deletions
diff --git a/src/stable/string.cpp b/src/stable/string.cpp index dd484fd..d073ec6 100644 --- a/src/stable/string.cpp +++ b/src/stable/string.cpp | |||
| @@ -14,117 +14,117 @@ | |||
| 14 | #include "bu/formatter.h" | 14 | #include "bu/formatter.h" |
| 15 | #include <stdlib.h> | 15 | #include <stdlib.h> |
| 16 | 16 | ||
| 17 | #define nMinSize (256) | 17 | #define nMinSize (256) |
| 18 | 18 | ||
| 19 | Bu::StringCore::StringCore() : | 19 | Bu::StringCore::StringCore() : |
| 20 | nLength( 0 ), | 20 | nLength( 0 ), |
| 21 | pFirst( NULL ), | 21 | pFirst( NULL ), |
| 22 | pLast( NULL ) | 22 | pLast( NULL ) |
| 23 | { | 23 | { |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | Bu::StringCore::StringCore( const StringCore &rSrc ) : | 26 | Bu::StringCore::StringCore( const StringCore &rSrc ) : |
| 27 | nLength( rSrc.nLength ), | 27 | nLength( rSrc.nLength ), |
| 28 | pFirst( NULL ), | 28 | pFirst( NULL ), |
| 29 | pLast( NULL ) | 29 | pLast( NULL ) |
| 30 | { | 30 | { |
| 31 | if( rSrc.pFirst == NULL || rSrc.nLength == 0 ) | 31 | if( rSrc.pFirst == NULL || rSrc.nLength == 0 ) |
| 32 | { | 32 | { |
| 33 | pFirst = pLast = NULL; | 33 | pFirst = pLast = NULL; |
| 34 | } | 34 | } |
| 35 | else | 35 | else |
| 36 | { | 36 | { |
| 37 | pFirst = pLast = newChunk( nLength ); | 37 | pFirst = pLast = newChunk( nLength ); |
| 38 | Chunk *pLink = rSrc.pFirst; | 38 | Chunk *pLink = rSrc.pFirst; |
| 39 | int iPos = 0; | 39 | int iPos = 0; |
| 40 | while( pLink != NULL ) | 40 | while( pLink != NULL ) |
| 41 | { | 41 | { |
| 42 | memcpy( pFirst->pData+iPos, pLink->pData, pLink->nLength ); | 42 | memcpy( pFirst->pData+iPos, pLink->pData, pLink->nLength ); |
| 43 | iPos += pLink->nLength; | 43 | iPos += pLink->nLength; |
| 44 | pLink = pLink->pNext; | 44 | pLink = pLink->pNext; |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | Bu::StringCore::~StringCore() | 49 | Bu::StringCore::~StringCore() |
| 50 | { | 50 | { |
| 51 | clear(); | 51 | clear(); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | void Bu::StringCore::clear() const | 54 | void Bu::StringCore::clear() const |
| 55 | { | 55 | { |
| 56 | if( pFirst == NULL ) | 56 | if( pFirst == NULL ) |
| 57 | return; | 57 | return; |
| 58 | 58 | ||
| 59 | Chunk *i = pFirst; | 59 | Chunk *i = pFirst; |
| 60 | for(;;) | 60 | for(;;) |
| 61 | { | 61 | { |
| 62 | Chunk *n = i->pNext; | 62 | Chunk *n = i->pNext; |
| 63 | delete[] i->pData; | 63 | delete[] i->pData; |
| 64 | delete i; | 64 | delete i; |
| 65 | if( n == NULL ) | 65 | if( n == NULL ) |
| 66 | break; | 66 | break; |
| 67 | i = n; | 67 | i = n; |
| 68 | } | 68 | } |
| 69 | pFirst = pLast = NULL; | 69 | pFirst = pLast = NULL; |
| 70 | nLength = 0; | 70 | nLength = 0; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | Bu::StringCore::Chunk *Bu::StringCore::newChunk() const | 73 | Bu::StringCore::Chunk *Bu::StringCore::newChunk() const |
| 74 | { | 74 | { |
| 75 | Chunk *pNew = new Chunk; | 75 | Chunk *pNew = new Chunk; |
| 76 | pNew->pNext = NULL; | 76 | pNew->pNext = NULL; |
| 77 | return pNew; | 77 | return pNew; |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | Bu::StringCore::Chunk *Bu::StringCore::newChunk( long nLen ) const | 80 | Bu::StringCore::Chunk *Bu::StringCore::newChunk( long nLen ) const |
| 81 | { | 81 | { |
| 82 | Chunk *pNew = new Chunk; | 82 | Chunk *pNew = new Chunk; |
| 83 | pNew->pNext = NULL; | 83 | pNew->pNext = NULL; |
| 84 | pNew->nLength = nLen; | 84 | pNew->nLength = nLen; |
| 85 | pNew->pData = new char[(nLen<nMinSize)?(nMinSize):(nLen)+1]; | 85 | pNew->pData = new char[(nLen<nMinSize)?(nMinSize):(nLen)+1]; |
| 86 | pNew->pData[nLen] = (char)0; | 86 | pNew->pData[nLen] = (char)0; |
| 87 | return pNew; | 87 | return pNew; |
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | Bu::StringCore::Chunk *Bu::StringCore::copyChunk( | 90 | Bu::StringCore::Chunk *Bu::StringCore::copyChunk( |
| 91 | Bu::StringCore::Chunk *pSrc ) const | 91 | Bu::StringCore::Chunk *pSrc ) const |
| 92 | { | 92 | { |
| 93 | Chunk *pNew = new Chunk; | 93 | Chunk *pNew = new Chunk; |
| 94 | pNew->pNext = pSrc->pNext; | 94 | pNew->pNext = pSrc->pNext; |
| 95 | pNew->nLength = pSrc->nLength; | 95 | pNew->nLength = pSrc->nLength; |
| 96 | pNew->pData = new char[ | 96 | pNew->pData = new char[ |
| 97 | (pNew->nLength<nMinSize)?(nMinSize):(pNew->nLength)+1 | 97 | (pNew->nLength<nMinSize)?(nMinSize):(pNew->nLength)+1 |
| 98 | ]; | 98 | ]; |
| 99 | memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); | 99 | memcpy( pNew->pData, pSrc->pData, pSrc->nLength ); |
| 100 | pNew->pData[pNew->nLength] = (char)0; | 100 | pNew->pData[pNew->nLength] = (char)0; |
| 101 | return pNew; | 101 | return pNew; |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | void Bu::StringCore::appendChunk( Bu::StringCore::Chunk *pNewChunk ) | 104 | void Bu::StringCore::appendChunk( Bu::StringCore::Chunk *pNewChunk ) |
| 105 | { | 105 | { |
| 106 | if( pFirst == NULL ) | 106 | if( pFirst == NULL ) |
| 107 | pLast = pFirst = pNewChunk; | 107 | pLast = pFirst = pNewChunk; |
| 108 | else | 108 | else |
| 109 | { | 109 | { |
| 110 | pLast->pNext = pNewChunk; | 110 | pLast->pNext = pNewChunk; |
| 111 | pLast = pNewChunk; | 111 | pLast = pNewChunk; |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | nLength += pNewChunk->nLength; | 114 | nLength += pNewChunk->nLength; |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | void Bu::StringCore::prependChunk( Bu::StringCore::Chunk *pNewChunk ) | 117 | void Bu::StringCore::prependChunk( Bu::StringCore::Chunk *pNewChunk ) |
| 118 | { | 118 | { |
| 119 | if( pFirst == NULL ) | 119 | if( pFirst == NULL ) |
| 120 | pLast = pFirst = pNewChunk; | 120 | pLast = pFirst = pNewChunk; |
| 121 | else | 121 | else |
| 122 | { | 122 | { |
| 123 | pNewChunk->pNext = pFirst; | 123 | pNewChunk->pNext = pFirst; |
| 124 | pFirst = pNewChunk; | 124 | pFirst = pNewChunk; |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | nLength += pNewChunk->nLength; | 127 | nLength += pNewChunk->nLength; |
| 128 | } | 128 | } |
| 129 | 129 | ||
| 130 | Bu::String::String() | 130 | Bu::String::String() |
| @@ -133,44 +133,44 @@ Bu::String::String() | |||
| 133 | 133 | ||
| 134 | Bu::String::String( const char *pData ) | 134 | Bu::String::String( const char *pData ) |
| 135 | { | 135 | { |
| 136 | append( pData ); | 136 | append( pData ); |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | Bu::String::String( const char *pData, long nLength ) | 139 | Bu::String::String( const char *pData, long nLength ) |
| 140 | { | 140 | { |
| 141 | append( pData, nLength ); | 141 | append( pData, nLength ); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | Bu::String::String( const Bu::String &rSrc ) : | 144 | Bu::String::String( const Bu::String &rSrc ) : |
| 145 | Bu::SharedCore<Bu::String, Bu::StringCore>( rSrc ) | 145 | Bu::SharedCore<Bu::String, Bu::StringCore>( rSrc ) |
| 146 | { | 146 | { |
| 147 | } | 147 | } |
| 148 | 148 | ||
| 149 | Bu::String::String( const Bu::String &rSrc, long nLength ) | 149 | Bu::String::String( const Bu::String &rSrc, long nLength ) |
| 150 | { | 150 | { |
| 151 | append( rSrc, nLength ); | 151 | append( rSrc, nLength ); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | Bu::String::String( const Bu::String &rSrc, long nStart, long nLength ) | 154 | Bu::String::String( const Bu::String &rSrc, long nStart, long nLength ) |
| 155 | { | 155 | { |
| 156 | append( rSrc, nStart, nLength ); | 156 | append( rSrc, nStart, nLength ); |
| 157 | } | 157 | } |
| 158 | 158 | ||
| 159 | Bu::String::String( long nSize ) | 159 | Bu::String::String( long nSize ) |
| 160 | { | 160 | { |
| 161 | core->pFirst = core->pLast = core->newChunk( nSize ); | 161 | core->pFirst = core->pLast = core->newChunk( nSize ); |
| 162 | core->nLength = nSize; | 162 | core->nLength = nSize; |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | Bu::String::String( const Bu::String::const_iterator &s ) | 165 | Bu::String::String( const Bu::String::const_iterator &s ) |
| 166 | { | 166 | { |
| 167 | append( s ); | 167 | append( s ); |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | Bu::String::String( const Bu::String::const_iterator &s, | 170 | Bu::String::String( const Bu::String::const_iterator &s, |
| 171 | const Bu::String::const_iterator &e ) | 171 | const Bu::String::const_iterator &e ) |
| 172 | { | 172 | { |
| 173 | append( s, e ); | 173 | append( s, e ); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | Bu::String::~String() | 176 | Bu::String::~String() |
| @@ -179,1049 +179,1049 @@ Bu::String::~String() | |||
| 179 | 179 | ||
| 180 | void Bu::String::append( const char *pData ) | 180 | void Bu::String::append( const char *pData ) |
| 181 | { | 181 | { |
| 182 | if( !pData ) return; | 182 | if( !pData ) return; |
| 183 | long nLen; | 183 | long nLen; |
| 184 | for( nLen = 0; pData[nLen] != (char)0; nLen++ ) { } | 184 | for( nLen = 0; pData[nLen] != (char)0; nLen++ ) { } |
| 185 | 185 | ||
| 186 | append( pData, 0, nLen ); | 186 | append( pData, 0, nLen ); |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | void Bu::String::append( const char *pData, long nLen ) | 189 | void Bu::String::append( const char *pData, long nLen ) |
| 190 | { | 190 | { |
| 191 | append( pData, 0, nLen ); | 191 | append( pData, 0, nLen ); |
| 192 | } | 192 | } |
| 193 | 193 | ||
| 194 | void Bu::String::append( const char *pData, long nStart, long nLen ) | 194 | void Bu::String::append( const char *pData, long nStart, long nLen ) |
| 195 | { | 195 | { |
| 196 | if( !pData ) return; | 196 | if( !pData ) return; |
| 197 | if( nLen <= 0 ) | 197 | if( nLen <= 0 ) |
| 198 | return; | 198 | return; |
| 199 | 199 | ||
| 200 | pData += nStart; | 200 | pData += nStart; |
| 201 | 201 | ||
| 202 | _hardCopy(); | 202 | _hardCopy(); |
| 203 | 203 | ||
| 204 | if( core->pLast && core->pLast->nLength < nMinSize ) | 204 | if( core->pLast && core->pLast->nLength < nMinSize ) |
| 205 | { | 205 | { |
| 206 | int nAmnt = nMinSize - core->pLast->nLength; | 206 | int nAmnt = nMinSize - core->pLast->nLength; |
| 207 | if( nAmnt > nLen ) | 207 | if( nAmnt > nLen ) |
| 208 | nAmnt = nLen; | 208 | nAmnt = nLen; |
| 209 | memcpy( | 209 | memcpy( |
| 210 | core->pLast->pData+core->pLast->nLength, | 210 | core->pLast->pData+core->pLast->nLength, |
| 211 | pData, | 211 | pData, |
| 212 | nAmnt | 212 | nAmnt |
| 213 | ); | 213 | ); |
| 214 | pData += nAmnt; | 214 | pData += nAmnt; |
| 215 | core->pLast->nLength += nAmnt; | 215 | core->pLast->nLength += nAmnt; |
| 216 | nLen -= nAmnt; | 216 | nLen -= nAmnt; |
| 217 | core->nLength += nAmnt; | 217 | core->nLength += nAmnt; |
| 218 | } | 218 | } |
| 219 | 219 | ||
| 220 | if( nLen > 0 ) | 220 | if( nLen > 0 ) |
| 221 | { | 221 | { |
| 222 | Chunk *pNew = core->newChunk( nLen ); | 222 | Chunk *pNew = core->newChunk( nLen ); |
| 223 | memcpy( pNew->pData, pData, nLen ); | 223 | memcpy( pNew->pData, pData, nLen ); |
| 224 | core->appendChunk( pNew ); | 224 | core->appendChunk( pNew ); |
| 225 | // core->nLength += nLen; | 225 | // core->nLength += nLen; |
| 226 | } | 226 | } |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | void Bu::String::append( const char &cData ) | 229 | void Bu::String::append( const char &cData ) |
| 230 | { | 230 | { |
| 231 | if( core->pLast && core->pLast->nLength < nMinSize ) | 231 | if( core->pLast && core->pLast->nLength < nMinSize ) |
| 232 | { | 232 | { |
| 233 | _hardCopy(); | 233 | _hardCopy(); |
| 234 | core->pLast->pData[core->pLast->nLength] = cData; | 234 | core->pLast->pData[core->pLast->nLength] = cData; |
| 235 | ++core->pLast->nLength; ++core->nLength; | 235 | ++core->pLast->nLength; ++core->nLength; |
| 236 | // pLast->pData[pLast->nLength] = (char)0; | 236 | // pLast->pData[pLast->nLength] = (char)0; |
| 237 | } | 237 | } |
| 238 | else | 238 | else |
| 239 | { | 239 | { |
| 240 | append( &cData, 1 ); | 240 | append( &cData, 1 ); |
| 241 | } | 241 | } |
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | void Bu::String::append( const String & sData ) | 244 | void Bu::String::append( const String & sData ) |
| 245 | { | 245 | { |
| 246 | append( sData.getStr(), 0, sData.getSize() ); | 246 | append( sData.getStr(), 0, sData.getSize() ); |
| 247 | } | 247 | } |
| 248 | 248 | ||
| 249 | void Bu::String::append( const String & sData, long nLen ) | 249 | void Bu::String::append( const String & sData, long nLen ) |
| 250 | { | 250 | { |
| 251 | append( sData.getStr(), 0, nLen ); | 251 | append( sData.getStr(), 0, nLen ); |
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | void Bu::String::append( const String & sData, long nStart, long nLen ) | 254 | void Bu::String::append( const String & sData, long nStart, long nLen ) |
| 255 | { | 255 | { |
| 256 | if( nLen < 0 ) | 256 | if( nLen < 0 ) |
| 257 | nLen = sData.getSize() - nStart; | 257 | nLen = sData.getSize() - nStart; |
| 258 | append( sData.getStr(), nStart, nLen ); | 258 | append( sData.getStr(), nStart, nLen ); |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | void Bu::String::append( const const_iterator &s ) | 261 | void Bu::String::append( const const_iterator &s ) |
| 262 | { | 262 | { |
| 263 | if( !s.isValid() ) | 263 | if( !s.isValid() ) |
| 264 | return; | 264 | return; |
| 265 | Chunk *pSrc = s.pChunk; | 265 | Chunk *pSrc = s.pChunk; |
| 266 | 266 | ||
| 267 | Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); | 267 | Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); |
| 268 | memcpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); | 268 | memcpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); |
| 269 | 269 | ||
| 270 | _hardCopy(); | 270 | _hardCopy(); |
| 271 | core->appendChunk( pNew ); | 271 | core->appendChunk( pNew ); |
| 272 | 272 | ||
| 273 | while( (pSrc = pSrc->pNext) ) | 273 | while( (pSrc = pSrc->pNext) ) |
| 274 | { | 274 | { |
| 275 | core->appendChunk( core->copyChunk( pSrc ) ); | 275 | core->appendChunk( core->copyChunk( pSrc ) ); |
| 276 | } | 276 | } |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | void Bu::String::append( const iterator &s ) | 279 | void Bu::String::append( const iterator &s ) |
| 280 | { | 280 | { |
| 281 | append( const_iterator( s ) ); | 281 | append( const_iterator( s ) ); |
| 282 | } | 282 | } |
| 283 | 283 | ||
| 284 | void Bu::String::append( const const_iterator &s, const const_iterator &e ) | 284 | void Bu::String::append( const const_iterator &s, const const_iterator &e ) |
| 285 | { | 285 | { |
| 286 | if( !s.isValid() ) | 286 | if( !s.isValid() ) |
| 287 | return; | 287 | return; |
| 288 | if( !e.isValid() ) | 288 | if( !e.isValid() ) |
| 289 | { | 289 | { |
| 290 | append( s ); | 290 | append( s ); |
| 291 | return; | 291 | return; |
| 292 | } | 292 | } |
| 293 | _hardCopy(); | 293 | _hardCopy(); |
| 294 | if( s.pChunk == e.pChunk ) | 294 | if( s.pChunk == e.pChunk ) |
| 295 | { | 295 | { |
| 296 | // Simple case, they're the same chunk | 296 | // Simple case, they're the same chunk |
| 297 | Chunk *pNew = core->newChunk( e.iPos-s.iPos ); | 297 | Chunk *pNew = core->newChunk( e.iPos-s.iPos ); |
| 298 | memcpy( pNew->pData, s.pChunk->pData+s.iPos, e.iPos-s.iPos ); | 298 | memcpy( pNew->pData, s.pChunk->pData+s.iPos, e.iPos-s.iPos ); |
| 299 | core->appendChunk( pNew ); | 299 | core->appendChunk( pNew ); |
| 300 | } | 300 | } |
| 301 | else | 301 | else |
| 302 | { | 302 | { |
| 303 | // A little trickier, scan the blocks... | 303 | // A little trickier, scan the blocks... |
| 304 | Chunk *pSrc = s.pChunk; | 304 | Chunk *pSrc = s.pChunk; |
| 305 | Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); | 305 | Chunk *pNew = core->newChunk( pSrc->nLength-s.iPos ); |
| 306 | memcpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); | 306 | memcpy( pNew->pData, pSrc->pData+s.iPos, pSrc->nLength-s.iPos ); |
| 307 | core->appendChunk( pNew ); | 307 | core->appendChunk( pNew ); |
| 308 | 308 | ||
| 309 | while( (pSrc = pSrc->pNext) != e.pChunk ) | 309 | while( (pSrc = pSrc->pNext) != e.pChunk ) |
| 310 | { | 310 | { |
| 311 | core->appendChunk( core->copyChunk( pSrc ) ); | 311 | core->appendChunk( core->copyChunk( pSrc ) ); |
| 312 | } | 312 | } |
| 313 | 313 | ||
| 314 | pNew = core->newChunk( e.iPos ); | 314 | pNew = core->newChunk( e.iPos ); |
| 315 | memcpy( pNew->pData, pSrc->pData, e.iPos ); | 315 | memcpy( pNew->pData, pSrc->pData, e.iPos ); |
| 316 | core->appendChunk( pNew ); | 316 | core->appendChunk( pNew ); |
| 317 | } | 317 | } |
| 318 | } | 318 | } |
| 319 | 319 | ||
| 320 | void Bu::String::prepend( const String & sData ) | 320 | void Bu::String::prepend( const String & sData ) |
| 321 | { | 321 | { |
| 322 | prepend( sData.getStr(), sData.getSize() ); | 322 | prepend( sData.getStr(), sData.getSize() ); |
| 323 | } | 323 | } |
| 324 | 324 | ||
| 325 | void Bu::String::prepend( const char *pData ) | 325 | void Bu::String::prepend( const char *pData ) |
| 326 | { | 326 | { |
| 327 | if( pData == NULL ) | 327 | if( pData == NULL ) |
| 328 | return; | 328 | return; |
| 329 | 329 | ||
| 330 | _hardCopy(); | 330 | _hardCopy(); |
| 331 | long nLen; | 331 | long nLen; |
| 332 | for( nLen = 0; pData[nLen] != (char)0; nLen++ ) { } | 332 | for( nLen = 0; pData[nLen] != (char)0; nLen++ ) { } |
| 333 | 333 | ||
| 334 | Chunk *pNew = core->newChunk( nLen ); | 334 | Chunk *pNew = core->newChunk( nLen ); |
| 335 | memcpy( pNew->pData, pData, nLen ); | 335 | memcpy( pNew->pData, pData, nLen ); |
| 336 | 336 | ||
| 337 | core->prependChunk( pNew ); | 337 | core->prependChunk( pNew ); |
| 338 | } | 338 | } |
| 339 | 339 | ||
| 340 | void Bu::String::prepend( const char *pData, long nLen ) | 340 | void Bu::String::prepend( const char *pData, long nLen ) |
| 341 | { | 341 | { |
| 342 | Chunk *pNew = core->newChunk( nLen ); | 342 | Chunk *pNew = core->newChunk( nLen ); |
| 343 | 343 | ||
| 344 | memcpy( pNew->pData, pData, nLen ); | 344 | memcpy( pNew->pData, pData, nLen ); |
| 345 | 345 | ||
| 346 | _hardCopy(); | 346 | _hardCopy(); |
| 347 | core->prependChunk( pNew ); | 347 | core->prependChunk( pNew ); |
| 348 | } | 348 | } |
| 349 | 349 | ||
| 350 | void Bu::String::prepend( const char c ) | 350 | void Bu::String::prepend( const char c ) |
| 351 | { | 351 | { |
| 352 | prepend( &c, 1 ); | 352 | prepend( &c, 1 ); |
| 353 | } | 353 | } |
| 354 | 354 | ||
| 355 | void Bu::String::insert( long nPos, const char *pData, long nLen ) | 355 | void Bu::String::insert( long nPos, const char *pData, long nLen ) |
| 356 | { | 356 | { |
| 357 | if( nLen <= 0 ) | 357 | if( nLen <= 0 ) |
| 358 | return; | 358 | return; |
| 359 | if( nPos <= 0 ) | 359 | if( nPos <= 0 ) |
| 360 | { | 360 | { |
| 361 | prepend( pData, nLen ); | 361 | prepend( pData, nLen ); |
| 362 | } | 362 | } |
| 363 | else if( nPos >= core->nLength ) | 363 | else if( nPos >= core->nLength ) |
| 364 | { | 364 | { |
| 365 | append( pData, nLen ); | 365 | append( pData, nLen ); |
| 366 | } | 366 | } |
| 367 | else | 367 | else |
| 368 | { | 368 | { |
| 369 | // If we're going to flatten anyway, might as well for everyone | 369 | // If we're going to flatten anyway, might as well for everyone |
| 370 | flatten(); | 370 | flatten(); |
| 371 | _hardCopy(); | 371 | _hardCopy(); |
| 372 | Chunk *p1 = core->newChunk( nPos ); | 372 | Chunk *p1 = core->newChunk( nPos ); |
| 373 | Chunk *p2 = core->newChunk( nLen ); | 373 | Chunk *p2 = core->newChunk( nLen ); |
| 374 | Chunk *p3 = core->newChunk( core->nLength-nPos ); | 374 | Chunk *p3 = core->newChunk( core->nLength-nPos ); |
| 375 | memcpy( p1->pData, core->pFirst->pData, nPos ); | 375 | memcpy( p1->pData, core->pFirst->pData, nPos ); |
| 376 | memcpy( p2->pData, pData, nLen ); | 376 | memcpy( p2->pData, pData, nLen ); |
| 377 | memcpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); | 377 | memcpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); |
| 378 | core->clear(); | 378 | core->clear(); |
| 379 | core->appendChunk( p1 ); | 379 | core->appendChunk( p1 ); |
| 380 | core->appendChunk( p2 ); | 380 | core->appendChunk( p2 ); |
| 381 | core->appendChunk( p3 ); | 381 | core->appendChunk( p3 ); |
| 382 | } | 382 | } |
| 383 | } | 383 | } |
| 384 | 384 | ||
| 385 | void Bu::String::insert( long nPos, const String &str ) | 385 | void Bu::String::insert( long nPos, const String &str ) |
| 386 | { | 386 | { |
| 387 | if( nPos <= 0 ) | 387 | if( nPos <= 0 ) |
| 388 | { | 388 | { |
| 389 | prepend( str ); | 389 | prepend( str ); |
| 390 | } | 390 | } |
| 391 | else if( nPos >= core->nLength ) | 391 | else if( nPos >= core->nLength ) |
| 392 | { | 392 | { |
| 393 | append( str ); | 393 | append( str ); |
| 394 | } | 394 | } |
| 395 | else | 395 | else |
| 396 | { | 396 | { |
| 397 | flatten(); | 397 | flatten(); |
| 398 | _hardCopy(); | 398 | _hardCopy(); |
| 399 | Chunk *p1 = core->newChunk( nPos ); | 399 | Chunk *p1 = core->newChunk( nPos ); |
| 400 | Chunk *p3 = core->newChunk( core->nLength-nPos ); | 400 | Chunk *p3 = core->newChunk( core->nLength-nPos ); |
| 401 | memcpy( p1->pData, core->pFirst->pData, nPos ); | 401 | memcpy( p1->pData, core->pFirst->pData, nPos ); |
| 402 | memcpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); | 402 | memcpy( p3->pData, core->pFirst->pData+nPos, core->nLength-nPos ); |
| 403 | core->clear(); | 403 | core->clear(); |
| 404 | core->appendChunk( p1 ); | 404 | core->appendChunk( p1 ); |
| 405 | for( Chunk *pChnk = str.core->pFirst; pChnk; | 405 | for( Chunk *pChnk = str.core->pFirst; pChnk; |
| 406 | pChnk = pChnk->pNext ) | 406 | pChnk = pChnk->pNext ) |
| 407 | { | 407 | { |
| 408 | core->appendChunk( core->copyChunk( pChnk ) ); | 408 | core->appendChunk( core->copyChunk( pChnk ) ); |
| 409 | } | 409 | } |
| 410 | 410 | ||
| 411 | core->appendChunk( p3 ); | 411 | core->appendChunk( p3 ); |
| 412 | } | 412 | } |
| 413 | } | 413 | } |
| 414 | 414 | ||
| 415 | void Bu::String::insert( long nPos, const char *pData ) | 415 | void Bu::String::insert( long nPos, const char *pData ) |
| 416 | { | 416 | { |
| 417 | insert( nPos, pData, strlen( pData ) ); | 417 | insert( nPos, pData, strlen( pData ) ); |
| 418 | } | 418 | } |
| 419 | 419 | ||
| 420 | void Bu::String::remove( long nPos, long nLen ) | 420 | void Bu::String::remove( long nPos, long nLen ) |
| 421 | { | 421 | { |
| 422 | if( nLen <= 0 || nPos < 0 || nPos >= core->nLength ) | 422 | if( nLen <= 0 || nPos < 0 || nPos >= core->nLength ) |
| 423 | return; | 423 | return; |
| 424 | if( nLen > core->nLength-nPos ) | 424 | if( nLen > core->nLength-nPos ) |
| 425 | nLen = core->nLength-nPos; | 425 | nLen = core->nLength-nPos; |
| 426 | flatten(); | 426 | flatten(); |
| 427 | _hardCopy(); | 427 | _hardCopy(); |
| 428 | memmove( core->pFirst->pData+nPos, core->pFirst->pData+nPos+nLen, core->nLength-nPos-nLen+1 ); | 428 | memmove( core->pFirst->pData+nPos, core->pFirst->pData+nPos+nLen, core->nLength-nPos-nLen+1 ); |
| 429 | core->nLength -= nLen; | 429 | core->nLength -= nLen; |
| 430 | core->pFirst->nLength -= nLen; | 430 | core->pFirst->nLength -= nLen; |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | void Bu::String::clear() | 433 | void Bu::String::clear() |
| 434 | { | 434 | { |
| 435 | _hardCopy(); | 435 | _hardCopy(); |
| 436 | core->clear(); | 436 | core->clear(); |
| 437 | } | 437 | } |
| 438 | 438 | ||
| 439 | Bu::String Bu::String::replace( const Bu::String &fnd, | 439 | Bu::String Bu::String::replace( const Bu::String &fnd, |
| 440 | const Bu::String &rep ) const | 440 | const Bu::String &rep ) const |
| 441 | { | 441 | { |
| 442 | String out; | 442 | String out; |
| 443 | const_iterator o = begin(); | 443 | const_iterator o = begin(); |
| 444 | while( true ) | 444 | while( true ) |
| 445 | { | 445 | { |
| 446 | const_iterator i = o.find( fnd, fnd.getSize() ); | 446 | const_iterator i = o.find( fnd, fnd.getSize() ); |
| 447 | if( !i ) | 447 | if( !i ) |
| 448 | { | 448 | { |
| 449 | out.append( o ); | 449 | out.append( o ); |
| 450 | return out; | 450 | return out; |
| 451 | } | 451 | } |
| 452 | else | 452 | else |
| 453 | { | 453 | { |
| 454 | out.append( o, i ); | 454 | out.append( o, i ); |
| 455 | out.append( rep ); | 455 | out.append( rep ); |
| 456 | o = i; | 456 | o = i; |
| 457 | o += fnd.getSize(); | 457 | o += fnd.getSize(); |
| 458 | } | 458 | } |
| 459 | } | 459 | } |
| 460 | } | 460 | } |
| 461 | 461 | ||
| 462 | void Bu::String::resize( long nNewSize ) | 462 | void Bu::String::resize( long nNewSize ) |
| 463 | { | 463 | { |
| 464 | if( core->nLength == nNewSize ) | 464 | if( core->nLength == nNewSize ) |
| 465 | return; | 465 | return; |
| 466 | if( nNewSize < 0 ) | 466 | if( nNewSize < 0 ) |
| 467 | nNewSize = 0; | 467 | nNewSize = 0; |
| 468 | 468 | ||
| 469 | flatten(); | 469 | flatten(); |
| 470 | _hardCopy(); | 470 | _hardCopy(); |
| 471 | 471 | ||
| 472 | // TODO: This is bad | 472 | // TODO: This is bad |
| 473 | 473 | ||
| 474 | Chunk *pNew = core->newChunk( nNewSize ); | 474 | Chunk *pNew = core->newChunk( nNewSize ); |
| 475 | long nNewLen = (nNewSize<core->nLength)?(nNewSize):(core->nLength); | 475 | long nNewLen = (nNewSize<core->nLength)?(nNewSize):(core->nLength); |
| 476 | if( core->nLength > 0 ) | 476 | if( core->nLength > 0 ) |
| 477 | { | 477 | { |
| 478 | memcpy( pNew->pData, core->pFirst->pData, nNewLen ); | 478 | memcpy( pNew->pData, core->pFirst->pData, nNewLen ); |
| 479 | delete[] core->pFirst->pData; | 479 | delete[] core->pFirst->pData; |
| 480 | delete core->pFirst; | 480 | delete core->pFirst; |
| 481 | } | 481 | } |
| 482 | pNew->pData[nNewLen] = (char)0; | 482 | pNew->pData[nNewLen] = (char)0; |
| 483 | core->pFirst = core->pLast = pNew; | 483 | core->pFirst = core->pLast = pNew; |
| 484 | core->nLength = nNewSize; | 484 | core->nLength = nNewSize; |
| 485 | } | 485 | } |
| 486 | 486 | ||
| 487 | long Bu::String::getSize() const | 487 | long Bu::String::getSize() const |
| 488 | { | 488 | { |
| 489 | return core->nLength; | 489 | return core->nLength; |
| 490 | } | 490 | } |
| 491 | 491 | ||
| 492 | char *Bu::String::getStr() | 492 | char *Bu::String::getStr() |
| 493 | { | 493 | { |
| 494 | if( core->pFirst == NULL || core->nLength == 0 ) | 494 | if( core->pFirst == NULL || core->nLength == 0 ) |
| 495 | return (char *)""; | 495 | return (char *)""; |
| 496 | 496 | ||
| 497 | flatten(); | 497 | flatten(); |
| 498 | _hardCopy(); | 498 | _hardCopy(); |
| 499 | core->pFirst->pData[core->nLength] = (char)0; | 499 | core->pFirst->pData[core->nLength] = (char)0; |
| 500 | return core->pFirst->pData; | 500 | return core->pFirst->pData; |
| 501 | } | 501 | } |
| 502 | 502 | ||
| 503 | const char *Bu::String::getStr() const | 503 | const char *Bu::String::getStr() const |
| 504 | { | 504 | { |
| 505 | if( core->pFirst == NULL || core->nLength == 0 ) | 505 | if( core->pFirst == NULL || core->nLength == 0 ) |
| 506 | return (char *)""; | 506 | return (char *)""; |
| 507 | 507 | ||
| 508 | flatten(); | 508 | flatten(); |
| 509 | core->pFirst->pData[core->nLength] = (char)0; | 509 | core->pFirst->pData[core->nLength] = (char)0; |
| 510 | return core->pFirst->pData; | 510 | return core->pFirst->pData; |
| 511 | } | 511 | } |
| 512 | 512 | ||
| 513 | const char *Bu::String::getConstStr() const | 513 | const char *Bu::String::getConstStr() const |
| 514 | { | 514 | { |
| 515 | return getStr(); | 515 | return getStr(); |
| 516 | } | 516 | } |
| 517 | 517 | ||
| 518 | Bu::String Bu::String::getSubStrIdx( long iStart, long iSize ) const | 518 | Bu::String Bu::String::getSubStrIdx( long iStart, long iSize ) const |
| 519 | { | 519 | { |
| 520 | if( iStart < 0 ) | 520 | if( iStart < 0 ) |
| 521 | iStart = 0; | 521 | iStart = 0; |
| 522 | if( iStart >= core->nLength ) | 522 | if( iStart >= core->nLength ) |
| 523 | return (const char[]){(char)0}; | 523 | return (const char[]){(char)0}; |
| 524 | if( iSize < 0 ) | 524 | if( iSize < 0 ) |
| 525 | iSize = core->nLength; | 525 | iSize = core->nLength; |
| 526 | if( iStart+iSize > core->nLength ) | 526 | if( iStart+iSize > core->nLength ) |
| 527 | iSize = core->nLength-iStart; | 527 | iSize = core->nLength-iStart; |
| 528 | if( iSize == 0 ) | 528 | if( iSize == 0 ) |
| 529 | return (const char[]){(char)0}; | 529 | return (const char[]){(char)0}; |
| 530 | 530 | ||
| 531 | flatten(); | 531 | flatten(); |
| 532 | String ret( core->pFirst->pData+iStart, iSize ); | 532 | String ret( core->pFirst->pData+iStart, iSize ); |
| 533 | return ret; | 533 | return ret; |
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | Bu::String Bu::String::getSubStr( const_iterator iBegin, | 536 | Bu::String Bu::String::getSubStr( const_iterator iBegin, |
| 537 | const_iterator iEnd ) const | 537 | const_iterator iEnd ) const |
| 538 | { | 538 | { |
| 539 | if( !iBegin.isValid() ) | 539 | if( !iBegin.isValid() ) |
| 540 | return String(); | 540 | return String(); |
| 541 | if( iBegin.pChunk == iEnd.pChunk ) | 541 | if( iBegin.pChunk == iEnd.pChunk ) |
| 542 | { | 542 | { |
| 543 | return String( iBegin.pChunk->pData+iBegin.iPos, | 543 | return String( iBegin.pChunk->pData+iBegin.iPos, |
| 544 | iEnd.iPos-iBegin.iPos ); | 544 | iEnd.iPos-iBegin.iPos ); |
| 545 | } | 545 | } |
| 546 | else if( !iEnd.isValid() ) | 546 | else if( !iEnd.isValid() ) |
| 547 | { | 547 | { |
| 548 | String ret; | 548 | String ret; |
| 549 | ret.append( | 549 | ret.append( |
| 550 | iBegin.pChunk->pData+iBegin.iPos, | 550 | iBegin.pChunk->pData+iBegin.iPos, |
| 551 | iBegin.pChunk->nLength-iBegin.iPos | 551 | iBegin.pChunk->nLength-iBegin.iPos |
| 552 | ); | 552 | ); |
| 553 | for( Chunk *pCur = iBegin.pChunk->pNext; | 553 | for( Chunk *pCur = iBegin.pChunk->pNext; |
| 554 | pCur; pCur = pCur->pNext ) | 554 | pCur; pCur = pCur->pNext ) |
| 555 | { | 555 | { |
| 556 | ret.append( pCur->pData, pCur->nLength ); | 556 | ret.append( pCur->pData, pCur->nLength ); |
| 557 | } | 557 | } |
| 558 | return ret; | 558 | return ret; |
| 559 | } | 559 | } |
| 560 | else | 560 | else |
| 561 | { | 561 | { |
| 562 | String ret; | 562 | String ret; |
| 563 | ret.append( | 563 | ret.append( |
| 564 | iBegin.pChunk->pData+iBegin.iPos, | 564 | iBegin.pChunk->pData+iBegin.iPos, |
| 565 | iBegin.pChunk->nLength-iBegin.iPos | 565 | iBegin.pChunk->nLength-iBegin.iPos |
| 566 | ); | 566 | ); |
| 567 | for( Chunk *pCur = iBegin.pChunk->pNext; | 567 | for( Chunk *pCur = iBegin.pChunk->pNext; |
| 568 | pCur != iEnd.pChunk; pCur = pCur->pNext ) | 568 | pCur != iEnd.pChunk; pCur = pCur->pNext ) |
| 569 | { | 569 | { |
| 570 | ret.append( pCur->pData, pCur->nLength ); | 570 | ret.append( pCur->pData, pCur->nLength ); |
| 571 | } | 571 | } |
| 572 | ret.append( | 572 | ret.append( |
| 573 | iEnd.pChunk->pData, | 573 | iEnd.pChunk->pData, |
| 574 | iEnd.iPos | 574 | iEnd.iPos |
| 575 | ); | 575 | ); |
| 576 | return ret; | 576 | return ret; |
| 577 | } | 577 | } |
| 578 | } | 578 | } |
| 579 | 579 | ||
| 580 | Bu::StringList Bu::String::split( const char c ) const | 580 | Bu::StringList Bu::String::split( const char c ) const |
| 581 | { | 581 | { |
| 582 | Bu::StringList ret; | 582 | Bu::StringList ret; |
| 583 | const_iterator l, r; | 583 | const_iterator l, r; |
| 584 | l = begin(); | 584 | l = begin(); |
| 585 | for(r=l; l;) | 585 | for(r=l; l;) |
| 586 | { | 586 | { |
| 587 | for( r = l; r && r != c; r++ ) { } | 587 | for( r = l; r && r != c; r++ ) { } |
| 588 | ret.append( String( l, r ) ); | 588 | ret.append( String( l, r ) ); |
| 589 | l = r; | 589 | l = r; |
| 590 | l++; | 590 | l++; |
| 591 | } | 591 | } |
| 592 | return ret; | 592 | return ret; |
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | Bu::String &Bu::String::operator+=( const char *pData ) | 595 | Bu::String &Bu::String::operator+=( const char *pData ) |
| 596 | { | 596 | { |
| 597 | append( pData ); | 597 | append( pData ); |
| 598 | 598 | ||
| 599 | return (*this); | 599 | return (*this); |
| 600 | } | 600 | } |
| 601 | 601 | ||
| 602 | Bu::String &Bu::String::operator+=( const Bu::String &rSrc ) | 602 | Bu::String &Bu::String::operator+=( const Bu::String &rSrc ) |
| 603 | { | 603 | { |
| 604 | append( rSrc ); | 604 | append( rSrc ); |
| 605 | 605 | ||
| 606 | return (*this); | 606 | return (*this); |
| 607 | } | 607 | } |
| 608 | 608 | ||
| 609 | Bu::String &Bu::String::operator+=( const Bu::String::const_iterator &i ) | 609 | Bu::String &Bu::String::operator+=( const Bu::String::const_iterator &i ) |
| 610 | { | 610 | { |
| 611 | append( i, i+1 ); | 611 | append( i, i+1 ); |
| 612 | 612 | ||
| 613 | return (*this); | 613 | return (*this); |
| 614 | } | 614 | } |
| 615 | 615 | ||
| 616 | Bu::String &Bu::String::operator+=( const char cData ) | 616 | Bu::String &Bu::String::operator+=( const char cData ) |
| 617 | { | 617 | { |
| 618 | if( core->pLast && core->pLast->nLength < nMinSize ) | 618 | if( core->pLast && core->pLast->nLength < nMinSize ) |
| 619 | { | 619 | { |
| 620 | _hardCopy(); | 620 | _hardCopy(); |
| 621 | core->pLast->pData[core->pLast->nLength] = cData; | 621 | core->pLast->pData[core->pLast->nLength] = cData; |
| 622 | ++core->pLast->nLength; ++core->nLength; | 622 | ++core->pLast->nLength; ++core->nLength; |
| 623 | // pLast->pData[pLast->nLength] = (char)0; | 623 | // pLast->pData[pLast->nLength] = (char)0; |
| 624 | } | 624 | } |
| 625 | else | 625 | else |
| 626 | { | 626 | { |
| 627 | append( &cData, 1 ); | 627 | append( &cData, 1 ); |
| 628 | } | 628 | } |
| 629 | //append( pData ); | 629 | //append( pData ); |
| 630 | 630 | ||
| 631 | return (*this); | 631 | return (*this); |
| 632 | } | 632 | } |
| 633 | 633 | ||
| 634 | Bu::String &Bu::String::operator=( const char *pData ) | 634 | Bu::String &Bu::String::operator=( const char *pData ) |
| 635 | { | 635 | { |
| 636 | set( pData ); | 636 | set( pData ); |
| 637 | 637 | ||
| 638 | return (*this); | 638 | return (*this); |
| 639 | } | 639 | } |
| 640 | 640 | ||
| 641 | Bu::String Bu::String::operator+( const Bu::String &rRight ) const | 641 | Bu::String Bu::String::operator+( const Bu::String &rRight ) const |
| 642 | { | 642 | { |
| 643 | String ret( *this ); | 643 | String ret( *this ); |
| 644 | ret.append( rRight ); | 644 | ret.append( rRight ); |
| 645 | return ret; | 645 | return ret; |
| 646 | } | 646 | } |
| 647 | 647 | ||
| 648 | Bu::String Bu::String::operator+( const char *pRight ) const | 648 | Bu::String Bu::String::operator+( const char *pRight ) const |
| 649 | { | 649 | { |
| 650 | String ret( *this ); | 650 | String ret( *this ); |
| 651 | ret.append( pRight ); | 651 | ret.append( pRight ); |
| 652 | return ret; | 652 | return ret; |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | Bu::String Bu::String::operator+( char *pRight ) const | 655 | Bu::String Bu::String::operator+( char *pRight ) const |
| 656 | { | 656 | { |
| 657 | String ret( *this ); | 657 | String ret( *this ); |
| 658 | ret.append( pRight ); | 658 | ret.append( pRight ); |
| 659 | return ret; | 659 | return ret; |
| 660 | } | 660 | } |
| 661 | 661 | ||
| 662 | void Bu::String::set( const char *pData ) | 662 | void Bu::String::set( const char *pData ) |
| 663 | { | 663 | { |
| 664 | clear(); | 664 | clear(); |
| 665 | append( pData ); | 665 | append( pData ); |
| 666 | } | 666 | } |
| 667 | 667 | ||
| 668 | void Bu::String::set( const char *pData, long nSize ) | 668 | void Bu::String::set( const char *pData, long nSize ) |
| 669 | { | 669 | { |
| 670 | clear(); | 670 | clear(); |
| 671 | append( pData, nSize ); | 671 | append( pData, nSize ); |
| 672 | } | 672 | } |
| 673 | 673 | ||
| 674 | void Bu::String::set( const char *pData, long nStart, long nSize ) | 674 | void Bu::String::set( const char *pData, long nStart, long nSize ) |
| 675 | { | 675 | { |
| 676 | clear(); | 676 | clear(); |
| 677 | append( pData, nStart, nSize ); | 677 | append( pData, nStart, nSize ); |
| 678 | } | 678 | } |
| 679 | 679 | ||
| 680 | void Bu::String::set( const String &rData ) | 680 | void Bu::String::set( const String &rData ) |
| 681 | { | 681 | { |
| 682 | clear(); | 682 | clear(); |
| 683 | append( rData ); | 683 | append( rData ); |
| 684 | } | 684 | } |
| 685 | 685 | ||
| 686 | void Bu::String::set( const String &rData, long nSize ) | 686 | void Bu::String::set( const String &rData, long nSize ) |
| 687 | { | 687 | { |
| 688 | clear(); | 688 | clear(); |
| 689 | append( rData, nSize ); | 689 | append( rData, nSize ); |
| 690 | } | 690 | } |
| 691 | 691 | ||
| 692 | void Bu::String::set( const String &rData, long nStart, long nSize ) | 692 | void Bu::String::set( const String &rData, long nStart, long nSize ) |
| 693 | { | 693 | { |
| 694 | clear(); | 694 | clear(); |
| 695 | append( rData, nStart, nSize ); | 695 | append( rData, nStart, nSize ); |
| 696 | } | 696 | } |
| 697 | 697 | ||
| 698 | void Bu::String::set( const_iterator s ) | 698 | void Bu::String::set( const_iterator s ) |
| 699 | { | 699 | { |
| 700 | clear(); | 700 | clear(); |
| 701 | append( s ); | 701 | append( s ); |
| 702 | } | 702 | } |
| 703 | 703 | ||
| 704 | void Bu::String::set( const_iterator s, const_iterator e ) | 704 | void Bu::String::set( const_iterator s, const_iterator e ) |
| 705 | { | 705 | { |
| 706 | clear(); | 706 | clear(); |
| 707 | append( s, e ); | 707 | append( s, e ); |
| 708 | } | 708 | } |
| 709 | 709 | ||
| 710 | void Bu::String::setSize( long iSize ) | 710 | void Bu::String::setSize( long iSize ) |
| 711 | { | 711 | { |
| 712 | _hardCopy(); | 712 | _hardCopy(); |
| 713 | core->clear(); | 713 | core->clear(); |
| 714 | core->appendChunk( core->newChunk( iSize ) ); | 714 | core->appendChunk( core->newChunk( iSize ) ); |
| 715 | } | 715 | } |
| 716 | 716 | ||
| 717 | bool Bu::String::operator==( const char *pData ) const | 717 | bool Bu::String::operator==( const char *pData ) const |
| 718 | { | 718 | { |
| 719 | if( core->pFirst == NULL || core->nLength == 0 ) { | 719 | if( core->pFirst == NULL || core->nLength == 0 ) { |
| 720 | if( pData == NULL ) | 720 | if( pData == NULL ) |
| 721 | return true; | 721 | return true; |
| 722 | if( pData[0] == (char)0 ) | 722 | if( pData[0] == (char)0 ) |
| 723 | return true; | 723 | return true; |
| 724 | return false; | 724 | return false; |
| 725 | } | 725 | } |
| 726 | 726 | ||
| 727 | flatten(); | 727 | flatten(); |
| 728 | core->pFirst->pData[core->nLength] = (char)0; | 728 | core->pFirst->pData[core->nLength] = (char)0; |
| 729 | const char *a = pData; | 729 | const char *a = pData; |
| 730 | char *b = core->pFirst->pData; | 730 | char *b = core->pFirst->pData; |
| 731 | for( long j = 0; *a!=(char)0 || *b!=(char)0; j++, a++, b++ ) | 731 | for( long j = 0; *a!=(char)0 || *b!=(char)0; j++, a++, b++ ) |
| 732 | { | 732 | { |
| 733 | if( *a != *b ) | 733 | if( *a != *b ) |
| 734 | return false; | 734 | return false; |
| 735 | if( *a == (char)0 && j < core->nLength ) | 735 | if( *a == (char)0 && j < core->nLength ) |
| 736 | return false; | 736 | return false; |
| 737 | } | 737 | } |
| 738 | 738 | ||
| 739 | return true; | 739 | return true; |
| 740 | } | 740 | } |
| 741 | 741 | ||
| 742 | bool Bu::String::operator==( const String &pData ) const | 742 | bool Bu::String::operator==( const String &pData ) const |
| 743 | { | 743 | { |
| 744 | if( core == pData.core ) | 744 | if( core == pData.core ) |
| 745 | return true; | 745 | return true; |
| 746 | if( core->pFirst == pData.core->pFirst ) | 746 | if( core->pFirst == pData.core->pFirst ) |
| 747 | return true; | 747 | return true; |
| 748 | if( (core->nLength == 0 && pData.core->nLength == 0) ) | 748 | if( (core->nLength == 0 && pData.core->nLength == 0) ) |
| 749 | return true; | 749 | return true; |
| 750 | if( core->nLength != pData.core->nLength ) | 750 | if( core->nLength != pData.core->nLength ) |
| 751 | return false; | 751 | return false; |
| 752 | if( pData.core->pFirst == NULL || core->pFirst == NULL ) | 752 | if( pData.core->pFirst == NULL || core->pFirst == NULL ) |
| 753 | return false; | 753 | return false; |
| 754 | 754 | ||
| 755 | flatten(); | 755 | flatten(); |
| 756 | pData.flatten(); | 756 | pData.flatten(); |
| 757 | const char *a = pData.core->pFirst->pData; | 757 | const char *a = pData.core->pFirst->pData; |
| 758 | char *b = core->pFirst->pData; | 758 | char *b = core->pFirst->pData; |
| 759 | for( long j = 0; j < core->nLength; j++, a++, b++ ) | 759 | for( long j = 0; j < core->nLength; j++, a++, b++ ) |
| 760 | { | 760 | { |
| 761 | if( *a != *b ) | 761 | if( *a != *b ) |
| 762 | return false; | 762 | return false; |
| 763 | } | 763 | } |
| 764 | 764 | ||
| 765 | return true; | 765 | return true; |
| 766 | } | 766 | } |
| 767 | 767 | ||
| 768 | bool Bu::String::operator!=(const char *pData ) const | 768 | bool Bu::String::operator!=(const char *pData ) const |
| 769 | { | 769 | { |
| 770 | return !(*this == pData); | 770 | return !(*this == pData); |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | bool Bu::String::operator!=(const String &pData ) const | 773 | bool Bu::String::operator!=(const String &pData ) const |
| 774 | { | 774 | { |
| 775 | return !(*this == pData); | 775 | return !(*this == pData); |
| 776 | } | 776 | } |
| 777 | 777 | ||
| 778 | bool Bu::String::operator<(const String &pData ) const | 778 | bool Bu::String::operator<(const String &pData ) const |
| 779 | { | 779 | { |
| 780 | flatten(); | 780 | flatten(); |
| 781 | pData.flatten(); | 781 | pData.flatten(); |
| 782 | 782 | ||
| 783 | const char *a = core->pFirst->pData; | 783 | const char *a = core->pFirst->pData; |
| 784 | char *b = pData.core->pFirst->pData; | 784 | char *b = pData.core->pFirst->pData; |
| 785 | for( long j = 0; j < core->nLength; j++, a++, b++ ) | 785 | for( long j = 0; j < core->nLength; j++, a++, b++ ) |
| 786 | { | 786 | { |
| 787 | if( *a != *b ) | 787 | if( *a != *b ) |
| 788 | return *a < *b; | 788 | return *a < *b; |
| 789 | } | 789 | } |
| 790 | 790 | ||
| 791 | return false; | 791 | return false; |
| 792 | } | 792 | } |
| 793 | 793 | ||
| 794 | bool Bu::String::operator<=(const String &pData ) const | 794 | bool Bu::String::operator<=(const String &pData ) const |
| 795 | { | 795 | { |
| 796 | flatten(); | 796 | flatten(); |
| 797 | pData.flatten(); | 797 | pData.flatten(); |
| 798 | 798 | ||
| 799 | const char *a = core->pFirst->pData; | 799 | const char *a = core->pFirst->pData; |
| 800 | char *b = pData.core->pFirst->pData; | 800 | char *b = pData.core->pFirst->pData; |
| 801 | for( long j = 0; j < core->nLength; j++, a++, b++ ) | 801 | for( long j = 0; j < core->nLength; j++, a++, b++ ) |
| 802 | { | 802 | { |
| 803 | if( *a != *b ) | 803 | if( *a != *b ) |
| 804 | return *a < *b; | 804 | return *a < *b; |
| 805 | } | 805 | } |
| 806 | 806 | ||
| 807 | return true; | 807 | return true; |
| 808 | } | 808 | } |
| 809 | 809 | ||
| 810 | bool Bu::String::operator>(const String &pData ) const | 810 | bool Bu::String::operator>(const String &pData ) const |
| 811 | { | 811 | { |
| 812 | flatten(); | 812 | flatten(); |
| 813 | pData.flatten(); | 813 | pData.flatten(); |
| 814 | 814 | ||
| 815 | const char *a = core->pFirst->pData; | 815 | const char *a = core->pFirst->pData; |
| 816 | char *b = pData.core->pFirst->pData; | 816 | char *b = pData.core->pFirst->pData; |
| 817 | for( long j = 0; j < core->nLength; j++, a++, b++ ) | 817 | for( long j = 0; j < core->nLength; j++, a++, b++ ) |
| 818 | { | 818 | { |
| 819 | if( *a != *b ) | 819 | if( *a != *b ) |
| 820 | return *a > *b; | 820 | return *a > *b; |
| 821 | } | 821 | } |
| 822 | 822 | ||
| 823 | return false; | 823 | return false; |
| 824 | } | 824 | } |
| 825 | 825 | ||
| 826 | bool Bu::String::operator>=(const String &pData ) const | 826 | bool Bu::String::operator>=(const String &pData ) const |
| 827 | { | 827 | { |
| 828 | flatten(); | 828 | flatten(); |
| 829 | pData.flatten(); | 829 | pData.flatten(); |
| 830 | 830 | ||
| 831 | const char *a = core->pFirst->pData; | 831 | const char *a = core->pFirst->pData; |
| 832 | char *b = pData.core->pFirst->pData; | 832 | char *b = pData.core->pFirst->pData; |
| 833 | for( long j = 0; j < core->nLength; j++, a++, b++ ) | 833 | for( long j = 0; j < core->nLength; j++, a++, b++ ) |
| 834 | { | 834 | { |
| 835 | if( *a != *b ) | 835 | if( *a != *b ) |
| 836 | return *a > *b; | 836 | return *a > *b; |
| 837 | } | 837 | } |
| 838 | 838 | ||
| 839 | return true; | 839 | return true; |
| 840 | } | 840 | } |
| 841 | 841 | ||
| 842 | char &Bu::String::operator[]( long nIndex ) | 842 | char &Bu::String::operator[]( long nIndex ) |
| 843 | { | 843 | { |
| 844 | if( nIndex < 0 || nIndex >= core->nLength ) | 844 | if( nIndex < 0 || nIndex >= core->nLength ) |
| 845 | throw Bu::ExceptionBase("Index out of range."); | 845 | throw Bu::ExceptionBase("Index out of range."); |
| 846 | flatten(); | 846 | flatten(); |
| 847 | _hardCopy(); | 847 | _hardCopy(); |
| 848 | 848 | ||
| 849 | return core->pFirst->pData[nIndex]; | 849 | return core->pFirst->pData[nIndex]; |
| 850 | } | 850 | } |
| 851 | 851 | ||
| 852 | const char &Bu::String::operator[]( long nIndex ) const | 852 | const char &Bu::String::operator[]( long nIndex ) const |
| 853 | { | 853 | { |
| 854 | if( nIndex < 0 || nIndex >= core->nLength ) | 854 | if( nIndex < 0 || nIndex >= core->nLength ) |
| 855 | throw Bu::ExceptionBase("Index out of range."); | 855 | throw Bu::ExceptionBase("Index out of range."); |
| 856 | flatten(); | 856 | flatten(); |
| 857 | 857 | ||
| 858 | return core->pFirst->pData[nIndex]; | 858 | return core->pFirst->pData[nIndex]; |
| 859 | } | 859 | } |
| 860 | 860 | ||
| 861 | bool Bu::String::isSet() const | 861 | bool Bu::String::isSet() const |
| 862 | { | 862 | { |
| 863 | return (core->pFirst != NULL); | 863 | return (core->pFirst != NULL); |
| 864 | } | 864 | } |
| 865 | 865 | ||
| 866 | bool Bu::String::compareSub( const char *pData, long nIndex, long nLen ) const | 866 | bool Bu::String::compareSub( const char *pData, long nIndex, long nLen ) const |
| 867 | { | 867 | { |
| 868 | if( core->pFirst == NULL || core->nLength == 0 ) { | 868 | if( core->pFirst == NULL || core->nLength == 0 ) { |
| 869 | if( pData == NULL ) | 869 | if( pData == NULL ) |
| 870 | return true; | 870 | return true; |
| 871 | if( nLen == 0 ) | 871 | if( nLen == 0 ) |
| 872 | return true; | 872 | return true; |
| 873 | if( pData[0] == (char)0 ) | 873 | if( pData[0] == (char)0 ) |
| 874 | return true; | 874 | return true; |
| 875 | return false; | 875 | return false; |
| 876 | } | 876 | } |
| 877 | if( nIndex+nLen > core->nLength ) | 877 | if( nIndex+nLen > core->nLength ) |
| 878 | return false; | 878 | return false; |
| 879 | 879 | ||
| 880 | flatten(); | 880 | flatten(); |
| 881 | core->pFirst->pData[core->nLength] = (char)0; | 881 | core->pFirst->pData[core->nLength] = (char)0; |
| 882 | const char *a = pData; | 882 | const char *a = pData; |
| 883 | char *b = core->pFirst->pData+nIndex; | 883 | char *b = core->pFirst->pData+nIndex; |
| 884 | for( long j = 0; j < nLen; j++, a++, b++ ) | 884 | for( long j = 0; j < nLen; j++, a++, b++ ) |
| 885 | { | 885 | { |
| 886 | if( *a != *b ) | 886 | if( *a != *b ) |
| 887 | return false; | 887 | return false; |
| 888 | if( *a == (char)0 && j < core->nLength ) | 888 | if( *a == (char)0 && j < core->nLength ) |
| 889 | return false; | 889 | return false; |
| 890 | } | 890 | } |
| 891 | 891 | ||
| 892 | return true; | 892 | return true; |
| 893 | } | 893 | } |
| 894 | 894 | ||
| 895 | bool Bu::String::compareSub( const String &rData, long nIndex, long nLen ) const | 895 | bool Bu::String::compareSub( const String &rData, long nIndex, long nLen ) const |
| 896 | { | 896 | { |
| 897 | if( core->pFirst == NULL || core->nLength == 0 || rData.core->pFirst == NULL || rData.core->nLength == 0 ) | 897 | if( core->pFirst == NULL || core->nLength == 0 || rData.core->pFirst == NULL || rData.core->nLength == 0 ) |
| 898 | return false; | 898 | return false; |
| 899 | if( nLen < 0 ) | 899 | if( nLen < 0 ) |
| 900 | nLen = rData.core->nLength; | 900 | nLen = rData.core->nLength; |
| 901 | if( nIndex+nLen > core->nLength ) | 901 | if( nIndex+nLen > core->nLength ) |
| 902 | return false; | 902 | return false; |
| 903 | 903 | ||
| 904 | flatten(); | 904 | flatten(); |
| 905 | rData.flatten(); | 905 | rData.flatten(); |
| 906 | const char *a = rData.core->pFirst->pData; | 906 | const char *a = rData.core->pFirst->pData; |
| 907 | char *b = core->pFirst->pData + nIndex; | 907 | char *b = core->pFirst->pData + nIndex; |
| 908 | for( long j = 0; j < nLen; j++, a++, b++ ) | 908 | for( long j = 0; j < nLen; j++, a++, b++ ) |
| 909 | { | 909 | { |
| 910 | if( *a != *b ) | 910 | if( *a != *b ) |
| 911 | return false; | 911 | return false; |
| 912 | } | 912 | } |
| 913 | 913 | ||
| 914 | return true; | 914 | return true; |
| 915 | } | 915 | } |
| 916 | 916 | ||
| 917 | bool Bu::String::isWS( long nIndex ) const | 917 | bool Bu::String::isWS( long nIndex ) const |
| 918 | { | 918 | { |
| 919 | flatten(); | 919 | flatten(); |
| 920 | 920 | ||
| 921 | return core->pFirst->pData[nIndex]==' ' || core->pFirst->pData[nIndex]=='\t' | 921 | return core->pFirst->pData[nIndex]==' ' || core->pFirst->pData[nIndex]=='\t' |
| 922 | || core->pFirst->pData[nIndex]=='\r' || core->pFirst->pData[nIndex]=='\n'; | 922 | || core->pFirst->pData[nIndex]=='\r' || core->pFirst->pData[nIndex]=='\n'; |
| 923 | } | 923 | } |
| 924 | 924 | ||
| 925 | bool Bu::String::isAlpha( long nIndex ) const | 925 | bool Bu::String::isAlpha( long nIndex ) const |
| 926 | { | 926 | { |
| 927 | flatten(); | 927 | flatten(); |
| 928 | 928 | ||
| 929 | return (core->pFirst->pData[nIndex] >= 'a' && core->pFirst->pData[nIndex] <= 'z') | 929 | return (core->pFirst->pData[nIndex] >= 'a' && core->pFirst->pData[nIndex] <= 'z') |
| 930 | || (core->pFirst->pData[nIndex] >= 'A' && core->pFirst->pData[nIndex] <= 'Z'); | 930 | || (core->pFirst->pData[nIndex] >= 'A' && core->pFirst->pData[nIndex] <= 'Z'); |
| 931 | } | 931 | } |
| 932 | 932 | ||
| 933 | Bu::String Bu::String::toLower() const | 933 | Bu::String Bu::String::toLower() const |
| 934 | { | 934 | { |
| 935 | Bu::String sRet = *this; | 935 | Bu::String sRet = *this; |
| 936 | 936 | ||
| 937 | sRet.flatten(); | 937 | sRet.flatten(); |
| 938 | sRet._hardCopy(); | 938 | sRet._hardCopy(); |
| 939 | 939 | ||
| 940 | for( long j = 0; j < sRet.core->nLength; j++ ) | 940 | for( long j = 0; j < sRet.core->nLength; j++ ) |
| 941 | { | 941 | { |
| 942 | if( sRet.core->pFirst->pData[j] >= 'A' && | 942 | if( sRet.core->pFirst->pData[j] >= 'A' && |
| 943 | sRet.core->pFirst->pData[j] <= 'Z' ) | 943 | sRet.core->pFirst->pData[j] <= 'Z' ) |
| 944 | sRet.core->pFirst->pData[j] -= 'A'-'a'; | 944 | sRet.core->pFirst->pData[j] -= 'A'-'a'; |
| 945 | } | 945 | } |
| 946 | 946 | ||
| 947 | return sRet; | 947 | return sRet; |
| 948 | } | 948 | } |
| 949 | 949 | ||
| 950 | Bu::String Bu::String::toUpper() const | 950 | Bu::String Bu::String::toUpper() const |
| 951 | { | 951 | { |
| 952 | Bu::String sRet = *this; | 952 | Bu::String sRet = *this; |
| 953 | 953 | ||
| 954 | sRet.flatten(); | 954 | sRet.flatten(); |
| 955 | sRet._hardCopy(); | 955 | sRet._hardCopy(); |
| 956 | 956 | ||
| 957 | for( long j = 0; j < sRet.core->nLength; j++ ) | 957 | for( long j = 0; j < sRet.core->nLength; j++ ) |
| 958 | { | 958 | { |
| 959 | if( sRet.core->pFirst->pData[j] >= 'a' && | 959 | if( sRet.core->pFirst->pData[j] >= 'a' && |
| 960 | sRet.core->pFirst->pData[j] <= 'z' ) | 960 | sRet.core->pFirst->pData[j] <= 'z' ) |
| 961 | sRet.core->pFirst->pData[j] += 'A'-'a'; | 961 | sRet.core->pFirst->pData[j] += 'A'-'a'; |
| 962 | } | 962 | } |
| 963 | 963 | ||
| 964 | return sRet; | 964 | return sRet; |
| 965 | } | 965 | } |
| 966 | 966 | ||
| 967 | Bu::String::const_iterator Bu::String::find( const char cChar, | 967 | Bu::String::const_iterator Bu::String::find( const char cChar, |
| 968 | Bu::String::const_iterator iStart ) const | 968 | Bu::String::const_iterator iStart ) const |
| 969 | { | 969 | { |
| 970 | if( !iStart ) iStart = begin(); | 970 | if( !iStart ) iStart = begin(); |
| 971 | for( ; iStart; iStart++ ) | 971 | for( ; iStart; iStart++ ) |
| 972 | { | 972 | { |
| 973 | if( cChar == *iStart ) | 973 | if( cChar == *iStart ) |
| 974 | return iStart; | 974 | return iStart; |
| 975 | } | 975 | } |
| 976 | return end(); | 976 | return end(); |
| 977 | } | 977 | } |
| 978 | 978 | ||
| 979 | Bu::String::const_iterator Bu::String::find( const char *sText, int nLen, | 979 | Bu::String::const_iterator Bu::String::find( const char *sText, int nLen, |
| 980 | Bu::String::const_iterator iStart ) const | 980 | Bu::String::const_iterator iStart ) const |
| 981 | { | 981 | { |
| 982 | if( !iStart ) iStart = begin(); | 982 | if( !iStart ) iStart = begin(); |
| 983 | for( ; iStart; iStart++ ) | 983 | for( ; iStart; iStart++ ) |
| 984 | { | 984 | { |
| 985 | if( iStart.compare( sText, nLen ) ) | 985 | if( iStart.compare( sText, nLen ) ) |
| 986 | return iStart; | 986 | return iStart; |
| 987 | } | 987 | } |
| 988 | return end(); | 988 | return end(); |
| 989 | } | 989 | } |
| 990 | 990 | ||
| 991 | Bu::String::const_iterator Bu::String::find( const String &rStr, | 991 | Bu::String::const_iterator Bu::String::find( const String &rStr, |
| 992 | Bu::String::const_iterator iStart ) const | 992 | Bu::String::const_iterator iStart ) const |
| 993 | { | 993 | { |
| 994 | if( !iStart ) iStart = begin(); | 994 | if( !iStart ) iStart = begin(); |
| 995 | for( ; iStart; iStart++ ) | 995 | for( ; iStart; iStart++ ) |
| 996 | { | 996 | { |
| 997 | if( iStart.compare( rStr ) ) | 997 | if( iStart.compare( rStr ) ) |
| 998 | return iStart; | 998 | return iStart; |
| 999 | } | 999 | } |
| 1000 | return end(); | 1000 | return end(); |
| 1001 | } | 1001 | } |
| 1002 | 1002 | ||
| 1003 | Bu::String::const_iterator Bu::String::find( const String &rStr, int nLen, | 1003 | Bu::String::const_iterator Bu::String::find( const String &rStr, int nLen, |
| 1004 | Bu::String::const_iterator iStart ) const | 1004 | Bu::String::const_iterator iStart ) const |
| 1005 | { | 1005 | { |
| 1006 | if( !iStart ) iStart = begin(); | 1006 | if( !iStart ) iStart = begin(); |
| 1007 | for( ; iStart; iStart++ ) | 1007 | for( ; iStart; iStart++ ) |
| 1008 | { | 1008 | { |
| 1009 | if( iStart.compare( rStr, nLen ) ) | 1009 | if( iStart.compare( rStr, nLen ) ) |
| 1010 | return iStart; | 1010 | return iStart; |
| 1011 | } | 1011 | } |
| 1012 | return end(); | 1012 | return end(); |
| 1013 | } | 1013 | } |
| 1014 | 1014 | ||
| 1015 | Bu::String::iterator Bu::String::find( const char cChar, | 1015 | Bu::String::iterator Bu::String::find( const char cChar, |
| 1016 | Bu::String::const_iterator iStart ) | 1016 | Bu::String::const_iterator iStart ) |
| 1017 | { | 1017 | { |
| 1018 | if( !iStart ) iStart = begin(); | 1018 | if( !iStart ) iStart = begin(); |
| 1019 | for( ; iStart; iStart++ ) | 1019 | for( ; iStart; iStart++ ) |
| 1020 | { | 1020 | { |
| 1021 | if( cChar == *iStart ) | 1021 | if( cChar == *iStart ) |
| 1022 | return iterator( iStart.pChunk, iStart.iPos ); | 1022 | return iterator( iStart.pChunk, iStart.iPos ); |
| 1023 | } | 1023 | } |
| 1024 | return end(); | 1024 | return end(); |
| 1025 | } | 1025 | } |
| 1026 | 1026 | ||
| 1027 | Bu::String::iterator Bu::String::find( const char *sText, int nLen, | 1027 | Bu::String::iterator Bu::String::find( const char *sText, int nLen, |
| 1028 | Bu::String::const_iterator iStart ) | 1028 | Bu::String::const_iterator iStart ) |
| 1029 | { | 1029 | { |
| 1030 | if( !iStart ) iStart = begin(); | 1030 | if( !iStart ) iStart = begin(); |
| 1031 | for( ; iStart; iStart++ ) | 1031 | for( ; iStart; iStart++ ) |
| 1032 | { | 1032 | { |
| 1033 | if( iStart.compare( sText, nLen ) ) | 1033 | if( iStart.compare( sText, nLen ) ) |
| 1034 | return iterator( iStart.pChunk, iStart.iPos ); | 1034 | return iterator( iStart.pChunk, iStart.iPos ); |
| 1035 | } | 1035 | } |
| 1036 | return end(); | 1036 | return end(); |
| 1037 | } | 1037 | } |
| 1038 | 1038 | ||
| 1039 | Bu::String::iterator Bu::String::find( const String &rStr, | 1039 | Bu::String::iterator Bu::String::find( const String &rStr, |
| 1040 | Bu::String::const_iterator iStart ) | 1040 | Bu::String::const_iterator iStart ) |
| 1041 | { | 1041 | { |
| 1042 | if( !iStart ) iStart = begin(); | 1042 | if( !iStart ) iStart = begin(); |
| 1043 | for( ; iStart; iStart++ ) | 1043 | for( ; iStart; iStart++ ) |
| 1044 | { | 1044 | { |
| 1045 | if( iStart.compare( rStr ) ) | 1045 | if( iStart.compare( rStr ) ) |
| 1046 | return iterator( iStart.pChunk, iStart.iPos ); | 1046 | return iterator( iStart.pChunk, iStart.iPos ); |
| 1047 | } | 1047 | } |
| 1048 | return end(); | 1048 | return end(); |
| 1049 | } | 1049 | } |
| 1050 | 1050 | ||
| 1051 | Bu::String::iterator Bu::String::find( const String &rStr, int nLen, | 1051 | Bu::String::iterator Bu::String::find( const String &rStr, int nLen, |
| 1052 | Bu::String::const_iterator iStart ) | 1052 | Bu::String::const_iterator iStart ) |
| 1053 | { | 1053 | { |
| 1054 | if( !iStart ) iStart = begin(); | 1054 | if( !iStart ) iStart = begin(); |
| 1055 | for( ; iStart; iStart++ ) | 1055 | for( ; iStart; iStart++ ) |
| 1056 | { | 1056 | { |
| 1057 | if( iStart.compare( rStr, nLen ) ) | 1057 | if( iStart.compare( rStr, nLen ) ) |
| 1058 | return iterator( iStart.pChunk, iStart.iPos ); | 1058 | return iterator( iStart.pChunk, iStart.iPos ); |
| 1059 | } | 1059 | } |
| 1060 | return end(); | 1060 | return end(); |
| 1061 | } | 1061 | } |
| 1062 | 1062 | ||
| 1063 | long Bu::String::findIdx( const char cChar, long iStart ) const | 1063 | long Bu::String::findIdx( const char cChar, long iStart ) const |
| 1064 | { | 1064 | { |
| 1065 | flatten(); | 1065 | flatten(); |
| 1066 | for( long j = iStart; j < core->pFirst->nLength; j++ ) | 1066 | for( long j = iStart; j < core->pFirst->nLength; j++ ) |
| 1067 | { | 1067 | { |
| 1068 | if( core->pFirst->pData[j] == cChar ) | 1068 | if( core->pFirst->pData[j] == cChar ) |
| 1069 | return j; | 1069 | return j; |
| 1070 | } | 1070 | } |
| 1071 | return -1; | 1071 | return -1; |
| 1072 | } | 1072 | } |
| 1073 | 1073 | ||
| 1074 | long Bu::String::findIdx( const char *sText, long iStart ) const | 1074 | long Bu::String::findIdx( const char *sText, long iStart ) const |
| 1075 | { | 1075 | { |
| 1076 | long nTLen = strlen( sText ); | 1076 | long nTLen = strlen( sText ); |
| 1077 | flatten(); | 1077 | flatten(); |
| 1078 | for( long j = iStart; j < core->pFirst->nLength-nTLen; j++ ) | 1078 | for( long j = iStart; j < core->pFirst->nLength-nTLen; j++ ) |
| 1079 | { | 1079 | { |
| 1080 | if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) | 1080 | if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) |
| 1081 | return j; | 1081 | return j; |
| 1082 | } | 1082 | } |
| 1083 | return -1; | 1083 | return -1; |
| 1084 | } | 1084 | } |
| 1085 | 1085 | ||
| 1086 | long Bu::String::rfindIdx( const char *sText ) const | 1086 | long Bu::String::rfindIdx( const char *sText ) const |
| 1087 | { | 1087 | { |
| 1088 | long nTLen = strlen( sText ); | 1088 | long nTLen = strlen( sText ); |
| 1089 | flatten(); | 1089 | flatten(); |
| 1090 | for( long j = core->pFirst->nLength-nTLen-1; j >= 0; j-- ) | 1090 | for( long j = core->pFirst->nLength-nTLen-1; j >= 0; j-- ) |
| 1091 | { | 1091 | { |
| 1092 | if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) | 1092 | if( !strncmp( sText, core->pFirst->pData+j, nTLen ) ) |
| 1093 | return j; | 1093 | return j; |
| 1094 | } | 1094 | } |
| 1095 | return -1; | 1095 | return -1; |
| 1096 | } | 1096 | } |
| 1097 | 1097 | ||
| 1098 | void Bu::String::trimFront( long nAmnt ) | 1098 | void Bu::String::trimFront( long nAmnt ) |
| 1099 | { | 1099 | { |
| 1100 | long nNewLen = core->nLength - nAmnt; | 1100 | long nNewLen = core->nLength - nAmnt; |
| 1101 | flatten(); | 1101 | flatten(); |
| 1102 | Chunk *pNew = core->newChunk( nNewLen ); | 1102 | Chunk *pNew = core->newChunk( nNewLen ); |
| 1103 | memcpy( pNew->pData, core->pFirst->pData+nAmnt, nNewLen ); | 1103 | memcpy( pNew->pData, core->pFirst->pData+nAmnt, nNewLen ); |
| 1104 | _hardCopy(); | 1104 | _hardCopy(); |
| 1105 | core->clear(); | 1105 | core->clear(); |
| 1106 | core->appendChunk( pNew ); | 1106 | core->appendChunk( pNew ); |
| 1107 | } | 1107 | } |
| 1108 | /* | 1108 | /* |
| 1109 | void Bu::String::trimBack( char c ) | 1109 | void Bu::String::trimBack( char c ) |
| 1110 | { | 1110 | { |
| 1111 | if( core->pFirst == NULL || core->nLength == 0 ) | 1111 | if( core->pFirst == NULL || core->nLength == 0 ) |
| 1112 | return; | 1112 | return; |
| 1113 | flatten(); | 1113 | flatten(); |
| 1114 | for( ; core->pFirst->nLength > 0 && | 1114 | for( ; core->pFirst->nLength > 0 && |
| 1115 | core->pFirst->pData[core->pFirst->nLength-1] == c; | 1115 | core->pFirst->pData[core->pFirst->nLength-1] == c; |
| 1116 | core->pFirst->nLength--, core->nLength-- ) { } | 1116 | core->pFirst->nLength--, core->nLength-- ) { } |
| 1117 | } | 1117 | } |
| 1118 | */ | 1118 | */ |
| 1119 | void Bu::String::trimBack( long iAmnt ) | 1119 | void Bu::String::trimBack( long iAmnt ) |
| 1120 | { | 1120 | { |
| 1121 | if( iAmnt < 0 ) | 1121 | if( iAmnt < 0 ) |
| 1122 | return; | 1122 | return; |
| 1123 | if( core->nLength - iAmnt < 0 ) | 1123 | if( core->nLength - iAmnt < 0 ) |
| 1124 | { | 1124 | { |
| 1125 | clear(); | 1125 | clear(); |
| 1126 | return; | 1126 | return; |
| 1127 | } | 1127 | } |
| 1128 | if( core->pFirst == NULL || core->nLength == 0 ) | 1128 | if( core->pFirst == NULL || core->nLength == 0 ) |
| 1129 | return; | 1129 | return; |
| 1130 | 1130 | ||
| 1131 | flatten(); | 1131 | flatten(); |
| 1132 | core->pFirst->nLength -= iAmnt; | 1132 | core->pFirst->nLength -= iAmnt; |
| 1133 | core->nLength -= iAmnt; | 1133 | core->nLength -= iAmnt; |
| 1134 | } | 1134 | } |
| 1135 | 1135 | ||
| 1136 | Bu::String Bu::String::trimWhitespace() const | 1136 | Bu::String Bu::String::trimWhitespace() const |
| 1137 | { | 1137 | { |
| 1138 | if( core->nLength == 0 ) | 1138 | if( core->nLength == 0 ) |
| 1139 | return ""; | 1139 | return ""; |
| 1140 | const_iterator i = begin(); | 1140 | const_iterator i = begin(); |
| 1141 | for( ; i && (*i == ' ' || *i == '\t' || *i == '\n' || *i == '\r'); i++ ) { } | 1141 | for( ; i && (*i == ' ' || *i == '\t' || *i == '\n' || *i == '\r'); i++ ) { } |
| 1142 | if( !i ) | 1142 | if( !i ) |
| 1143 | return ""; | 1143 | return ""; |
| 1144 | 1144 | ||
| 1145 | const_iterator e = i; | 1145 | const_iterator e = i; |
| 1146 | for( ; e; e++ ) | 1146 | for( ; e; e++ ) |
| 1147 | { | 1147 | { |
| 1148 | if( *e == ' ' || *e == '\t' || *e == '\n' || *e == '\r' ) | 1148 | if( *e == ' ' || *e == '\t' || *e == '\n' || *e == '\r' ) |
| 1149 | { | 1149 | { |
| 1150 | const_iterator t = e; | 1150 | const_iterator t = e; |
| 1151 | for( ; t && (*t == ' ' || *t == '\t' || *t == '\n' || *t == '\r'); t++ ) { } | 1151 | for( ; t && (*t == ' ' || *t == '\t' || *t == '\n' || *t == '\r'); t++ ) { } |
| 1152 | if( t ) | 1152 | if( t ) |
| 1153 | { | 1153 | { |
| 1154 | e = t; | 1154 | e = t; |
| 1155 | } | 1155 | } |
| 1156 | else | 1156 | else |
| 1157 | { | 1157 | { |
| 1158 | break; | 1158 | break; |
| 1159 | } | 1159 | } |
| 1160 | } | 1160 | } |
| 1161 | } | 1161 | } |
| 1162 | 1162 | ||
| 1163 | return Bu::String( i, e ); | 1163 | return Bu::String( i, e ); |
| 1164 | } | 1164 | } |
| 1165 | 1165 | ||
| 1166 | Bu::String::iterator Bu::String::begin() | 1166 | Bu::String::iterator Bu::String::begin() |
| 1167 | { | 1167 | { |
| 1168 | if( core->nLength == 0 ) | 1168 | if( core->nLength == 0 ) |
| 1169 | return iterator( NULL, 0 ); | 1169 | return iterator( NULL, 0 ); |
| 1170 | return iterator( core->pFirst, 0 ); | 1170 | return iterator( core->pFirst, 0 ); |
| 1171 | } | 1171 | } |
| 1172 | 1172 | ||
| 1173 | Bu::String::const_iterator Bu::String::begin() const | 1173 | Bu::String::const_iterator Bu::String::begin() const |
| 1174 | { | 1174 | { |
| 1175 | if( core->nLength == 0 ) | 1175 | if( core->nLength == 0 ) |
| 1176 | return const_iterator( NULL, 0 ); | 1176 | return const_iterator( NULL, 0 ); |
| 1177 | return iterator( core->pFirst, 0 ); | 1177 | return iterator( core->pFirst, 0 ); |
| 1178 | } | 1178 | } |
| 1179 | 1179 | ||
| 1180 | Bu::String::iterator Bu::String::end() | 1180 | Bu::String::iterator Bu::String::end() |
| 1181 | { | 1181 | { |
| 1182 | return iterator( NULL, 0 ); | 1182 | return iterator( NULL, 0 ); |
| 1183 | } | 1183 | } |
| 1184 | 1184 | ||
| 1185 | Bu::String::const_iterator Bu::String::end() const | 1185 | Bu::String::const_iterator Bu::String::end() const |
| 1186 | { | 1186 | { |
| 1187 | return const_iterator( NULL, 0 ); | 1187 | return const_iterator( NULL, 0 ); |
| 1188 | } | 1188 | } |
| 1189 | 1189 | ||
| 1190 | bool Bu::String::isEmpty() const | 1190 | bool Bu::String::isEmpty() const |
| 1191 | { | 1191 | { |
| 1192 | if( core->nLength == 0 ) | 1192 | if( core->nLength == 0 ) |
| 1193 | return true; | 1193 | return true; |
| 1194 | return false; | 1194 | return false; |
| 1195 | } | 1195 | } |
| 1196 | 1196 | ||
| 1197 | void Bu::String::flatten() const | 1197 | void Bu::String::flatten() const |
| 1198 | { | 1198 | { |
| 1199 | if( isFlat() ) | 1199 | if( isFlat() ) |
| 1200 | return; | 1200 | return; |
| 1201 | 1201 | ||
| 1202 | if( core->pFirst == NULL || core->nLength == 0 ) | 1202 | if( core->pFirst == NULL || core->nLength == 0 ) |
| 1203 | return; | 1203 | return; |
| 1204 | 1204 | ||
| 1205 | Chunk *pNew = core->newChunk( core->nLength ); | 1205 | Chunk *pNew = core->newChunk( core->nLength ); |
| 1206 | char *pos = pNew->pData; | 1206 | char *pos = pNew->pData; |
| 1207 | Chunk *i = core->pFirst; | 1207 | Chunk *i = core->pFirst; |
| 1208 | for(;;) | 1208 | for(;;) |
| 1209 | { | 1209 | { |
| 1210 | memcpy( pos, i->pData, i->nLength ); | 1210 | memcpy( pos, i->pData, i->nLength ); |
| 1211 | pos += i->nLength; | 1211 | pos += i->nLength; |
| 1212 | i = i->pNext; | 1212 | i = i->pNext; |
| 1213 | if( i == NULL ) | 1213 | if( i == NULL ) |
| 1214 | break; | 1214 | break; |
| 1215 | } | 1215 | } |
| 1216 | core->clear(); | 1216 | core->clear(); |
| 1217 | 1217 | ||
| 1218 | core->pLast = core->pFirst = pNew; | 1218 | core->pLast = core->pFirst = pNew; |
| 1219 | core->nLength = pNew->nLength; | 1219 | core->nLength = pNew->nLength; |
| 1220 | } | 1220 | } |
| 1221 | 1221 | ||
| 1222 | bool Bu::String::isFlat() const | 1222 | bool Bu::String::isFlat() const |
| 1223 | { | 1223 | { |
| 1224 | return (core->pFirst == core->pLast); | 1224 | return (core->pFirst == core->pLast); |
| 1225 | } | 1225 | } |
| 1226 | 1226 | ||
| 1227 | // | 1227 | // |
| @@ -1229,98 +1229,98 @@ bool Bu::String::isFlat() const | |||
| 1229 | // | 1229 | // |
| 1230 | 1230 | ||
| 1231 | Bu::String::FormatProxy::FormatProxy( const String &rFmt, | 1231 | Bu::String::FormatProxy::FormatProxy( const String &rFmt, |
| 1232 | String::FormatProxyEndAction *pAct ) : | 1232 | String::FormatProxyEndAction *pAct ) : |
| 1233 | rFmt( rFmt ), | 1233 | rFmt( rFmt ), |
| 1234 | pAct( pAct ), | 1234 | pAct( pAct ), |
| 1235 | bOpen( true ) | 1235 | bOpen( true ) |
| 1236 | { | 1236 | { |
| 1237 | } | 1237 | } |
| 1238 | 1238 | ||
| 1239 | Bu::String::FormatProxy::~FormatProxy() | 1239 | Bu::String::FormatProxy::~FormatProxy() |
| 1240 | { | 1240 | { |
| 1241 | if( pAct && bOpen ) | 1241 | if( pAct && bOpen ) |
| 1242 | end(); | 1242 | end(); |
| 1243 | 1243 | ||
| 1244 | delete pAct; | 1244 | delete pAct; |
| 1245 | } | 1245 | } |
| 1246 | 1246 | ||
| 1247 | Bu::String Bu::String::FormatProxy::end() const | 1247 | Bu::String Bu::String::FormatProxy::end() const |
| 1248 | { | 1248 | { |
| 1249 | int iCount = lArgs.getSize(); | 1249 | int iCount = lArgs.getSize(); |
| 1250 | ArgList::const_iterator *aArg = | 1250 | ArgList::const_iterator *aArg = |
| 1251 | new ArgList::const_iterator[iCount]; | 1251 | new ArgList::const_iterator[iCount]; |
| 1252 | { | 1252 | { |
| 1253 | int j = 0; | 1253 | int j = 0; |
| 1254 | for( ArgList::const_iterator i = lArgs.begin(); | 1254 | for( ArgList::const_iterator i = lArgs.begin(); |
| 1255 | i; i++, j++ ) | 1255 | i; i++, j++ ) |
| 1256 | { | 1256 | { |
| 1257 | aArg[j] = i; | 1257 | aArg[j] = i; |
| 1258 | } | 1258 | } |
| 1259 | } | 1259 | } |
| 1260 | Bu::MemBuf mbOut; | 1260 | Bu::MemBuf mbOut; |
| 1261 | Bu::Formatter f( mbOut ); | 1261 | Bu::Formatter f( mbOut ); |
| 1262 | for( String::const_iterator s = rFmt.begin(); s; ) | 1262 | for( String::const_iterator s = rFmt.begin(); s; ) |
| 1263 | { | 1263 | { |
| 1264 | if( *s == '%' ) | 1264 | if( *s == '%' ) |
| 1265 | { | 1265 | { |
| 1266 | s++; | 1266 | s++; |
| 1267 | if( *s == '%' ) | 1267 | if( *s == '%' ) |
| 1268 | f << *s; | 1268 | f << *s; |
| 1269 | else | 1269 | else |
| 1270 | { | 1270 | { |
| 1271 | String sNum; | 1271 | String sNum; |
| 1272 | if( *s == '{' ) | 1272 | if( *s == '{' ) |
| 1273 | { | 1273 | { |
| 1274 | s++; | 1274 | s++; |
| 1275 | while( s && *s >= '0' && *s <= '9' ) | 1275 | while( s && *s >= '0' && *s <= '9' ) |
| 1276 | { | 1276 | { |
| 1277 | sNum += *s; | 1277 | sNum += *s; |
| 1278 | s++; | 1278 | s++; |
| 1279 | } | 1279 | } |
| 1280 | if( !s || *s != '}' ) | 1280 | if( !s || *s != '}' ) |
| 1281 | { | 1281 | { |
| 1282 | delete[] aArg; | 1282 | delete[] aArg; |
| 1283 | throw Bu::ExceptionBase( | 1283 | throw Bu::ExceptionBase( |
| 1284 | "Argument started with a '{' but terminated " | 1284 | "Argument started with a '{' but terminated " |
| 1285 | "with a '%c' instead of '}'.", *s ); | 1285 | "with a '%c' instead of '}'.", *s ); |
| 1286 | } | 1286 | } |
| 1287 | s++; | 1287 | s++; |
| 1288 | } | 1288 | } |
| 1289 | else | 1289 | else |
| 1290 | { | 1290 | { |
| 1291 | while( s && *s >= '0' && *s <= '9' ) | 1291 | while( s && *s >= '0' && *s <= '9' ) |
| 1292 | { | 1292 | { |
| 1293 | sNum += *s; | 1293 | sNum += *s; |
| 1294 | s++; | 1294 | s++; |
| 1295 | } | 1295 | } |
| 1296 | } | 1296 | } |
| 1297 | int iIndex = strtol( sNum.getStr(), 0, 10 )-1; | 1297 | int iIndex = strtol( sNum.getStr(), 0, 10 )-1; |
| 1298 | if( iIndex < 0 || iIndex >= iCount ) | 1298 | if( iIndex < 0 || iIndex >= iCount ) |
| 1299 | { | 1299 | { |
| 1300 | delete[] aArg; | 1300 | delete[] aArg; |
| 1301 | throw Bu::ExceptionBase( | 1301 | throw Bu::ExceptionBase( |
| 1302 | "Argument index %d is outside of " | 1302 | "Argument index %d is outside of " |
| 1303 | "valid range (1-%d).", iIndex+1, iCount | 1303 | "valid range (1-%d).", iIndex+1, iCount |
| 1304 | ); | 1304 | ); |
| 1305 | } | 1305 | } |
| 1306 | 1306 | ||
| 1307 | f << (*aArg[iIndex]).format << (*aArg[iIndex]).value; | 1307 | f << (*aArg[iIndex]).format << (*aArg[iIndex]).value; |
| 1308 | continue; | 1308 | continue; |
| 1309 | } | 1309 | } |
| 1310 | } | 1310 | } |
| 1311 | else | 1311 | else |
| 1312 | { | 1312 | { |
| 1313 | f << *s; | 1313 | f << *s; |
| 1314 | } | 1314 | } |
| 1315 | s++; | 1315 | s++; |
| 1316 | } | 1316 | } |
| 1317 | 1317 | ||
| 1318 | bOpen = false; | 1318 | bOpen = false; |
| 1319 | delete[] aArg; | 1319 | delete[] aArg; |
| 1320 | 1320 | ||
| 1321 | if( pAct ) | 1321 | if( pAct ) |
| 1322 | (*pAct)( mbOut.getString() ); | 1322 | (*pAct)( mbOut.getString() ); |
| 1323 | return mbOut.getString(); | 1323 | return mbOut.getString(); |
| 1324 | } | 1324 | } |
| 1325 | 1325 | ||
| 1326 | 1326 | ||
| @@ -1371,131 +1371,131 @@ Bu::String Bu::String::FormatProxy::end() const | |||
| 1371 | 1371 | ||
| 1372 | template<> uint32_t Bu::__calcHashCode<Bu::String>( const Bu::String &k ) | 1372 | template<> uint32_t Bu::__calcHashCode<Bu::String>( const Bu::String &k ) |
| 1373 | { | 1373 | { |
| 1374 | long j, sz = k.getSize(); | 1374 | long j, sz = k.getSize(); |
| 1375 | const char *s = k.getStr(); | 1375 | const char *s = k.getStr(); |
| 1376 | 1376 | ||
| 1377 | long nPos = 0; | 1377 | long nPos = 0; |
| 1378 | for( j = 0; j < sz; j++, s++ ) | 1378 | for( j = 0; j < sz; j++, s++ ) |
| 1379 | { | 1379 | { |
| 1380 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; | 1380 | nPos = *s + (nPos << 6) + (nPos << 16) - nPos; |
| 1381 | } | 1381 | } |
| 1382 | 1382 | ||
| 1383 | return nPos; | 1383 | return nPos; |
| 1384 | } | 1384 | } |
| 1385 | 1385 | ||
| 1386 | template<> bool Bu::__cmpHashKeys<Bu::String>( | 1386 | template<> bool Bu::__cmpHashKeys<Bu::String>( |
| 1387 | const Bu::String &a, const Bu::String &b ) | 1387 | const Bu::String &a, const Bu::String &b ) |
| 1388 | { | 1388 | { |
| 1389 | return a == b; | 1389 | return a == b; |
| 1390 | } | 1390 | } |
| 1391 | 1391 | ||
| 1392 | template<> void Bu::__tracer_format<Bu::String>( const Bu::String &v ) | 1392 | template<> void Bu::__tracer_format<Bu::String>( const Bu::String &v ) |
| 1393 | { | 1393 | { |
| 1394 | printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); | 1394 | printf("(%ld)\"%s\"", v.getSize(), v.getStr() ); |
| 1395 | } | 1395 | } |
| 1396 | 1396 | ||
| 1397 | bool &Bu::operator<<( bool &dst, const Bu::String &sIn ) | 1397 | bool &Bu::operator<<( bool &dst, const Bu::String &sIn ) |
| 1398 | { | 1398 | { |
| 1399 | if( sIn == "true" || sIn == "yes" || sIn == "t" ) | 1399 | if( sIn == "true" || sIn == "yes" || sIn == "t" ) |
| 1400 | dst = true; | 1400 | dst = true; |
| 1401 | else | 1401 | else |
| 1402 | dst = false; | 1402 | dst = false; |
| 1403 | 1403 | ||
| 1404 | return dst; | 1404 | return dst; |
| 1405 | } | 1405 | } |
| 1406 | 1406 | ||
| 1407 | uint8_t &Bu::operator<<( uint8_t &dst, const Bu::String &sIn ) | 1407 | uint8_t &Bu::operator<<( uint8_t &dst, const Bu::String &sIn ) |
| 1408 | { | 1408 | { |
| 1409 | sscanf( sIn.getStr(), "%hhu", &dst ); | 1409 | sscanf( sIn.getStr(), "%hhu", &dst ); |
| 1410 | return dst; | 1410 | return dst; |
| 1411 | } | 1411 | } |
| 1412 | 1412 | ||
| 1413 | int8_t &Bu::operator<<( int8_t &dst, const Bu::String &sIn ) | 1413 | int8_t &Bu::operator<<( int8_t &dst, const Bu::String &sIn ) |
| 1414 | { | 1414 | { |
| 1415 | sscanf( sIn.getStr(), "%hhd", &dst ); | 1415 | sscanf( sIn.getStr(), "%hhd", &dst ); |
| 1416 | return dst; | 1416 | return dst; |
| 1417 | } | 1417 | } |
| 1418 | 1418 | ||
| 1419 | char &Bu::operator<<( char &dst, const Bu::String &sIn ) | 1419 | char &Bu::operator<<( char &dst, const Bu::String &sIn ) |
| 1420 | { | 1420 | { |
| 1421 | sscanf( sIn.getStr(), "%hhd", &dst ); | 1421 | sscanf( sIn.getStr(), "%hhd", &dst ); |
| 1422 | return dst; | 1422 | return dst; |
| 1423 | } | 1423 | } |
| 1424 | 1424 | ||
| 1425 | uint16_t &Bu::operator<<( uint16_t &dst, const Bu::String &sIn ) | 1425 | uint16_t &Bu::operator<<( uint16_t &dst, const Bu::String &sIn ) |
| 1426 | { | 1426 | { |
| 1427 | sscanf( sIn.getStr(), "%hu", &dst ); | 1427 | sscanf( sIn.getStr(), "%hu", &dst ); |
| 1428 | return dst; | 1428 | return dst; |
| 1429 | } | 1429 | } |
| 1430 | 1430 | ||
| 1431 | int16_t &Bu::operator<<( int16_t &dst, const Bu::String &sIn ) | 1431 | int16_t &Bu::operator<<( int16_t &dst, const Bu::String &sIn ) |
| 1432 | { | 1432 | { |
| 1433 | sscanf( sIn.getStr(), "%hd", &dst ); | 1433 | sscanf( sIn.getStr(), "%hd", &dst ); |
| 1434 | return dst; | 1434 | return dst; |
| 1435 | } | 1435 | } |
| 1436 | 1436 | ||
| 1437 | uint32_t &Bu::operator<<( uint32_t &dst, const Bu::String &sIn ) | 1437 | uint32_t &Bu::operator<<( uint32_t &dst, const Bu::String &sIn ) |
| 1438 | { | 1438 | { |
| 1439 | sscanf( sIn.getStr(), "%u", &dst ); | 1439 | sscanf( sIn.getStr(), "%u", &dst ); |
| 1440 | return dst; | 1440 | return dst; |
| 1441 | } | 1441 | } |
| 1442 | 1442 | ||
| 1443 | int32_t &Bu::operator<<( int32_t &dst, const Bu::String &sIn ) | 1443 | int32_t &Bu::operator<<( int32_t &dst, const Bu::String &sIn ) |
| 1444 | { | 1444 | { |
| 1445 | sscanf( sIn.getStr(), "%d", &dst ); | 1445 | sscanf( sIn.getStr(), "%d", &dst ); |
| 1446 | return dst; | 1446 | return dst; |
| 1447 | } | 1447 | } |
| 1448 | 1448 | ||
| 1449 | uint64_t &Bu::operator<<( uint64_t &dst, const Bu::String &sIn ) | 1449 | uint64_t &Bu::operator<<( uint64_t &dst, const Bu::String &sIn ) |
| 1450 | { | 1450 | { |
| 1451 | sscanf( sIn.getStr(), "%llu", &dst ); | 1451 | sscanf( sIn.getStr(), "%llu", &dst ); |
| 1452 | return dst; | 1452 | return dst; |
| 1453 | } | 1453 | } |
| 1454 | 1454 | ||
| 1455 | int64_t &Bu::operator<<( int64_t &dst, const Bu::String &sIn ) | 1455 | int64_t &Bu::operator<<( int64_t &dst, const Bu::String &sIn ) |
| 1456 | { | 1456 | { |
| 1457 | sscanf( sIn.getStr(), "%lld", &dst ); | 1457 | sscanf( sIn.getStr(), "%lld", &dst ); |
| 1458 | return dst; | 1458 | return dst; |
| 1459 | } | 1459 | } |
| 1460 | 1460 | ||
| 1461 | float &Bu::operator<<( float &dst, const Bu::String &sIn ) | 1461 | float &Bu::operator<<( float &dst, const Bu::String &sIn ) |
| 1462 | { | 1462 | { |
| 1463 | sscanf( sIn.getStr(), "%f", &dst ); | 1463 | sscanf( sIn.getStr(), "%f", &dst ); |
| 1464 | return dst; | 1464 | return dst; |
| 1465 | } | 1465 | } |
| 1466 | 1466 | ||
| 1467 | double &Bu::operator<<( double &dst, const Bu::String &sIn ) | 1467 | double &Bu::operator<<( double &dst, const Bu::String &sIn ) |
| 1468 | { | 1468 | { |
| 1469 | sscanf( sIn.getStr(), "%lf", &dst ); | 1469 | sscanf( sIn.getStr(), "%lf", &dst ); |
| 1470 | return dst; | 1470 | return dst; |
| 1471 | } | 1471 | } |
| 1472 | 1472 | ||
| 1473 | long double &Bu::operator<<( long double &dst, const Bu::String &sIn ) | 1473 | long double &Bu::operator<<( long double &dst, const Bu::String &sIn ) |
| 1474 | { | 1474 | { |
| 1475 | sscanf( sIn.getStr(), "%Lf", &dst ); | 1475 | sscanf( sIn.getStr(), "%Lf", &dst ); |
| 1476 | return dst; | 1476 | return dst; |
| 1477 | } | 1477 | } |
| 1478 | 1478 | ||
| 1479 | Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn ) | 1479 | Bu::String &Bu::operator<<( Bu::String &dst, const Bu::String &sIn ) |
| 1480 | { | 1480 | { |
| 1481 | dst = sIn; | 1481 | dst = sIn; |
| 1482 | return dst; | 1482 | return dst; |
| 1483 | } | 1483 | } |
| 1484 | 1484 | ||
| 1485 | Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::String &s ) | 1485 | Bu::ArchiveBase &Bu::operator<<( Bu::ArchiveBase &ar, const Bu::String &s ) |
| 1486 | { | 1486 | { |
| 1487 | long n = s.getSize(); | 1487 | long n = s.getSize(); |
| 1488 | ar << n; | 1488 | ar << n; |
| 1489 | ar.write( s.getConstStr(), n ); | 1489 | ar.write( s.getConstStr(), n ); |
| 1490 | return ar; | 1490 | return ar; |
| 1491 | } | 1491 | } |
| 1492 | 1492 | ||
| 1493 | Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, Bu::String &s ) | 1493 | Bu::ArchiveBase &Bu::operator>>( Bu::ArchiveBase &ar, Bu::String &s ) |
| 1494 | { | 1494 | { |
| 1495 | long n; | 1495 | long n; |
| 1496 | ar >> n; | 1496 | ar >> n; |
| 1497 | s.setSize( n ); | 1497 | s.setSize( n ); |
| 1498 | ar.read( s.getStr(), n ); | 1498 | ar.read( s.getStr(), n ); |
| 1499 | return ar; | 1499 | return ar; |
| 1500 | } | 1500 | } |
| 1501 | 1501 | ||
