[DFDL-WG] Clarification needed: textNumberFormat quoting and prefix/suffix

Mike Beckerle mbeckerle at apache.org
Wed Jan 11 14:44:22 PST 2023


I created an ICU DecimalFormat string where the positive sign is the word
POSITIVE, and the negative sign is the word NEGATIVE.

Per unit test below, this works in ICU, so long as they are escaped,
because "E" is a special character in the ICU pattern language.

But...  I can find no example of this online for ICU nor DFDL.

All examples are of a sign being just a single character, or a pair of
single characters before and after for negative values.

So my question: Do we intend DFDL to support this full generality, or only
single characters for the prefix/suffix regions of the textNumberPattern?

Right now I think Daffodil requires the sign to be a single character,
which can be one of the special characters only by quoting it individually.
E.g., if I wanted the positive sign to be P and negative sign to be N, then
I'd use textNumberPattern:

'P'#0.0#;'N'#0.0#

I don't have to quote the N, but I did just for consistency.

If we want the full generality, I'd appreciate a realistic motivating
example of it.

/**
 * This test shows that quoting of characters in ICU text number patterns

 * and hence DFDL text number patterns can quote strings, not just individual
 * characters.
 *
 * I found no examples of this anywhere. Everything shows patterns where
 * quotes surround only single characters, or are doubled up for self
quoting as in
 * the o''clock example.
 */
@Test def testICUDecimalFormatQuoting_01(): Unit = {
  {
    // Note that E is a pattern special character
    val pattern = "'POSITIVE' #.0###;'NEGATIVE' #.0###"
    val df = new DecimalFormat(pattern)
    val actual = df.format(-6.847)
    assertEquals("NEGATIVE 6.847", actual)

  }

  {
    // here we quote only the E, not the other characters.
    val pattern = "POSITIV'E' #.0###;NEGATIV'E' #.0###"
    val df = new DecimalFormat(pattern)
    val actual = df.format(6.847)
    assertEquals("POSITIVE 6.847", actual)
  }
}


Mike Beckerle
Apache Daffodil PMC | daffodil.apache.org
OGF DFDL Workgroup Co-Chair | www.ogf.org/ogf/doku.php/standards/dfdl/dfdl
Owl Cyber Defense | www.owlcyberdefense.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/html
Size: 6452 bytes
Desc: not available
URL: <https://lists.ogf.org/pipermail/dfdl-wg/attachments/20230111/6d03b144/attachment.txt>


More information about the dfdl-wg mailing list