git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/jdk8@1265 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-3.0.0
@@ -35,7 +35,7 @@ public class NumericConfig | |||
2, true, false, true, 3, Locale.US); | |||
public enum Type { | |||
CURRENCY, FIXED, STANDARD, PERCENT, SCIENTIFIC; | |||
CURRENCY, FIXED, STANDARD, PERCENT, SCIENTIFIC, EURO; | |||
} | |||
private final int _numDecDigits; | |||
@@ -49,6 +49,7 @@ public class NumericConfig | |||
private final String _standardFormat; | |||
private final String _percentFormat; | |||
private final String _scientificFormat; | |||
private final String _euroFormat; | |||
public NumericConfig(int numDecDigits, boolean incLeadingDigit, | |||
boolean useNegParens, boolean useNegCurrencyParens, | |||
@@ -75,6 +76,9 @@ public class NumericConfig | |||
_scientificFormat = FormatUtil.createNumberFormatPattern( | |||
FormatUtil.NumPatternType.SCIENTIFIC, _numDecDigits, true, | |||
false, 0); | |||
_euroFormat = FormatUtil.createNumberFormatPattern( | |||
FormatUtil.NumPatternType.EURO, _numDecDigits, _incLeadingDigit, | |||
_useNegCurrencyParens, _numGroupDigits); | |||
} | |||
public int getNumDecimalDigits() { | |||
@@ -109,6 +113,8 @@ public class NumericConfig | |||
return _percentFormat; | |||
case SCIENTIFIC: | |||
return _scientificFormat; | |||
case EURO: | |||
return _euroFormat; | |||
default: | |||
throw new IllegalArgumentException("unknown number type " + type); | |||
} |
@@ -505,7 +505,7 @@ public class DefaultDateFunctions | |||
return getOptionalIntParam(ctx, params, idx, 1, 0); | |||
} | |||
private static WeekFields weekFields(int firstDay, int firstWeekType) { | |||
static WeekFields weekFields(int firstDay, int firstWeekType) { | |||
int minDays = 1; | |||
switch(firstWeekType) { |
@@ -239,29 +239,34 @@ class ExpressionTokenizer | |||
} | |||
private static String parseQuotedString(ExprBuf buf, char quoteChar) { | |||
return parseStringUntil(buf, quoteChar, null, true); | |||
return parseStringUntil(buf, null, quoteChar, true); | |||
} | |||
private static String parseObjNameString(ExprBuf buf) { | |||
return parseStringUntil(buf, OBJ_NAME_END_CHAR, OBJ_NAME_START_CHAR, false); | |||
return parseStringUntil(buf, OBJ_NAME_START_CHAR, OBJ_NAME_END_CHAR, false); | |||
} | |||
private static String parseDateLiteralString(ExprBuf buf) { | |||
return parseStringUntil(buf, DATE_LIT_QUOTE_CHAR, null, false); | |||
return parseStringUntil(buf, null, DATE_LIT_QUOTE_CHAR, false); | |||
} | |||
private static String parseStringUntil(ExprBuf buf, char endChar, | |||
Character startChar, | |||
boolean allowDoubledEscape) | |||
static String parseStringUntil(ExprBuf buf, Character startChar, | |||
char endChar, boolean allowDoubledEscape) | |||
{ | |||
StringBuilder sb = buf.getScratchBuffer(); | |||
return parseStringUntil(buf, startChar, endChar, allowDoubledEscape, | |||
buf.getScratchBuffer()) | |||
.toString(); | |||
} | |||
static StringBuilder parseStringUntil( | |||
ExprBuf buf, Character startChar, char endChar, boolean allowDoubledEscape, | |||
StringBuilder sb) | |||
{ | |||
boolean complete = false; | |||
while(buf.hasNext()) { | |||
char c = buf.next(); | |||
if(c == endChar) { | |||
if(allowDoubledEscape && (buf.peekNext() == endChar)) { | |||
sb.append(endChar); | |||
buf.next(); | |||
} else { | |||
complete = true; | |||
@@ -281,7 +286,7 @@ class ExpressionTokenizer | |||
"' for quoted string " + buf); | |||
} | |||
return sb.toString(); | |||
return sb; | |||
} | |||
private static Token parseDateLiteral(ExprBuf buf) | |||
@@ -451,7 +456,7 @@ class ExpressionTokenizer | |||
return new AbstractMap.SimpleImmutableEntry<K,V>(a, b); | |||
} | |||
private static final class ExprBuf | |||
static final class ExprBuf | |||
{ | |||
private final String _str; | |||
private final ParseContext _ctx; | |||
@@ -461,7 +466,7 @@ class ExpressionTokenizer | |||
TemporalConfig.Type.class); | |||
private final StringBuilder _scratch = new StringBuilder(); | |||
private ExprBuf(String str, ParseContext ctx) { | |||
ExprBuf(String str, ParseContext ctx) { | |||
_str = str; | |||
_ctx = ctx; | |||
} |
@@ -19,7 +19,6 @@ package com.healthmarketscience.jackcess.impl.expr; | |||
import java.math.BigDecimal; | |||
import java.time.LocalDateTime; | |||
import java.util.Calendar; | |||
import java.util.Date; | |||
import com.healthmarketscience.jackcess.expr.EvalException; | |||
import junit.framework.TestCase; | |||
@@ -145,6 +144,7 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("FOOO", "=UCase(\"fOoO\")"); | |||
assertEval("fooo", "=LCase(\"fOoO\")"); | |||
assertEval(" FOO \" BAR ", "=UCase(\" foo \"\" bar \")"); | |||
assertEval("bl", "=Left(\"blah\", 2)"); | |||
assertEval("", "=Left(\"blah\", 0)"); | |||
@@ -285,6 +285,11 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("-12345.68", "=Format(-12345.6789, 'Fixed')"); | |||
assertEval("-0.12", "=Format(-0.12345, 'Fixed')"); | |||
assertEval("\u20AC12,345.68", "=Format(12345.6789, 'Euro')"); | |||
assertEval("\u20AC0.12", "=Format(0.12345, 'Euro')"); | |||
assertEval("(\u20AC12,345.68)", "=Format(-12345.6789, 'Euro')"); | |||
assertEval("(\u20AC0.12)", "=Format(-0.12345, 'Euro')"); | |||
assertEval("$12,345.68", "=Format(12345.6789, 'Currency')"); | |||
assertEval("$0.12", "=Format(0.12345, 'Currency')"); | |||
assertEval("($12,345.68)", "=Format(-12345.6789, 'Currency')"); | |||
@@ -321,6 +326,16 @@ public class DefaultFunctionsTest extends TestCase | |||
assertEval("07:00", "=Format(#01/02/2003 7:00:00 AM#, 'Short Time')"); | |||
assertEval("19:00", "=Format(#01/02/2003 7:00:00 PM#, 'Short Time')"); | |||
assertEval("07:00 a", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p')"); | |||
assertEval("07:00 a 6 2", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p w ww')"); | |||
assertEval("07:00 a 4 1", "=Format(#01/10/2003 7:00:00 AM#, 'hh:nn a/p w ww', 3, 3)"); | |||
assertEval("1313", "=Format(#01/10/2003 7:13:00 AM#, 'nnnn; foo bar')"); | |||
assertEval("1 1/10/2003 7:13:00 AM ttt this is text", | |||
"=Format(#01/10/2003 7:13:00 AM#, 'q c ttt \"this is text\"')"); | |||
assertEval("1 1/10/2003 ttt this is text", | |||
"=Format(#01/10/2003#, 'q c ttt \"this is text\"')"); | |||
assertEval("4 7:13:00 AM ttt this 'is' \"text\"", | |||
"=Format(#7:13:00 AM#, \"q c ttt \"\"this 'is' \"\"\"\"text\"\"\"\"\"\"\")"); | |||
} | |||
public void testNumberFuncs() throws Exception |