swirl
Guide to OmniMark 8   OmniMark home
docs home 
IndexConceptsTasksSyntaxLibrariesLegacy LibrariesErrors
 
     

String data: formatting

You will encounter string-like data in many places in an OmniMark program:

You can output a string value directly. The following program outputs the value of a stream variable, the value of a literal string, the value of a pattern variable, another literal string, and a source:

  find letter+ => file-name
      local stream file-name initial {"The file"}
      output first-name
          || " named "
          || file-name
          || " contains%n"
          || file file-name

You can format string data using the "g" format command with either a format item or the format operator. By itself, the "g" format command does not change the original format of the string. However, you can use "g" in a format item to output the contents of a stream within a string expression:

  process
      local stream first-name initial {"John"}
      output "Hello %g(first-name)"

To change the format of a string, you can add a format modifier to the "g" format command. For example, you can use the "l" and "u" format modifiers to force the string to lowercase or uppercase, respectively. The following program outputs "johnJOHN":

  process
      local stream first-name initial {"John"}
      output "Hello "
          || "lg" % first-name
          || "ug" % first-name

You can use the "f" format modifier to pad the string to a specified width. Spaces are added on the right to make up the width. If the string is longer than the specified width, the full string is output. The following program outputs [John ]:

  process
      local stream first-name initial {"John"}
      output "[" || "8fg" % first-name || "]"

You can use the "k" format modifier with the "f" modifier to pad the string to the left instead of the right: The following program outputs [ John]:

  process
      local stream first-name initial {"John"}
      output "[" || "8fkg" % first-name || "]"

You can use any reasonable combination of these modifiers together.

Format items can be used only with variables. However, you can use the fomrat operator with any type of expressions. You can use the format command "g" with the format operator to format the result of any type of string expression. For instance:

  element "codeblock"
      output "lg" % attribute "language"

In earlier versions of OmniMark, the "g" format command could not be used to format pattern variables. You had to use the "x" format item instead. The use of the "x" format command is now deprecated.

There are also format commands that can be used only in format items and are used to access and format various artifacts of markup parsing. These include, "c" (the parse continuation operator), "q" (which deals with element names), and "v" (which deals with attributes and external-data-entities).

     
 

Top [ INDEX ] [ CONCEPTS ] [ TASKS ] [ SYNTAX ] [ LIBRARIES ] [ LEGACY LIBRARIES ] [ ERRORS ]

OmniMark 8.2.0 Documentation Generated: March 13, 2008 at 3:25:49 pm
If you have any comments about this section of the documentation, please use this form.

Copyright © Stilo International plc, 1988-2008.