source: release-kits/lirk3/ant-scripts/tasks/antelope/docs/manual/bk03ch13.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 14.1 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 13. StringUtils</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch12.html" title="Chapter 12. FileUtils"><link rel="next" href="bk03ch14.html" title="Chapter 14. UID"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 13. StringUtils</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch12.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch14.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="StringUtils"></a>Chapter 13. StringUtils</h2></div></div></div>
2<STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
3 <p>
4The StringUtils task provides a number of useful string manipulation functions, such as converting a string to upper or lower case, trimming white space, finding a substring, etc. <span class="bold"><strong>Caution: this task does not follow the standard Ant convention of property immutability.</strong></span>
5</p><p>
6To use this task in your build files, include a task definition like this:
7</p><p>
8</p><pre class="programlisting">
9
10 &lt;taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask"/&gt;
11
12</pre><p>
13</p><p>
14</p><div class="table"><a name="id2522160"></a><p class="title"><b>Table 13.1. StringUtil Task Attributes</b></p><table summary="StringUtil Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>string</td><td>The string to manipulate.</td><td>None</td><td>No</td></tr><tr><td>property</td><td>Where to store the manipulated string. Caution: this task will overwrite any existing property with this name.</td><td>None</td><td>No</td></tr></tbody></table></div><p>
15</p><p>
16Operations as nested elements:
17</p><p>
18</p><div class="table"><a name="id2522239"></a><p class="title"><b>Table 13.2. indexof, lastindexof: Find the index of or the last index of a substring.</b></p><table summary="indexof, lastindexof: Find the index of or the last index of a substring." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>string</td><td>The string to find the index of.</td><td>None</td><td>No</td></tr><tr><td>fromindex</td><td>Where to start looking.</td><td>0</td><td>No</td></tr></tbody></table></div><p>
19
20
21</p><div class="table"><a name="id2522312"></a><p class="title"><b>Table 13.3. substring: Get a substring from the string.</b></p><table summary="substring: Get a substring from the string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>beginindex</td><td>Start of substring.</td><td>0</td><td>No</td></tr><tr><td>endindex</td><td>End of substring.</td><td>End of string.</td><td>No</td></tr></tbody></table></div><p>
22
23
24</p><div class="table"><a name="id2522383"></a><p class="title"><b>Table 13.4. replace: Replace parts of the string.</b></p><table summary="replace: Replace parts of the string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>regex</td><td>Pattern to replace.</td><td>None</td><td>No</td></tr><tr><td>replacement</td><td>What to replace with.</td><td>None</td><td>No</td></tr></tbody></table></div><p>
25
26</p><div class="table"><a name="id2522455"></a><p class="title"><b>Table 13.5. sort: Sort items in a string.</b></p><table summary="sort: Sort items in a string." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>separator</td><td>The character separating individual items in the string.</td><td>Any of tab, new line, carriage return, line feed, or space.</td><td>No</td></tr></tbody></table></div><p>
27This is useful for sorting a comma separated list or a property value that spans several lines.
28
29</p><p>
30</p><div class="table"><a name="id2522516"></a><p class="title"><b>Table 13.6. messagebox: Put the string in a box for nice display.</b></p><table summary="messagebox: Put the string in a box for nice display." border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>title</td><td>Title for the message box.</td><td>None</td><td>No</td></tr><tr><td>width</td><td>
31Maximum width in characters for the message box. Lines
32will be wrapped to fit inside the box. The box will not
33stretch to this width if the message is less than
34width - 4 characters wide.
35</td><td>60</td><td>No</td></tr></tbody></table></div><p>
36</p><p>
37These operations have no attributes:
38</p><div class="itemizedlist"><ul type="disc"><li><p>
39<span class="bold"><strong>lowercase</strong></span> Converts the string to lowercase.
40</p></li><li><p>
41<span class="bold"><strong>uppercase</strong></span> Converts the string to uppercase.
42</p></li><li><p>
43<span class="bold"><strong>length</strong></span> Finds the length of the string.
44</p></li><li><p>
45<span class="bold"><strong>trim</strong></span> Removes white space from boths ends of the string.
46</p></li></ul></div><p>
47
48</p><p>
49More than one of the operations can be used at once, that is, you can convert a string to lowercase and trim it at the same time. See below for examples.
50</p><p>
51Examples:
52</p><p>
53Convert a string to lower case:
54</p><pre class="programlisting">
55
56 &lt;target name="test1"&gt;
57 &lt;property name="prop1" value="ABCDE"/&gt;
58 &lt;echo&gt;prop1 before = ${prop1}&lt;/echo&gt;
59 &lt;a:stringutil string="${prop1}" property="prop1"&gt;
60 &lt;a:lowercase/&gt;
61 &lt;/a:stringutil&gt;
62 &lt;echo&gt;prop1 after = ${prop1}&lt;/echo&gt;
63 &lt;a:assert message="prop1, expected abcde, got ${prop1}"&gt;
64 &lt;bool&gt;
65 &lt;equals arg1="abcde" arg2="${prop1}"/&gt;
66 &lt;/bool&gt;
67 &lt;/a:assert&gt;
68 &lt;/target&gt;
69
70</pre><p>
71</p><p>
72Convert a string to upper case:
73</p><pre class="programlisting">
74
75 &lt;target name="test2"&gt;
76 &lt;property name="prop2" value="abcdefgh"/&gt;
77 &lt;echo&gt;prop2 before = ${prop2}&lt;/echo&gt;
78 &lt;a:stringutil string="${prop2}" property="prop2"&gt;
79 &lt;a:uppercase/&gt;
80 &lt;/a:stringutil&gt;
81 &lt;echo&gt;prop2 after = ${prop2}&lt;/echo&gt;
82 &lt;a:assert message="prop2, expected ABCDEFGH, got ${prop2}"&gt;
83 &lt;bool&gt;
84 &lt;equals arg1="ABCDEFGH" arg2="${prop2}"/&gt;
85 &lt;/bool&gt;
86 &lt;/a:assert&gt;
87 &lt;/target&gt;
88
89</pre><p>
90</p><p>
91Convert a string to upper case and trim white space:
92</p><pre class="programlisting">
93
94 &lt;target name="test3"&gt;
95 &lt;property name="prop3" value=" abcdefgh "/&gt;
96 &lt;echo&gt;prop3 before = ${prop3}&lt;/echo&gt;
97 &lt;a:stringutil string="${prop3}" property="prop3"&gt;
98 &lt;a:uppercase/&gt;
99 &lt;a:trim/&gt;
100 &lt;/a:stringutil&gt;
101 &lt;echo&gt;prop3 after = ${prop3}&lt;/echo&gt;
102 &lt;a:assert message="prop3, expected ABCDEFGH, got ${prop3}"&gt;
103 &lt;bool&gt;
104 &lt;equals arg1="ABCDEFGH" arg2="${prop3}"/&gt;
105 &lt;/bool&gt;
106 &lt;/a:assert&gt;
107 &lt;/target&gt;
108
109</pre><p>
110</p><p>
111Convert a string to upper case, trim white space, and find a substring:
112</p><pre class="programlisting">
113
114 &lt;target name="test4"&gt;
115 &lt;property name="prop4" value=" abcdefgh "/&gt;
116 &lt;echo&gt;prop4 before = ${prop4}&lt;/echo&gt;
117 &lt;a:stringutil string="${prop4}" property="prop4"&gt;
118 &lt;a:uppercase/&gt;
119 &lt;a:trim/&gt;
120 &lt;a:substring beginindex="3"/&gt;
121 &lt;/a:stringutil&gt;
122 &lt;echo&gt;prop4 after = ${prop4}&lt;/echo&gt;
123 &lt;a:assert message="prop4, expected DEFGH, got ${prop4}"&gt;
124 &lt;bool&gt;
125 &lt;equals arg1="DEFGH" arg2="${prop4}"/&gt;
126 &lt;/bool&gt;
127 &lt;/a:assert&gt;
128 &lt;/target&gt;
129
130</pre><p>
131</p><p>
132Get the length of a string:
133</p><pre class="programlisting">
134
135 &lt;target name="test7"&gt;
136 &lt;property name="prop7" value="abcdefgh"/&gt;
137 &lt;echo&gt;prop7 before = ${prop7}&lt;/echo&gt;
138 &lt;a:stringutil string="${prop7}" property="prop7"&gt;
139 &lt;a:length/&gt;
140 &lt;/a:stringutil&gt;
141 &lt;echo&gt;prop7 length = ${prop7}&lt;/echo&gt;
142 &lt;a:assert message="prop7, expected 8, got ${prop7}"&gt;
143 &lt;bool&gt;
144 &lt;mathequals arg1="8" arg2="${prop7}"/&gt;
145 &lt;/bool&gt;
146 &lt;/a:assert&gt;
147 &lt;/target&gt;
148
149</pre><p>
150</p><p>
151Sort a list:
152</p><pre class="programlisting">
153
154 &lt;target name="test12"&gt;
155 &lt;property name="prop12" value="a,b,c,d,e,f,g,h,a,b,c,d,e,f,g,h"/&gt;
156 &lt;echo&gt;prop12 before = ${prop12}&lt;/echo&gt;
157 &lt;a:stringutil string="${prop12}" property="prop12"&gt;
158 &lt;a:sort separator=","/&gt;
159 &lt;/a:stringutil&gt;
160 &lt;echo&gt;prop12 sorted = ${prop12}&lt;/echo&gt;
161 &lt;a:assert message="prop12, expected 'a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h', got ${prop12}"&gt;
162 &lt;bool&gt;
163 &lt;equals arg1="a,a,b,b,c,c,d,d,e,e,f,f,g,g,h,h" arg2="${prop12}"/&gt;
164 &lt;/bool&gt;
165 &lt;/a:assert&gt;
166 &lt;/target&gt;
167
168</pre><p>
169</p><p>
170Message boxes:
171</p><pre class="programlisting">
172
173 &lt;target name="test13"&gt;
174 &lt;property name="prop13" value="Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages."/&gt;
175 &lt;echo&gt;prop13 before = ${prop13}&lt;/echo&gt;
176 &lt;a:stringutil string="${prop13}" property="prop13"&gt;
177 &lt;a:messagebox/&gt;
178 &lt;/a:stringutil&gt;
179 &lt;echo&gt;prop13 in messagebox:${line.separator}${prop13}&lt;/echo&gt;
180
181 &lt;property name="prop13a" value="Character boundary analysis allows users to interact with characters as they expect to, for example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of through character strings, regardless of how the character is stored. For example, an accented character might be stored as a base character and a diacritical mark. What users consider to be a character can differ between languages."/&gt;
182 &lt;a:stringutil string="${prop13a}" property="prop13a"&gt;
183 &lt;a:messagebox title="About Character Boundaries"/&gt;
184 &lt;/a:stringutil&gt;
185 &lt;echo&gt;prop13a in messagebox with title:${line.separator}${prop13a}&lt;/echo&gt;
186
187 &lt;/target&gt;
188
189test13:
190 [echo] prop13 before = Character boundary analysis allows users to interact with characters as they expect to, for
191example, when moving the cursor around through a text string. Character boundary analysis provides correct navigation of
192 through character strings, regardless of how the character is stored. For example, an accented character might be store
193d as a base character and a diacritical mark. What users consider to be a character can differ between languages.
194 [echo] prop13 in messagebox:
195 [echo]
196 [echo] +----------------------------------------------------------------------+
197 [echo] | Character boundary analysis allows users to interact with characters |
198 [echo] | as they expect to, for example, when moving the cursor around |
199 [echo] | through a text string. Character boundary analysis provides correct |
200 [echo] | navigation of through character strings, regardless of how the |
201 [echo] | character is stored. For example, an accented character might |
202 [echo] | be stored as a base character and a diacritical mark. What users |
203 [echo] | consider to be a character can differ between languages. |
204 [echo] +----------------------------------------------------------------------+
205 [echo] prop13a in messagebox with title:
206 [echo]
207 [echo] +----------------------------------------------------------------------+
208 [echo] | About Character Boundaries |
209 [echo] +----------------------------------------------------------------------+
210 [echo] | Character boundary analysis allows users to interact with characters |
211 [echo] | as they expect to, for example, when moving the cursor around |
212 [echo] | through a text string. Character boundary analysis provides correct |
213 [echo] | navigation of through character strings, regardless of how the |
214 [echo] | character is stored. For example, an accented character might |
215 [echo] | be stored as a base character and a diacritical mark. What users |
216 [echo] | consider to be a character can differ between languages. |
217 [echo] +----------------------------------------------------------------------+
218[antlib:ise.antelope.tasks:testcase] test13 passed.
219
220</pre><p>
221</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch12.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch14.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 12. FileUtils </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 14. UID</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.