From 762312dd4904a77283b2fa849e0c5baca6c68d5a Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 5 Oct 2018 19:09:25 +0000 Subject: [PATCH] handle alternate decimal separators based on numeric config git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1205 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/expr/StringValue.java | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java index d3b829b..9988477 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/StringValue.java @@ -18,10 +18,10 @@ package com.healthmarketscience.jackcess.impl.expr; import java.math.BigDecimal; import java.math.BigInteger; +import java.text.DecimalFormatSymbols; import java.util.regex.Pattern; import com.healthmarketscience.jackcess.expr.LocaleContext; -import org.apache.commons.lang.CharUtils; import org.apache.commons.lang.StringUtils; /** @@ -37,6 +37,7 @@ public class StringValue extends BaseValue Pattern.compile(NUMBER_BASE_PREFIX + "[oO][0-7]+"); private static final Pattern HEX_PAT = Pattern.compile(NUMBER_BASE_PREFIX + "[hH]\\p{XDigit}+"); + private static final char CANON_DEC_SEP = '.'; private final String _val; private Object _num; @@ -93,11 +94,8 @@ public class StringValue extends BaseValue if(tmpVal.length() > 0) { if(tmpVal.charAt(0) != NUMBER_BASE_PREFIX) { - // parse using standard numeric support, after discarding any - // grouping separators - char groupSepChar = ctx.getNumericConfig().getDecimalFormatSymbols() - .getGroupingSeparator(); - tmpVal = StringUtils.remove(tmpVal, groupSepChar); + // convert to standard numeric support for parsing + tmpVal = toCanonicalNumberFormat(ctx, tmpVal); _num = ValueSupport.normalize(new BigDecimal(tmpVal)); return (BigDecimal)_num; } @@ -123,4 +121,21 @@ public class StringValue extends BaseValue _num = new BigDecimal(new BigInteger(tmpVal.substring(2), radix)); return (BigDecimal)_num; } + + private static String toCanonicalNumberFormat(LocaleContext ctx, String tmpVal) + { + // convert to standard numeric format: + // - discard any grouping separators + // - convert decimal separator to '.' + DecimalFormatSymbols syms = ctx.getNumericConfig().getDecimalFormatSymbols(); + char groupSepChar = syms.getGroupingSeparator(); + tmpVal = StringUtils.remove(tmpVal, groupSepChar); + + char decSepChar = syms.getDecimalSeparator(); + if((decSepChar != CANON_DEC_SEP) && (tmpVal.indexOf(decSepChar) >= 0)) { + tmpVal = tmpVal.replace(decSepChar, CANON_DEC_SEP); + } + + return tmpVal; + } } -- 2.39.5