Advanced

Advanced scanning functions

Package Contents

scanReal

Scan a signed real number

scanInteger

Scan signed integer number

scanString

Scan string

scanIdentifier

Scan simple identifiers

skipWhiteSpace

Scan white space

skipLineComments

Scan comments and white space

Information

This information is part of the Modelica Standard Library maintained by the Modelica Association.

Library content

Package Strings.Advanced contains basic scanning functions. These functions should be not called directly, because it is much simpler to utilize the higher level functions "Strings.scanXXX". The functions of the "Strings.Advanced" library provide the basic interface in order to implement the higher level functions in package "Strings".

Library "Advanced" provides the following functions:

(nextIndex, realNumber)    = scanReal        (string, startIndex, unsigned=false);
(nextIndex, integerNumber) = scanInteger     (string, startIndex, unsigned=false);
(nextIndex, string2)       = scanString      (string, startIndex);
(nextIndex, identifier)    = scanIdentifier  (string, startIndex);
 nextIndex                 = skipWhiteSpace  (string, startIndex);
 nextIndex                 = skipLineComments(string, startIndex);

All functions perform the following actions:

  1. Scanning starts at character position "startIndex" of "string" (startIndex has a default of 1).
  2. First, white space is skipped, such as blanks (" "), tabs ("\t"), or newline ("\n")
  3. Afterwards, the required token is scanned.
  4. If successful, on return nextIndex = index of character directly after the found token and the token value is returned as second output argument.
    If not successful, on return nextIndex = startIndex.

The following additional rules apply for the scanning:

  • Function scanReal:
    Scans a full number including one optional leading "+" or "-" (if unsigned=false) according to the Modelica grammar. For example, "+1.23e-5", "0.123" are Real numbers, but ".1" is not. Note, an Integer number, such as "123" is also treated as a Real number.
     
  • Function scanInteger:
    Scans an Integer number including one optional leading "+" or "-" (if unsigned=false) according to the Modelica (and C/C++) grammar. For example, "+123", "20" are Integer numbers. Note, a Real number, such as "123.4" is not an Integer and scanInteger returns nextIndex = startIndex.
     
  • Function scanString:
    Scans a String according to the Modelica (and C/C++) grammar, e.g., "This is a "string"" is a valid string token.
     
  • Function scanIdentifier:
    Scans a Modelica identifier, i.e., the identifier starts either with a letter, followed by letters, digits or "_". For example, "w_rel", "T12".
     
  • Function skipLineComments
    Skips white space and Modelica (C/C++) line comments iteratively. A line comment starts with "//" and ends either with an end-of-line ("\n") or the end of the "string".