diff options
Diffstat (limited to 'src/fstring.h')
-rw-r--r-- | src/fstring.h | 31 |
1 files changed, 16 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 | /** |