root/branches/maintenance/2.2.2/Modelica/Utilities/Strings.mo

Revision 573, 52.4 kB (checked in by otter, 15 months ago)

Fixed about 200 link errors in the generated html file. Reasons:
- "Hierarchical" classes in UsersGuides have been defined with "class"

and not with "package", but Dymola generates sub-hierarchies only
for "packages". Fixed this by renaming the corresponding classes to
"package".

- If a link is included in bold, e.g. <b><a href ....>...</a></b>,

Dymola does not translate the Modelica link in a html link.
Fixed this by removing the bold-type.

- There had been several errors in the link definition

(e.g. href=Modelica:Modelica..). Fixed them all.

- The link Modelica://Modelica.Blocks.Examples.BusUsage_Utilities.Interfaces.Internal

was not transformed because no documentation for "Internal" was generated.
It seems useful to not generate documentation for a class called "Internal".
On the other hand, for buses, it seems useful to have the documentation.
Fixed this by renaming "Internal" to "InternalConnectors".

There are the following remaining link errors:

Modelica://Modelica_Fluid.Interfaces
Modelica://Modelica_Fluid.Utilities.PipeFriction
Modelica://Magnetic.Interfaces
Modelica://HyLibLight.Interfaces
Modelica://PneuLibLight.Interfaces
Modelica://ModelicaReference.Operators.SemiLinear
Modelica://ModelicaReference.Operators.string

i.e., links to other libraries. Probably, one cannot do much and
it seems o.k. to have these errors.

Additionally, "versionBuild" (of subversion) was included as top level
annotations. Should be updated, for the release.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1within Modelica.Utilities;
2package Strings "Operations on strings" 
3  function length "Returns length of string" 
4    extends Modelica.Icons.Function;
5    input String string;
6    output Integer result "Number of characters of string";
7  external "C" result=  ModelicaStrings_length(string);
8    annotation (preferedView="info", Documentation(info="<html>
9<h4>Syntax</h4>
10<blockquote><pre>
11Strings.<b>length</b>(string);
12</pre></blockquote>
13<h4>Description</h4>
14<p>
15Returns the number of characters of \"string\".
16</p>
17</html>"));
18  end length;
19 
20  function substring "Returns a substring defined by start and end index" 
21   
22    extends Modelica.Icons.Function;
23    input String string "String from which a substring is inquired";
24    input Integer startIndex(min=1) 
25      "Character position of substring begin (index=1 is first character in string)";
26    input Integer endIndex(min=1) "Character position of substring end";
27    output String result
28      "String containing substring string[startIndex:endIndex]";
29  external "C" result = 
30                      ModelicaStrings_substring(string,startIndex,endIndex);
31    annotation (  preferedView="info",
32  Documentation(info="<html>
33<h4>Syntax</h4>
34<blockquote><pre>
35string2 = Strings.<b>substring</b>(string, startIndex, endIndex);
36</pre></blockquote>
37<h4>Description</h4>
38<p>
39This function returns
40the substring from position startIndex
41up to and including position endIndex of \"string\" .
42</p>
43<p>
44If index, startIndex, or endIndex are not correct, e.g.,
45if endIndex &gt; length(string), an assert is triggered.
46</p>
47<h4>Example</h4>
48<blockquote><pre>
49  string1 := \"This is line 111\";
50  string2 := Strings.substring(string1,9,12); // string2 = \"line\"
51</pre></blockquote>
52</html>"));
53  end substring;
54 
55  function repeat "Repeat a string n times" 
56    extends Modelica.Icons.Function;
57    input Integer n(min=0) = 1 "Number of occurences";
58    input String string=" " "String that is repeated";
59    output String repeatedString "String containing n concatenated strings";
60    annotation (  preferedView="info",
61  Documentation(info="<html>
62<h4>Syntax</h4>
63<blockquote><pre>
64string2 = Strings.<b>repeat</b>(n);
65string2 = Strings.<b>repeat</b>(n, string=\" \");
66</pre></blockquote>
67<h4>Description</h4>
68<p>
69The first form returns a string consisting of n blanks.
70</p>
71<p>
72The second form returns a string consisting of n substrings
73defined by the optional argument \"string\".
74</p>
75</html>"));
76  algorithm 
77    repeatedString :="";
78    for i in 1:n loop
79       repeatedString := repeatedString + string;
80    end for;
81  end repeat;
82 
83  function compare "Compare two strings lexicographically" 
84    extends Modelica.Icons.Function;
85    input String string1;
86    input String string2;
87    input Boolean caseSensitive=true "= false, if case of letters is ignored";
88    output Modelica.Utilities.Types.Compare.Type result "Result of comparison";
89  external "C" result=  ModelicaStrings_compare(string1, string2, caseSensitive);
90    annotation (preferedView="info", Documentation(info="<html>
91<h4>Syntax</h4>
92<blockquote><pre>
93result = Strings.<b>compare</b>(string1, string2);
94result = Strings.<b>compare</b>(string1, string2, caseSensitive=true);
95</pre></blockquote>
96<h4>Description</h4>
97<p>
98Compares two strings. If the optional argument caseSensitive=false,
99upper case letters are treated as if they would be lower case letters.
100The result of the comparison is returned as:
101</p>
102<pre>
103  result = Modelica.Utilities.Types.Compare.Less     // string1 &lt; string2
104         = Modelica.Utilities.Types.Compare.Equal    // string1 = string2
105         = Modelica.Utilities.Types.Compare.Greater  // string1 &gt; string2
106</pre>
107<p>
108Comparison is with regards to lexicographical order,
109e.g., \"a\" &lt; \"b\";
110</p>
111</html>"));
112  end compare;
113 
114  function isEqual "Determine whether two strings are identical" 
115    extends Modelica.Icons.Function;
116    input String string1;
117    input String string2;
118    input Boolean caseSensitive=true 
119      "= false, if lower and upper case are ignored for the comparison";
120    output Boolean identical "True, if string1 is identical to string2";
121    annotation (  preferedView="info",
122  Documentation(info="<html>
123<h4>Syntax</h4>
124<blockquote><pre>
125Strings.<b>isEqual</b>(string1, string2);
126Strings.<b>isEqual</b>(string1, string2, caseSensitive=true);
127</pre></blockquote>
128<h4>Description</h4>
129<p>
130Compare whether two strings are identical,
131optionally ignoring case.
132</p>
133</html>"));
134  algorithm 
135    identical :=compare(string1, string2, caseSensitive) == Types.Compare.Equal;
136  end isEqual;
137  extends Modelica.Icons.Library;
138 
139  annotation (
140  version="1.0",
141  versionDate="2004-10-01",
142  preferedView="info",
143    Documentation(info="<HTML>
144<h4>Library content</h4>
145<p>
146Package <b>Strings</b> contains functions to manipulate strings.
147</p>
148<p>
149In the table below an example
150call to every function is given using the <b>default</b> options.
151</p>
152<table border=1 cellspacing=0 cellpadding=2>
153  <tr><th><b><i>Function</i></b></th><th><b><i>Description</i></b></th></tr>
154  <tr><td valign=\"top\">len = <a href=\"Modelica://Modelica.Utilities.Strings.length\">length</a>(string)</td>
155      <td valign=\"top\">Returns length of string</td></tr>
156  <tr><td valign=\"top\">string2 = <a href=\"Modelica://Modelica.Utilities.Strings.substring\">substring</a>(string1,startIndex,endIndex)
157       </td>
158      <td valign=\"top\">Returns a substring defined by start and end index</td></tr>
159  <tr><td valign=\"top\">result = <a href=\"Modelica://Modelica.Utilities.Strings.repeat\">repeat</a>(n)<br>
160 result = <a href=\"Modelica://Modelica.Utilities.Strings.repeat\">repeat</a>(n,string)</td>
161      <td valign=\"top\">Repeat a blank or a string n times.</td></tr>
162  <tr><td valign=\"top\">result = <a href=\"Modelica://Modelica.Utilities.Strings.compare\">compare</a>(string1, string2)</td>
163      <td valign=\"top\">Compares two substrings with regards to alphabetical order</td></tr>
164  <tr><td valign=\"top\">identical =
165<a href=\"Modelica://Modelica.Utilities.Strings.isEqual\">isEqual</a>(string1,string2)</td>
166      <td valign=\"top\">Determine whether two strings are identical</td></tr>
167  <tr><td valign=\"top\">result = <a href=\"Modelica://Modelica.Utilities.Strings.count\">count</a>(string,searchString)</td>
168      <td valign=\"top\">Count the number of occurrences of a string</td></tr>
169  <tr>
170<td valign=\"top\">index = <a href=\"Modelica://Modelica.Utilities.Strings.find\">find</a>(string,searchString)</td>
171      <td valign=\"top\">Find first occurrence of a string in another string</td></tr>
172<tr>
173<td valign=\"top\">index = <a href=\"Modelica://Modelica.Utilities.Strings.findLast\">findLast</a>(string,searchString)</td>
174      <td valign=\"top\">Find last occurrence of a string in another string</td></tr>
175  <tr><td valign=\"top\">string2 = <a href=\"Modelica://Modelica.Utilities.Strings.replace\">replace</a>(string,searchString,replaceString)</td>
176      <td valign=\"top\">Replace one or all occurrences of a string</td></tr>
177  <tr><td valign=\"top\">stringVector2 = <a href=\"Modelica://Modelica.Utilities.Strings.sort\">sort</a>(stringVector1)</td>
178      <td valign=\"top\">Sort vector of strings in alphabetic order</td></tr>
179  <tr><td valign=\"top\">(token, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanToken\">scanToken</a>(string,startIndex)</td>
180      <td valign=\"top\">Scan for a token (Real/Integer/Boolean/String/Identifier/Delimiter/NoToken)</td></tr>
181  <tr><td valign=\"top\">(number, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanReal\">scanReal</a>(string,startIndex)</td>
182      <td valign=\"top\">Scan for a Real constant</td></tr>
183  <tr><td valign=\"top\">(number, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanInteger\">scanInteger</a>(string,startIndex)</td>
184      <td valign=\"top\">Scan for an Integer constant</td></tr>
185  <tr><td valign=\"top\">(boolean, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanBoolean\">scanBoolean</a>(string,startIndex)</td>
186      <td valign=\"top\">Scan for a Boolean constant</td></tr>
187  <tr><td valign=\"top\">(string2, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanString\">scanString</a>(string,startIndex)</td>
188      <td valign=\"top\">Scan for a String constant</td></tr>
189  <tr><td valign=\"top\">(identifier, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanIdentifier\">scanIdentifier</a>(string,startIndex)</td>
190      <td valign=\"top\">Scan for an identifier</td></tr>
191  <tr><td valign=\"top\">(delimiter, index) = <a href=\"Modelica://Modelica.Utilities.Strings.scanDelimiter\">scanDelimiter</a>(string,startIndex)</td>
192      <td valign=\"top\">Scan for delimiters</td></tr>
193  <tr><td valign=\"top\"><a href=\"Modelica://Modelica.Utilities.Strings.scanNoToken\">scanNoToken</a>(string,startIndex)</td>
194      <td valign=\"top\">Check that remaining part of string consists solely of <br>
195          white space or line comments (\"// ...\\n\").</td></tr>
196  <tr><td valign=\"top\"><a href=\"Modelica://Modelica.Utilities.Strings.syntaxError\">syntaxError</a>(string,index,message)</td>
197      <td valign=\"top\"> Print a \"syntax error message\" as well as a string and the <br>
198           index at which scanning detected an error</td></tr>
199</table>
200<p>
201The functions \"compare\", \"isEqual\", \"count\", \"find\", \"findLast\", \"replace\", \"sort\"
202have the optional
203input argument <b>caseSensitive</b> with default <b>true</b>.
204If <b>false</b>, the operation is carried out without taking
205into account whether a character is upper or lower case.
206</p>
207</HTML>"));
208 
209  function count "Count the number of non-overlapping occurrences of a string" 
210    extends Modelica.Icons.Function;
211    input String string "String that is analyzed";
212    input String searchString "String that is searched for in string";
213    input Integer startIndex(min=1)=1 "Start search at index startIndex";
214    input Boolean caseSensitive=true 
215      "= false, if lower and upper case are ignored for count";
216    output Integer result "Number of occurrences of 'searchString' in 'string'";
217    annotation (  preferedView="info",
218  Documentation(info="<html>
219<h4>Syntax</h4>
220<blockquote><pre>
221Strings.<b>count</b>(string, searchString)
222Strings.<b>count</b>(string, searchString, startIndex=1,
223                     caseSensitive=true)
224</pre></blockquote>
225<h4>Description</h4>
226<p>
227Returns the number of non-overlapping occurrences of string \"searchString\"
228in \"string\". The search is started at index \"startIndex\" (default = 1).
229If the optional argument \"caseSensitive\" is false,
230for the counting it does not matter whether a letter is upper
231or lower case.
232/p>
233</html>"));
234  protected 
235    Integer lenSearchString = length(searchString);
236    Integer i = startIndex;
237  algorithm 
238    result := 0;
239    while i <> 0 loop
240       i := find(string, searchString, i, caseSensitive);
241       if i > 0 then
242          result := result + 1;
243          i := i + lenSearchString;
244       end if;
245    end while;
246  end count;
247 
248  function find "Find first occurrence of a string within another string" 
249    extends Modelica.Icons.Function;
250    input String string "String that is analyzed";
251    input String searchString "String that is searched for in string";
252    input Integer startIndex(min=1)=1 "Start search at index startIndex";
253    input Boolean caseSensitive=true 
254      "= false, if lower and upper case are ignored for the search";
255     output Integer index
256      "Index of the beginning of the first occurrence of 'searchString' within 'string', or zero if not present";
257    annotation (  preferedView="info",
258  Documentation(info="<html>
259<h4>Syntax</h4>
260<blockquote><pre>
261index = Strings.<b>find</b>(string, searchString);
262index = Strings.<b>find</b>(string, searchString, startIndex=1,
263                     caseSensitive=true);
264</pre></blockquote>
265<h4>Description</h4>
266<p>
267Finds first occurence of \"searchString\" within \"string\"
268and return the corresponding index.
269Start search at index \"startIndex\" (default = 1).
270If the optional argument \"caseSensitive\" is false, lower
271and upper case are ignored for the search.
272If \"searchString\" is not found, a value of \"0\" is returned.
273</p>
274</html>
275"));
276  protected 
277    Integer lengthSearchString = length(searchString);
278    Integer len = lengthSearchString-1;
279    Integer i = startIndex;
280    Integer i_max = length(string) - lengthSearchString + 1;
281  algorithm 
282    index := 0;
283    while i <= i_max loop
284       if isEqual(substring(string,i,i+len),
285                  searchString, caseSensitive) then
286          index := i;
287          i := i_max + 1;
288       else
289          i := i+1;
290       end if;
291    end while;
292  end find;
293 
294  function findLast "Find last occurrence of a string within another string" 
295    extends Modelica.Icons.Function;
296    input String string "String that is analyzed";
297    input String searchString "String that is searched for in string";
298    input Integer startIndex(min=0)=0 
299      "Start search at index startIndex. If startIndex = 0, start at length(string)";
300    input Boolean caseSensitive=true 
301      "= false, if lower and upper case are ignored for the search";
302    output Integer index
303      "Index of the beginning of the last occurrence of 'searchString' within 'string', or zero if not present";
304    annotation (  preferedView="info",
305  Documentation(info="<html>
306<h4>Syntax</h4>
307<blockquote><pre>
308index = Strings.<b>findLast</b>(string, searchString);
309index = Strings.<b>findLast</b>(string, searchString,
310                         startIndex=length(string), caseSensitive=true,
311</pre></blockquote>
312<h4>Description</h4>
313<p>
314Finds first occurence of \"searchString\" within \"string\"
315when searching from the last character of \"string\"
316backwards, and return the corresponding index.
317Start search at index \"startIndex\" (default = length(string)).
318If the optional argument \"caseSensitive\" is false, lower
319and upper case are ignored for the search.
320If \"searchString\" is not found, a value of \"0\" is returned.
321</p>
322</html>
323"));
324  protected 
325    Integer lenString = length(string);
326    Integer lenSearchString = length(searchString);
327    Integer i;
328  algorithm 
329    i := if startIndex == 0 then lenString-lenSearchString+1 else startIndex;
330    index := 0;
331    while i >= 1 loop
332       if isEqual(substring(string,i,i+lenSearchString-1),
333                  searchString, caseSensitive) then
334          index := i;
335          i := 0;
336       else
337          i := i-1;
338       end if;
339    end while;
340  end findLast;
341 
342  function replace
343    "Replace non-overlapping occurrences of a string from left to right" 
344    extends Modelica.Icons.Function;
345    input String string "String to be modified";
346    input String searchString
347      "Replace non-overlapping occurrences of 'searchString' in 'string' with 'replaceString'";
348    input String replaceString
349      "String that replaces 'searchString' in 'string'";
350    input Integer startIndex=1 "Start search at index startIndex";
351    input Boolean replaceAll=true 
352      "if false, replace only the first occurrence, otherwise all occurrences";
353    input Boolean caseSensitive=true 
354      "= false, if lower and upper case are ignored when searching for searchString";
355    output String result "Resultant string of replacement operation";
356    annotation (  preferedView="info",
357  Documentation(info="<html>
358<h4>Syntax</h4>
359<blockquote><pre>
360Strings.<b>replace</b>(string, searchString, replaceString);
361Strings.<b>replace</b>(string, searchString, replaceString,
362                startIndex=1, replaceAll=true, caseSensitive=true);
363</pre></blockquote>
364<h4>Description</h4>
365<p>
366Search in \"string\" for \"searchString\" and replace the found
367substring by \"replaceString\".
368<p>
369<ul>
370<li> The search starts at the first character of \"string\",
371     or at character position \"startIndex\",
372     if this optional argument is provided.</li>
373<li> If the optional argument \"replaceAll\" is <b>true</b> (default),
374     all occurrences of \"searchString\" are replaced.
375     If the argument is <b>false</b>, only the first occurrence
376     is replaced. </li>
377<li> The search for \"searchString\" distinguishes upper and lower
378     case letters. If the optional argument \"caseSensitive\" is
379     <b>false</b>,
380     the search ignores whether letters are upper
381     or lower case. </li>
382</ul>
383<p>
384The function returns the \"string\" with the
385performed replacements.
386</p>
387</html>"));
388  protected 
389    Integer lenString = length(string);
390    Integer lenSearchString = length(searchString);
391    Integer i = startIndex;
392    Integer i_found;
393  algorithm 
394    result := if startIndex == 1 then "" else substring(string,1,startIndex-1);
395    while i > 0 loop
396       i_found := find(string, searchString, i, caseSensitive);
397       if i_found > 0 then
398          result := if i_found == 1 then 
399                       replaceString else 
400                       result + (if i_found-1<i then "" else substring(string, i, i_found-1)) + replaceString;
401          i := i_found + lenSearchString;
402          if i > lenString then
403             i := 0;
404          elseif not replaceAll then
405             result := result + substring(string, i, lenString);
406             i := 0;
407          end if;
408       elseif lenString<i then
409          i := 0;
410       else
411          result := result + substring(string, i, lenString);
412          i := 0;
413       end if;
414    end while;
415  end replace;
416 
417  function sort "Sort vector of strings in alphabetic order" 
418    extends Modelica.Icons.Function;
419    input String stringVector1[:] "vector of strings";
420    input Boolean caseSensitive=true 
421      "= false, if lower and upper case are ignored when comparing elements of stringVector1";
422    output String stringVector2[size(stringVector1,1)] 
423      "string1 sorted in alphabetical order";
424    /* shellsort algorithm; should be improved later */
425  protected 
426    Integer gap;
427    Integer i;
428    Integer j;
429    String tempString;
430    Integer nStringVector1 = size(stringVector1,1);
431    Boolean swap;
432  algorithm 
433    stringVector2 := stringVector1;
434    gap := div(nStringVector1,2);
435   
436    while gap > 0 loop
437       i := gap;
438       while i < nStringVector1 loop
439          j := i-gap;
440          if j >= 0 then
441             swap := compare(stringVector2[j+1], stringVector2[j+gap+1], caseSensitive)
442                     == Modelica.Utilities.Types.Compare.Greater;
443          else
444             swap := false;
445          end if;
446       
447          while swap loop
448             tempString := stringVector2[j+1];
449             stringVector2[j+1] := stringVector2[j+gap+1];
450             stringVector2[j+gap+1] := tempString;
451             j := j - gap;
452             if j >= 0 then
453                swap := compare(stringVector2[j+1], stringVector2[j+gap+1], caseSensitive)
454                        == Modelica.Utilities.Types.Compare.Greater;
455             else
456                swap := false;
457             end if;
458          end while;
459          i := i + 1;
460       end while;
461       gap := div(gap,2);
462    end while;
463   
464    annotation (preferedView="info",Documentation(info="<HTML>
465<h4>Syntax</h4>
466<blockquote><pre>
467stringVector2 = Streams.<b>sort</b>(stringVector1);
468stringVector2 = Streams.<b>sort</b>(stringVector1, caseSensitive=true);
469</pre></blockquote>
470<h4>Description</h4>
471<p>
472Function <b>sort</b>(..) sorts a string vector stringVector1
473in lexicographical order and returns the result in stringVector2.
474If the optional argument \"caseSensitive\" is <b>false</b>, lower
475and upper case letters are not distinguished.
476</p>
477<h4>Example</h4>
478<blockquote><pre>
479  s1 = {\"force\", \"angle\", \"pressure\"};
480  s2 = Strings.sort(s1);
481       -> s2 = {\"angle\", \"force\", \"pressure\"};
482</pre></blockquote>
483</HTML>"));
484  end sort;
485 
486  function scanToken "Scan for the next token and return it" 
487    extends Modelica.Icons.Function;
488    input String string "String to be scanned";
489    input Integer startIndex(min=1) = 1 
490      "Start scanning of string at character startIndex";
491    input Boolean unsigned=false 
492      "= true, if Real and Integer tokens shall not start with a sign";
493    output Types.TokenValue token "Scanned token";
494    output Integer nextIndex
495      "Index of character after the found token; = 0, if NoToken";
496    annotation (preferedView="info", Documentation(info="<html>
497<h4>Syntax</h4>
498<blockquote><pre>
499(token, nextIndex) = Strings.<b>scanToken</b>(string, startIndex, unsigned=false);
500</pre></blockquote>
501<h4>Description</h4>
502<p>
503Function <b>scanToken</b> scans the string starting at index
504\"startIndex\" and returns the next token, as well as the
505index directly after the token. The returned token is a record
506that holds the type of the token and the value of the token:
507</p>
508<table border=1 cellspacing=0 cellpadding=2>
509  <tr><td valign=\"top\">token.tokenType</td>
510      <td valign=\"top\">Type of the token, see below</td></tr>
511  <tr><td valign=\"top\">token.real</td>
512      <td valign=\"top\">Real value if tokenType == TokenType.RealToken</td></tr>
513  <tr><td valign=\"top\">token.integer</td>
514      <td valign=\"top\">Integer value if tokenType == TokenType.IntegerToken</td></tr>
515  <tr><td valign=\"top\">token.boolean</td>
516      <td valign=\"top\">Boolean value if tokenType == TokenType.BooleanToken</td></tr>
517  <tr><td valign=\"top\">token.string</td>
518      <td valign=\"top\">String value if tokenType == TokenType.StringToken/IdentifierToken/DelimiterToken</td></tr>
519</table>
520<p>
521Variable token.tokenType is an enumeration (emulated as a package
522with constants) that can have the following values:
523</p>
524<pre>
525   import T = Modelica.Utilities.Types.TokenType;
526</pre>
527<table border=1 cellspacing=0 cellpadding=2>
528  <tr><td valign=\"top\">T.RealToken</td>
529      <td valign=\"top\">Modelica Real literal (e.g., 1.23e-4)</td></tr>
530  <tr><td valign=\"top\">T.IntegerToken</td>
531      <td valign=\"top\">Modelica Integer literal (e.g., 123)</td></tr>
532  <tr><td valign=\"top\">T.BooleanToken</td>
533      <td valign=\"top\">Modelica Boolean literal (e.g., false)</td></tr>
534  <tr><td valign=\"top\">T.StringToken</td>
535      <td valign=\"top\">Modelica String literal (e.g., \"string 123\")</td></tr>
536  <tr><td valign=\"top\">T.IdentifierToken</td>
537      <td valign=\"top\">Modelica identifier (e.g., \"force_a\")</td></tr>
538  <tr><td valign=\"top\">T.DelimiterToken</td>
539      <td valign=\"top\">any character without white space that does not appear<br>
540          as first character in the tokens above (e.g., \"&\")</td></tr>
541  <tr><td valign=\"top\">T.NoToken</td>
542      <td valign=\"top\">White space, line comments and no other token<br>
543          until the end of the string</td></tr>
544</table>
545<p>
546Modelica line comments (\"// ... end-of-line/end-of-string\")
547as well as white space is ignored.
548If \"unsigned=true\", a Real or Integer literal
549is not allowed to start with a \"+\" or \"-\" sign.
550</p>
551<h4>Example</h4>
552<blockquote><pre>
553  import Modelica.Utilities.Strings.*;
554  import T = Modelica.Utilities.Types.TokenType;
555  (token, index) := scanToken(string);
556  <b>if</b> token.tokenType == T.RealToken <b>then</b>
557     realValue := token.real;
558  <b>elseif</b> token.tokenType == T.IntegerToken <b>then</b>
559     integerValue := token.integer;
560  <b>elseif</b> token.tokenType == T.BooleanToken<b> then</b>
561     booleanValue := token.boolean;
562  <b>elseif</b> token.tokenType == T.Identifier <b>then</b>
563     name := token.string;
564  <b>else</b>
565     syntaxError(string,index,\"Expected Real, Integer, Boolean or identifier token\");
566  <b>end if</b>;
567</pre></blockquote>
568</html>"));
569  protected 
570    Integer startTokenIndex;
571  algorithm 
572    // Initialize token
573    token.real :=0.0;
574    token.integer :=0;
575    token.boolean :=false;
576    token.string :="";
577   
578    // skip white space and line comments
579    startTokenIndex := Advanced.skipLineComments(string, startIndex);
580    if startTokenIndex > length(string) then
581      token.tokenType := Types.TokenType.NoToken;
582      nextIndex := startTokenIndex;
583    else
584      // scan Integer number
585        (nextIndex, token.integer) := Advanced.scanInteger(string, startTokenIndex, unsigned);
586         token.tokenType := Types.TokenType.IntegerToken;
587     
588      // scan Real number
589      if nextIndex == startTokenIndex then
590        (nextIndex, token.real) :=Advanced.scanReal(string, startTokenIndex, unsigned);
591         token.tokenType := Types.TokenType.RealToken;
592      end if;
593     
594      // scan String
595      if nextIndex == startTokenIndex then
596         (nextIndex,token.string) := Advanced.scanString(string, startTokenIndex);
597          token.tokenType:= Types.TokenType.StringToken;
598      end if;
599     
600      // scan Identifier or Boolean
601      if nextIndex == startTokenIndex then
602         (nextIndex,token.string) := Advanced.scanIdentifier(string, startTokenIndex);
603         if nextIndex > startTokenIndex then
604            if token.string == "false" then
605               token.string := "";
606               token.boolean :=false;
607               token.tokenType := Types.TokenType.BooleanToken;
608            elseif token.string == "true" then
609               token.string := "";
610               token.boolean := true;
611               token.tokenType := Types.TokenType.BooleanToken;
612            else
613               token.tokenType := Types.TokenType.IdentifierToken;
614            end if;
615         end if;
616      end if;
617     
618      // scan Delimiter
619      if nextIndex == startTokenIndex then
620         token.string :=substring(string, startTokenIndex, startTokenIndex);
621         token.tokenType := Types.TokenType.DelimiterToken;
622         nextIndex := startTokenIndex + 1;
623      end if;
624    end if;
625  end scanToken;
626 
627  function scanReal
628    "Scan for the next Real number and trigger an assert if not present" 
629    extends Modelica.Icons.Function;
630    input String string "String to be scanned";
631    input Integer startIndex(min=1)=1 
632      "Start scanning of string at character startIndex";
633    input Boolean unsigned=false 
634      "= true, if Real token shall not start with a sign";
635    input String message="" 
636      "Message used in error message if scan is not successful";
637    output Real number "Value of real number";
638    output Integer nextIndex "index of character after the found number";
639    annotation (preferedView="info",Documentation(info="<html>
640<h4>Syntax</h4>
641<blockquote><pre>
642             number = Strings.<b>scanReal</b>(string);
643(number, nextIndex) = Strings.<b>scanReal</b>(string, startIndex=1,
644                                            unsigned=false, message=\"\");
645</pre></blockquote>
646<h4>Description</h4>
647<p>
648The first form, \"scanReal(string)\", scans \"string\" for a
649Real number with leading white space and returns the value.
650</p>
651<p>
652The second form, \"scanReal(string,startIndex,unsigned)\",
653scans the string starting at index
654\"startIndex\", checks whether the next token is a Real literal
655and returns its value as a Real number, as well as the
656index directly after the Real number.
657If the optional argument \"unsigned\" is <b>true</b>,
658the real number shall not have a leading \"+\" or \"-\" sign.
659</p>
660<p>
661If the required Real number with leading white space
662is not present in \"string\",  an assert is triggered.
663</p>
664</html>"));
665  algorithm 
666    (nextIndex, number) :=Advanced.scanReal(string, startIndex, unsigned);
667    if nextIndex == startIndex then
668       nextIndex :=Advanced.skipWhiteSpace(string, startIndex);
669       if unsigned then
670          syntaxError(string, nextIndex, "Expected a Real number without a sign " + message);
671       else
672          syntaxError(string, nextIndex, "Expected a Real number " + message);
673       end if;
674    end if;
675  end scanReal;
676 
677  function scanInteger
678    "Scan for the next Integer number and trigger an assert if not present" 
679    extends Modelica.Icons.Function;
680    input String string "String to be scanned";
681    input Integer startIndex(min=1)=1 
682      "Start scanning of string at character startIndex";
683    input Boolean unsigned=false 
684      "= true, if Integer token shall not start with a sign";
685    input String message="" 
686      "Message used in error message if scan is not successful";
687    output Integer number "Value of Integer number";
688    output Integer nextIndex "Index of character after the found number";
689    annotation (preferedView="info",Documentation(info="<html>
690<h4>Syntax</h4>
691<blockquote><pre>
692             number = Strings.<b>scanInteger</b>(string);
693(number, nextIndex) = Strings.<b>scanInteger</b>(string, startIndex=1,
694                                               unsigned=false, message=\"\");
695</pre></blockquote>
696<h4>Description</h4>
697<p>
698Function <b>scanInteger</b> scans the string starting at index
699\"startIndex\", checks whether the next token is an Integer literal
700and returns its value as an Integer number, as well as the
701index directly after the Integer number. An assert is triggered,
702if the scanned string does not con