129
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * Port to the D programming language:
|
|
11 * Frank Benoit <benoit@tionex.de>
|
|
12 *******************************************************************************/
|
|
13 module dwtx.jface.text.DefaultLineTracker;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17
|
|
18 /**
|
|
19 * Standard implementation of {@link dwtx.jface.text.ILineTracker}.
|
|
20 * <p>
|
|
21 * The line tracker considers the three common line delimiters which are '\n',
|
|
22 * '\r', '\r\n'.
|
|
23 * <p>
|
|
24 * This class is not intended to be subclassed.
|
|
25 * </p>
|
|
26 * @noextend This class is not intended to be subclassed by clients.
|
|
27 */
|
|
28 public class DefaultLineTracker : AbstractLineTracker {
|
|
29
|
|
30 /** The predefined delimiters of this tracker */
|
|
31 public final static String[] DELIMITERS= { "\r", "\n", "\r\n" }; //$NON-NLS-3$ //$NON-NLS-1$ //$NON-NLS-2$
|
|
32 /** A predefined delimiter information which is always reused as return value */
|
|
33 private DelimiterInfo fDelimiterInfo= new DelimiterInfo();
|
|
34
|
|
35
|
|
36 /**
|
|
37 * Creates a standard line tracker.
|
|
38 */
|
|
39 public DefaultLineTracker() {
|
|
40 }
|
|
41
|
|
42 /*
|
|
43 * @see dwtx.jface.text.ILineTracker#getLegalLineDelimiters()
|
|
44 */
|
|
45 public String[] getLegalLineDelimiters() {
|
|
46 return TextUtilities.copy(DELIMITERS);
|
|
47 }
|
|
48
|
|
49 /*
|
|
50 * @see dwtx.jface.text.AbstractLineTracker#nextDelimiterInfo(java.lang.String, int)
|
|
51 */
|
|
52 protected DelimiterInfo nextDelimiterInfo(String text, int offset) {
|
|
53
|
|
54 char ch;
|
|
55 int length= text.length();
|
|
56 for (int i= offset; i < length; i++) {
|
|
57
|
|
58 ch= text.charAt(i);
|
|
59 if (ch is '\r') {
|
|
60
|
|
61 if (i + 1 < length) {
|
|
62 if (text.charAt(i + 1) is '\n') {
|
|
63 fDelimiterInfo.delimiter= DELIMITERS[2];
|
|
64 fDelimiterInfo.delimiterIndex= i;
|
|
65 fDelimiterInfo.delimiterLength= 2;
|
|
66 return fDelimiterInfo;
|
|
67 }
|
|
68 }
|
|
69
|
|
70 fDelimiterInfo.delimiter= DELIMITERS[0];
|
|
71 fDelimiterInfo.delimiterIndex= i;
|
|
72 fDelimiterInfo.delimiterLength= 1;
|
|
73 return fDelimiterInfo;
|
|
74
|
|
75 } else if (ch is '\n') {
|
|
76
|
|
77 fDelimiterInfo.delimiter= DELIMITERS[1];
|
|
78 fDelimiterInfo.delimiterIndex= i;
|
|
79 fDelimiterInfo.delimiterLength= 1;
|
|
80 return fDelimiterInfo;
|
|
81 }
|
|
82 }
|
|
83
|
|
84 return null;
|
|
85 }
|
|
86 }
|