blob: 4df75a6c95d9e5da66c924beda8ea0ca8b398a96 [file] [log] [blame]
Stuart McCulloch669423b2012-06-26 16:34:24 +00001package aQute.lib.properties;
2
3public class Document implements IDocument {
4
5 public final static String[] DELIMITERS = {
6 "\r", "\n", "\r\n"
7 };
8
9 private LineTracker lineTracker = new LineTracker();
10 private ITextStore textStore = new CopyOnWriteTextStore(new GapTextStore());
11
12 public Document(String text) {
13 setText(text);
14 }
15
16 public int getNumberOfLines() {
17 return lineTracker.getNumberOfLines();
18 }
19
20 public IRegion getLineInformation(int line) throws BadLocationException {
21 return lineTracker.getLineInformation(line);
22 }
23
24 public String get(int offset, int length) throws BadLocationException {
25 return textStore.get(offset, length);
26 }
27
28 public String getLineDelimiter(int line) throws BadLocationException {
29 return lineTracker.getLineDelimiter(line);
30 }
31
32 public int getLength() {
33 return textStore.getLength();
34 }
35
36 public void replace(int offset, int length, String text) throws BadLocationException {
37 textStore.replace(offset, length, text);
38 lineTracker.set(get());
39 }
40
41 public char getChar(int pos) {
42 return textStore.get(pos);
43 }
44
45 public void setText(String text) {
46 textStore.set(text);
47 lineTracker.set(text);
48 }
49
50 public String get() {
51 return textStore.get(0, textStore.getLength());
52 }
53
54 protected static class DelimiterInfo {
55 public int delimiterIndex;
56 public int delimiterLength;
57 public String delimiter;
58 }
59}