Mercurial > projects > dwt-addons
comparison dwtx/jface/text/templates/TemplateBuffer.d @ 129:eb30df5ca28b
Added JFace Text sources
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 23 Aug 2008 19:10:48 +0200 |
parents | |
children | c4fb132a086c |
comparison
equal
deleted
inserted
replaced
128:8df1d4193877 | 129:eb30df5ca28b |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2006 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.templates.TemplateBuffer; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 | |
17 import dwtx.core.runtime.Assert; | |
18 | |
19 /** | |
20 * A template buffer is a container for a string and variables. | |
21 * <p> | |
22 * Clients may instantiate this class. | |
23 * </p> | |
24 * | |
25 * @since 3.0 | |
26 */ | |
27 public final class TemplateBuffer { | |
28 | |
29 /** The string of the template buffer */ | |
30 private String fString; | |
31 /** The variable positions of the template buffer */ | |
32 private TemplateVariable[] fVariables; | |
33 | |
34 /** | |
35 * Creates a template buffer. | |
36 * | |
37 * @param string the string | |
38 * @param variables the variable positions | |
39 */ | |
40 public TemplateBuffer(String string, TemplateVariable[] variables) { | |
41 setContent(string, variables); | |
42 } | |
43 | |
44 /** | |
45 * Sets the content of the template buffer. | |
46 * | |
47 * @param string the string | |
48 * @param variables the variable positions | |
49 */ | |
50 public final void setContent(String string, TemplateVariable[] variables) { | |
51 Assert.isNotNull(string); | |
52 Assert.isNotNull(variables); | |
53 | |
54 // XXX assert non-overlapping variable properties | |
55 | |
56 fString= string; | |
57 fVariables= copy(variables); | |
58 } | |
59 | |
60 /** | |
61 * Returns a copy of the given array. | |
62 * | |
63 * @param array the array to be copied | |
64 * @return a copy of the given array or <code>null</code> when <code>array</code> is <code>null</code> | |
65 * @since 3.1 | |
66 */ | |
67 private static TemplateVariable[] copy(TemplateVariable[] array) { | |
68 if (array !is null) { | |
69 TemplateVariable[] copy= new TemplateVariable[array.length]; | |
70 System.arraycopy(array, 0, copy, 0, array.length); | |
71 return copy; | |
72 } | |
73 return null; | |
74 } | |
75 | |
76 /** | |
77 * Returns the string of the template buffer. | |
78 * | |
79 * @return the string representation of the template buffer | |
80 */ | |
81 public final String getString() { | |
82 return fString; | |
83 } | |
84 | |
85 /** | |
86 * Returns the variable positions of the template buffer. The returned array is | |
87 * owned by this variable and must not be modified. | |
88 * | |
89 * @return the variable positions of the template buffer | |
90 */ | |
91 public final TemplateVariable[] getVariables() { | |
92 return fVariables; | |
93 } | |
94 | |
95 } |