This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git
The following commit(s) were added to refs/heads/master by this push:
new df0780e Require grouping and decimal separators for non-integer types
df0780e is described below
commit df0780eee240a64a2d528e5019167ba9f3db5c0a
Author: Steve Lawrence <[email protected]>
AuthorDate: Wed Apr 8 13:43:12 2020 -0400
Require grouping and decimal separators for non-integer types
Even if the textNumberPattern does not include decimal or grouping
separators, ICU still looks for those separators when the primType is
not an integer. If we do not require and apply the grouping and decimal
separators for these prim types, ICU will get them from the users
LANG, which means our behavior is not system environment interdependent.
To fix this, this requires and applies the decimal and grouping
separator properties for float primTypes, even if textNumberPattern does
not specify the separators.
DAFFODIL-2320
---
.../grammar/primitives/PrimitivesTextNumber.scala | 13 +++++++++--
.../grammar/primitives/PrimitivesZoned.scala | 1 +
.../apache/daffodil/processors/EvTextNumber.scala | 6 +----
.../text_number_props/TextNumberProps.tdml | 27 ++++++++++++++++++++++
.../text_number_props/TestTextNumberProps.scala | 2 ++
5 files changed, 42 insertions(+), 7 deletions(-)
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesTextNumber.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesTextNumber.scala
index 160e640..44b3569 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesTextNumber.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesTextNumber.scala
@@ -109,15 +109,23 @@ case class ConvertTextNumberPrim(e: ElementBase)
case _ => (Nope, Nope)
}
+ val isInt = e.primType match {
+ case PrimType.Double | PrimType.Float | PrimType.Decimal => false
+ case _ => true
+ }
+
// If the pattern contains any of these characters, we need to set both
// group and decimal separators, even if the pattern doesn't contain the
// associated character. This is because even when the pattern does not
// contain the grouping/decimal separators, ICU stills seems to take the
// separators into account. And since ICU provides defaut values based on
- // locales, not setting them can cause subtle locale related bugs.
+ // locales, not setting them can cause subtle locale related bugs. We must
+ // also require the separators if the prim type is not an integer type,
+ // since ICU will use them even if the pattern does not specify them.
val requireDecGroupSeps =
patternStripped.contains(",") || patternStripped.contains(".") ||
- patternStripped.contains("E") || patternStripped.contains("@")
+ patternStripped.contains("E") || patternStripped.contains("@") ||
+ !isInt
val decSep =
if (requireDecGroupSeps) {
@@ -146,6 +154,7 @@ case class ConvertTextNumberPrim(e: ElementBase)
roundingMode,
roundingIncrement,
zeroRepsRaw,
+ isInt,
e.primType)
ev.compile(tunable)
ev
diff --git
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesZoned.scala
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesZoned.scala
index e2e2e52..a17845a 100644
---
a/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesZoned.scala
+++
b/daffodil-core/src/main/scala/org/apache/daffodil/grammar/primitives/PrimitivesZoned.scala
@@ -132,6 +132,7 @@ case class ConvertZonedNumberPrim(e: ElementBase)
roundingMode,
roundingIncrement,
Nil,
+ isInt = true,
e.primType)
ev.compile(tunable)
ev
diff --git
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/EvTextNumber.scala
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/EvTextNumber.scala
index 88e0bc1..a972515 100644
---
a/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/EvTextNumber.scala
+++
b/daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/EvTextNumber.scala
@@ -79,17 +79,13 @@ class TextNumberFormatEv(
roundingMode: Maybe[TextNumberRoundingMode],
roundingIncrement: MaybeDouble,
zeroRepsRaw: List[String],
+ isInt: Boolean,
primType: PrimType)
extends Evaluatable[ThreadLocal[DecimalFormat]](tci)
with InfosetCachedEvaluatable[ThreadLocal[DecimalFormat]] {
override lazy val runtimeDependencies = (decimalSepEv.toList ++
groupingSepEv.toList ++ exponentRepEv.toList).toVector
- private val isInt = primType match {
- case PrimType.Double | PrimType.Float | PrimType.Decimal => false
- case _ => true
- }
-
private def checkUnique(
decimalSep: MaybeChar,
groupingSep: MaybeChar,
diff --git
a/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberProps.tdml
b/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberProps.tdml
index 4a22626..c731f02 100644
---
a/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberProps.tdml
+++
b/daffodil-test/src/test/resources/org/apache/daffodil/section13/text_number_props/TextNumberProps.tdml
@@ -296,6 +296,10 @@
</xs:complexType>
</xs:element>
+ <xs:element name="tnp96" type="xs:float" dfdl:textNumberPattern="####"
+ dfdl:textStandardGroupingSeparator="."
dfdl:textStandardDecimalSeparator=","
+ dfdl:textNumberRoundingIncrement="0.1"
dfdl:textNumberRoundingMode="roundHalfEven" />
+
</tdml:defineSchema>
<tdml:defineSchema name="textNumberPattern2" elementFormDefault="qualified">
@@ -4261,4 +4265,27 @@
</tdml:errors>
</tdml:parserTestCase>
+
+ <!--
+ Test Name: textStandardFloatPatternNoSeparators
+ Schema: textNumberPattern
+ Root: tnp96
+ Purpose: This test shows what even if the textNumberPattern contains
+ no grouping/decimal separators, we still require and use the
+ properties because ICU uses them for non-integer types
+ -->
+
+ <tdml:parserTestCase name="textStandardFloatPatternNoSeparators1"
root="tnp96" model="textNumberPattern">
+
+ <tdml:document>
+ <tdml:documentPart type="text">10,1</tdml:documentPart>
+ </tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <tnp96>10.1</tnp96>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+
+ </tdml:parserTestCase>
+
</tdml:testSuite>
diff --git
a/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberProps.scala
b/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberProps.scala
index 7b73182..1cb388e 100644
---
a/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberProps.scala
+++
b/daffodil-test/src/test/scala/org/apache/daffodil/section13/text_number_props/TestTextNumberProps.scala
@@ -237,4 +237,6 @@ class TestTextNumberProps {
@Test def test_textStandardDistinctValues() {
runner.runOneTest("textStandardDistinctValues") }
@Test def test_textStandardDistinctValues2() {
runner.runOneTest("textStandardDistinctValues2") }
@Test def test_textStandardDistinctValues3() {
runner.runOneTest("textStandardDistinctValues3") }
+
+ @Test def test_textStandardFloatPatternNoSeparators1() {
runner.runOneTest("textStandardFloatPatternNoSeparators1") }
}