Mercurial > projects > dwt-addons
comparison dwtx/jface/text/GapTextStore.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | a9566845f1cb |
children |
comparison
equal
deleted
inserted
replaced
161:f8d52b926852 | 162:1a5b8f8129df |
---|---|
58 import dwtx.jface.text.IRegion; // packageimport | 58 import dwtx.jface.text.IRegion; // packageimport |
59 import dwtx.jface.text.IInformationControlExtension2; // packageimport | 59 import dwtx.jface.text.IInformationControlExtension2; // packageimport |
60 import dwtx.jface.text.IDocumentExtension4; // packageimport | 60 import dwtx.jface.text.IDocumentExtension4; // packageimport |
61 import dwtx.jface.text.IDocumentExtension2; // packageimport | 61 import dwtx.jface.text.IDocumentExtension2; // packageimport |
62 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport | 62 import dwtx.jface.text.IDocumentPartitionerExtension2; // packageimport |
63 import dwtx.jface.text.Assert; // packageimport | |
64 import dwtx.jface.text.DefaultInformationControl; // packageimport | 63 import dwtx.jface.text.DefaultInformationControl; // packageimport |
65 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport | 64 import dwtx.jface.text.IWidgetTokenOwnerExtension; // packageimport |
66 import dwtx.jface.text.DocumentClone; // packageimport | 65 import dwtx.jface.text.DocumentClone; // packageimport |
67 import dwtx.jface.text.DefaultUndoManager; // packageimport | 66 import dwtx.jface.text.DefaultUndoManager; // packageimport |
68 import dwtx.jface.text.IFindReplaceTarget; // packageimport | 67 import dwtx.jface.text.IFindReplaceTarget; // packageimport |
200 * @since 3.3 | 199 * @since 3.3 |
201 */ | 200 */ |
202 private const float fSizeMultiplier; | 201 private const float fSizeMultiplier; |
203 | 202 |
204 /** The store's content */ | 203 /** The store's content */ |
205 private char[] fContent= new char[0]; | 204 private char[] fContent; |
206 /** Starting index of the gap */ | 205 /** Starting index of the gap */ |
207 private int fGapStart= 0; | 206 private int fGapStart= 0; |
208 /** End index of the gap */ | 207 /** End index of the gap */ |
209 private int fGapEnd= 0; | 208 private int fGapEnd= 0; |
210 /** | 209 /** |
296 /* | 295 /* |
297 * @see dwtx.jface.text.ITextStore#get(int, int) | 296 * @see dwtx.jface.text.ITextStore#get(int, int) |
298 */ | 297 */ |
299 public final String get(int offset, int length) { | 298 public final String get(int offset, int length) { |
300 if (fGapStart <= offset) | 299 if (fGapStart <= offset) |
301 return new String(fContent, offset + gapSize() , length); | 300 return new_String(fContent, offset + gapSize() , length); |
302 | 301 |
303 final int end= offset + length; | 302 final int end= offset + length; |
304 | 303 |
305 if (end <= fGapStart) | 304 if (end <= fGapStart) |
306 return new String(fContent, offset, length); | 305 return new_String(fContent, offset, length); |
307 | 306 |
308 StringBuffer buf= new StringBuffer(length); | 307 StringBuffer buf= new StringBuffer(length); |
309 buf.append(fContent, offset, fGapStart - offset); | 308 buf.append(fContent[ offset .. fGapStart ]); |
310 buf.append(fContent, fGapEnd, end - fGapStart); | 309 buf.append(fContent[ fGapEnd .. end - fGapStart + fGapEnd ]); |
311 return buf.toString(); | 310 return buf.toString(); |
312 } | 311 } |
313 | 312 |
314 /* | 313 /* |
315 * @see dwtx.jface.text.ITextStore#getLength() | 314 * @see dwtx.jface.text.ITextStore#getLength() |
336 */ | 335 */ |
337 public final void replace(int offset, int length, String text) { | 336 public final void replace(int offset, int length, String text) { |
338 if (text is null) { | 337 if (text is null) { |
339 adjustGap(offset, length, 0); | 338 adjustGap(offset, length, 0); |
340 } else { | 339 } else { |
341 int textLength= text.length(); | 340 int textLength= text.length; |
342 adjustGap(offset, length, textLength); | 341 adjustGap(offset, length, textLength); |
343 if (textLength !is 0) | 342 if (textLength !is 0) |
344 text.getChars(0, textLength, fContent, offset); | 343 text.getChars(0, textLength, fContent, offset); |
345 } | 344 } |
346 } | 345 } |
359 final int oldGapSize= gapSize(); | 358 final int oldGapSize= gapSize(); |
360 final int newGapSize= oldGapSize - add + remove; | 359 final int newGapSize= oldGapSize - add + remove; |
361 final bool reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; | 360 final bool reuseArray= 0 <= newGapSize && newGapSize <= fThreshold; |
362 | 361 |
363 final int newGapStart= offset + add; | 362 final int newGapStart= offset + add; |
364 final int newGapEnd; | 363 int newGapEnd; |
365 | 364 |
366 if (reuseArray) | 365 if (reuseArray) |
367 newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); | 366 newGapEnd= moveGap(offset, remove, oldGapSize, newGapSize, newGapStart); |
368 else | 367 else |
369 newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); | 368 newGapEnd= reallocate(offset, remove, oldGapSize, newGapSize, newGapStart); |
510 * For internal use only. | 509 * For internal use only. |
511 * | 510 * |
512 * @return a copy of the content of this text store | 511 * @return a copy of the content of this text store |
513 */ | 512 */ |
514 protected String getContentAsString() { | 513 protected String getContentAsString() { |
515 return new String(fContent); | 514 return new_String(fContent); |
516 } | 515 } |
517 | 516 |
518 /** | 517 /** |
519 * Returns the start index of the gap managed by this text store. | 518 * Returns the start index of the gap managed by this text store. |
520 * For internal use only. | 519 * For internal use only. |