private def generateNumFormat()

in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/processors/EvTextNumber.scala [129:198]


  private def generateNumFormat(
    decimalSep: MaybeChar,
    groupingSep: MaybeChar,
    exponentRep: Maybe[String]
  ): DecimalFormat = {

    val dfs = new DecimalFormatSymbols()

    if (decimalSep.isDefined) {
      dfs.setDecimalSeparator(decimalSep.get)
    }

    if (groupingSep.isDefined) {
      dfs.setGroupingSeparator(groupingSep.get)
    }

    // TODO: this is allowed to be case insenstive, ICU doesn't support that
    if (exponentRep.isDefined) {
      dfs.setExponentSeparator(exponentRep.get)
    }

    if (infRep.isDefined) {
      // TODO: this is allowed to be case insensitive, ICU doesn't support that
      dfs.setInfinity(infRep.get)
    }

    if (nanRep.isDefined) {
      // TODO: this is allowed to be case insensitive, ICU doesn't support that
      dfs.setNaN(nanRep.get)
    }

    val df = new DecimalFormat(textNumberPattern, dfs)

    val cp = checkPolicy match {
      case TextNumberCheckPolicy.Strict => true
      case TextNumberCheckPolicy.Lax => false
    }
    df.setParseStrict(cp)
    // if strict mode is enabled, we also enable setDecimalPatternMatchRequired. This says that
    // if a decimal point is in the pattern, then the data must contain a decimal point. It also
    // says the reverse, that if a decimal point is not in the pattern, then the data cannot
    // contain a decimal point.
    df.setDecimalPatternMatchRequired(cp)

    rounding match {
      case TextNumberRounding.Pattern => {
        df.setRoundingMode(RoundingMode.HALF_EVEN.ordinal())
      }
      case TextNumberRounding.Explicit => {
        val rm = roundingMode.get match {
          case TextNumberRoundingMode.RoundCeiling => RoundingMode.CEILING
          case TextNumberRoundingMode.RoundFloor => RoundingMode.FLOOR
          case TextNumberRoundingMode.RoundDown => RoundingMode.DOWN
          case TextNumberRoundingMode.RoundUp => RoundingMode.UP
          case TextNumberRoundingMode.RoundHalfEven => RoundingMode.HALF_EVEN
          case TextNumberRoundingMode.RoundHalfDown => RoundingMode.HALF_DOWN
          case TextNumberRoundingMode.RoundHalfUp => RoundingMode.HALF_UP
          case TextNumberRoundingMode.RoundUnnecessary => RoundingMode.UNNECESSARY
        }
        df.setRoundingMode(rm.ordinal())
        df.setRoundingIncrement(roundingIncrement.get)
      }
    }

    if (icuPadPosition.isDefined) {
      df.setPadPosition(icuPadPosition.get)
    }

    df
  }