aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-11-24 00:15:26 +0000
committerMike Buland <eichlan@xagasoft.com>2007-11-24 00:15:26 +0000
commited402db706488ab910b7c810684379cc2d7b7662 (patch)
treef23f8ac4725f7b44e28e8f2a4c65302fe6aa0533
parentd09fbd451f492ab0df5c45f8205172b1035ce210 (diff)
downloadlibbu++-ed402db706488ab910b7c810684379cc2d7b7662.tar.gz
libbu++-ed402db706488ab910b7c810684379cc2d7b7662.tar.bz2
libbu++-ed402db706488ab910b7c810684379cc2d7b7662.tar.xz
libbu++-ed402db706488ab910b7c810684379cc2d7b7662.zip
Alright, *now* remove works.
Diffstat (limited to '')
-rw-r--r--src/fstring.h31
-rw-r--r--src/unit/fstring.cpp3
2 files changed, 19 insertions, 15 deletions
diff --git a/src/fstring.h b/src/fstring.h
index c1b377c..666480c 100644
--- a/src/fstring.h
+++ b/src/fstring.h
@@ -230,7 +230,6 @@ namespace Bu
230 { 230 {
231 if( nLen <= 0 ) 231 if( nLen <= 0 )
232 return; 232 return;
233 flatten();
234 if( nPos <= 0 ) 233 if( nPos <= 0 )
235 { 234 {
236 prepend( pData, nLen ); 235 prepend( pData, nLen );
@@ -241,6 +240,7 @@ namespace Bu
241 } 240 }
242 else 241 else
243 { 242 {
243 flatten();
244 Chunk *p1 = newChunk( nPos ); 244 Chunk *p1 = newChunk( nPos );
245 Chunk *p2 = newChunk( nLen ); 245 Chunk *p2 = newChunk( nLen );
246 Chunk *p3 = newChunk( nLength-nPos ); 246 Chunk *p3 = newChunk( nLength-nPos );
@@ -253,34 +253,34 @@ namespace Bu
253 appendChunk( p3 ); 253 appendChunk( p3 );
254 } 254 }
255 } 255 }
256 /* 256
257 void insert( long nPos, const MyType &str ) 257 void insert( long nPos, const MyType &str )
258 { 258 {
259 if( nLen <= 0 )
260 return;
261 flatten();
262 if( nPos <= 0 ) 259 if( nPos <= 0 )
263 { 260 {
264 prepend( pData, nLen ); 261 prepend( str );
265 } 262 }
266 else if( nPos >= nLength ) 263 else if( nPos >= nLength )
267 { 264 {
268 append( pData, nLen ); 265 append( str );
269 } 266 }
270 else 267 else
271 { 268 {
269 flatten();
272 Chunk *p1 = newChunk( nPos ); 270 Chunk *p1 = newChunk( nPos );
273 Chunk *p2 = newChunk( nLen );
274 Chunk *p3 = newChunk( nLength-nPos ); 271 Chunk *p3 = newChunk( nLength-nPos );
275 cpy( p1->pData, pFirst->pData, nPos ); 272 cpy( p1->pData, pFirst->pData, nPos );
276 cpy( p2->pData, pData, nLen );
277 cpy( p3->pData, pFirst->pData+nPos, nLength-nPos ); 273 cpy( p3->pData, pFirst->pData+nPos, nLength-nPos );
278 clear(); 274 clear();
279 appendChunk( p1 ); 275 appendChunk( p1 );
280 appendChunk( p2 ); 276 for( Chunk *pChnk = str->pFirst; pChnk; pChnk = pChnk->next )
277 {
278 appendChunk( copyChunk( pChnk ) );
279 }
280
281 appendChunk( p3 ); 281 appendChunk( p3 );
282 } 282 }
283 }*/ 283 }
284 284
285 void insert( long nPos, const chr *pData ) 285 void insert( long nPos, const chr *pData )
286 { 286 {
@@ -291,11 +291,12 @@ namespace Bu
291 { 291 {
292 if( nLen <= 0 || nPos < 0 || nPos >= nLength ) 292 if( nLen <= 0 || nPos < 0 || nPos >= nLength )
293 return; 293 return;
294 if( nLen >= nLength-nPos ) 294 if( nLen > nLength-nPos )
295 nLen = nLength-nPos-1; 295 nLen = nLength-nPos;
296 flatten(); 296 flatten();
297 cpy( pFirst->pData+nPos, pFirst->pData+nPos+nLen, nLength-nPos+1 ); 297 cpy( pFirst->pData+nPos, pFirst->pData+nPos+nLen, nLength-nPos-nLen+1 );
298 nLength -= nPos; 298 nLength -= nLen;
299 pFirst->nLength -= nLen;
299 } 300 }
300 301
301 /** 302 /**
diff --git a/src/unit/fstring.cpp b/src/unit/fstring.cpp
index 03df9c3..b00f11b 100644
--- a/src/unit/fstring.cpp
+++ b/src/unit/fstring.cpp
@@ -86,6 +86,9 @@ public:
86 unitTest( a == "abcd" ); 86 unitTest( a == "abcd" );
87 a.remove( 2, 5 ); 87 a.remove( 2, 5 );
88 unitTest( a == "ab" ); 88 unitTest( a == "ab" );
89 a += "cdefghijklmnop";
90 a.remove( 5, 1 );
91 unitTest( a = "abcdeghijklmnop" );
89 } 92 }
90}; 93};
91 94