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.ConfigurableLineTracker;
|
|
14
|
|
15 import dwt.dwthelper.utils;
|
|
16
|
|
17 import dwtx.core.runtime.Assert;
|
|
18
|
|
19
|
|
20 /**
|
|
21 * Standard implementation of a generic
|
|
22 * {@link dwtx.jface.text.ILineTracker}.
|
|
23 * <p>
|
|
24 * The line tracker can be configured with the set of legal line delimiters.
|
|
25 * Line delimiters are unconstrained. The line delimiters are used to compute
|
|
26 * the tracker's line structure. In the case of overlapping line delimiters, the
|
|
27 * longest line delimiter is given precedence of the shorter ones.
|
|
28 * <p>
|
|
29 * This class is not intended to be subclassed.
|
|
30 * </p>
|
|
31 * @noextend This class is not intended to be subclassed by clients.
|
|
32 */
|
|
33 public class ConfigurableLineTracker : AbstractLineTracker {
|
|
34
|
|
35
|
|
36 /** The strings which are considered being the line delimiter */
|
|
37 private String[] fDelimiters;
|
|
38 /** A predefined delimiter information which is always reused as return value */
|
|
39 private DelimiterInfo fDelimiterInfo= new DelimiterInfo();
|
|
40
|
|
41
|
|
42 /**
|
|
43 * Creates a standard line tracker for the given line delimiters.
|
|
44 *
|
|
45 * @param legalLineDelimiters the tracker's legal line delimiters,
|
|
46 * may not be <code>null</code> and must be longer than 0
|
|
47 */
|
|
48 public ConfigurableLineTracker(String[] legalLineDelimiters) {
|
|
49 Assert.isTrue(legalLineDelimiters !is null && legalLineDelimiters.length > 0);
|
|
50 fDelimiters= TextUtilities.copy(legalLineDelimiters);
|
|
51 }
|
|
52
|
|
53 /*
|
|
54 * @see dwtx.jface.text.ILineTracker#getLegalLineDelimiters()
|
|
55 */
|
|
56 public String[] getLegalLineDelimiters() {
|
|
57 return TextUtilities.copy(fDelimiters);
|
|
58 }
|
|
59
|
|
60 /*
|
|
61 * @see dwtx.jface.text.AbstractLineTracker#nextDelimiterInfo(java.lang.String, int)
|
|
62 */
|
|
63 protected DelimiterInfo nextDelimiterInfo(String text, int offset) {
|
|
64 if (fDelimiters.length > 1) {
|
|
65 int[] info= TextUtilities.indexOf(fDelimiters, text, offset);
|
|
66 if (info[0] is -1)
|
|
67 return null;
|
|
68 fDelimiterInfo.delimiterIndex= info[0];
|
|
69 fDelimiterInfo.delimiter= fDelimiters[info[1]];
|
|
70 } else {
|
|
71 int index= text.indexOf(fDelimiters[0], offset);
|
|
72 if (index is -1)
|
|
73 return null;
|
|
74 fDelimiterInfo.delimiterIndex= index;
|
|
75 fDelimiterInfo.delimiter= fDelimiters[0];
|
|
76 }
|
|
77
|
|
78 fDelimiterInfo.delimiterLength= fDelimiterInfo.delimiter.length();
|
|
79 return fDelimiterInfo;
|
|
80 }
|
|
81 }
|