aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience/jackcess/impl/expr
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2018-10-05 19:11:18 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2018-10-05 19:11:18 +0000
commit11b92ba49dcad2db58255e557055dea3a27bd78b (patch)
tree804e151c5ee586b9f9d2d87920fca7217aea6297 /src/main/java/com/healthmarketscience/jackcess/impl/expr
parent535e01e48552081565dc76b98148fa0a2a67c52d (diff)
downloadjackcess-11b92ba49dcad2db58255e557055dea3a27bd78b.tar.gz
jackcess-11b92ba49dcad2db58255e557055dea3a27bd78b.zip
add support for strconv function
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@1207 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/impl/expr')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java48
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/expr/ValueSupport.java30
2 files changed, 63 insertions, 15 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java
index 4a6da20..42212cf 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/DefaultTextFunctions.java
@@ -23,6 +23,7 @@ import com.healthmarketscience.jackcess.expr.EvalException;
import com.healthmarketscience.jackcess.expr.Function;
import com.healthmarketscience.jackcess.expr.LocaleContext;
import com.healthmarketscience.jackcess.expr.Value;
+import org.apache.commons.lang.WordUtils;
import static com.healthmarketscience.jackcess.impl.expr.DefaultFunctions.*;
import static com.healthmarketscience.jackcess.impl.expr.FunctionSupport.*;
@@ -32,6 +33,9 @@ import static com.healthmarketscience.jackcess.impl.expr.FunctionSupport.*;
*/
public class DefaultTextFunctions
{
+ // mask to separate the case conversion value (first two bits) from the char
+ // conversion value for the StrConv() function
+ private static final int STR_CONV_MASK = 0x03;
private DefaultTextFunctions() {}
@@ -317,6 +321,50 @@ public class DefaultTextFunctions
}
});
+ public static final Function STRCONV = registerStringFunc(new FuncVar("StrConv", 2, 3) {
+ @Override
+ protected Value evalVar(EvalContext ctx, Value[] params) {
+ Value param1 = params[0];
+ if(param1.isNull()) {
+ return ValueSupport.NULL_VAL;
+ }
+
+ String str = param1.getAsString(ctx);
+ int conversion = params[1].getAsLongInt(ctx);
+ // TODO, for now, ignore locale id...?
+ // int localeId = params[2];
+
+ int caseConv = STR_CONV_MASK & conversion;
+ int charConv = (~STR_CONV_MASK) & conversion;
+
+ switch(caseConv) {
+ case 1:
+ // vbUpperCase
+ str = str.toUpperCase();
+ break;
+ case 2:
+ // vbLowerCase
+ str = str.toLowerCase();
+ break;
+ case 3:
+ // vbProperCase
+ str = WordUtils.capitalize(str.toLowerCase());
+ break;
+ default:
+ // do nothing
+ }
+
+ if(charConv != 0) {
+ // 64 = vbUnicode, all java strings are already unicode,so nothing to do
+ if(charConv != 64) {
+ throw new EvalException("Unsupported character conversion " + charConv);
+ }
+ }
+
+ return ValueSupport.toValue(str);
+ }
+ });
+
public static final Function STRING = registerStringFunc(new Func2("String") {
@Override
protected Value eval2(EvalContext ctx, Value param1, Value param2) {
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/expr/ValueSupport.java b/src/main/java/com/healthmarketscience/jackcess/impl/expr/ValueSupport.java
index 06833de..621ed37 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/expr/ValueSupport.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/expr/ValueSupport.java
@@ -96,21 +96,21 @@ public class ValueSupport
}
public static DateFormat getDateFormatForType(LocaleContext ctx, Value.Type type) {
- String fmtStr = null;
- switch(type) {
- case DATE:
- fmtStr = ctx.getTemporalConfig().getDefaultDateFormat();
- break;
- case TIME:
- fmtStr = ctx.getTemporalConfig().getDefaultTimeFormat();
- break;
- case DATE_TIME:
- fmtStr = ctx.getTemporalConfig().getDefaultDateTimeFormat();
- break;
- default:
- throw new EvalException("Unexpected date/time type " + type);
- }
- return ctx.createDateFormat(fmtStr);
+ String fmtStr = null;
+ switch(type) {
+ case DATE:
+ fmtStr = ctx.getTemporalConfig().getDefaultDateFormat();
+ break;
+ case TIME:
+ fmtStr = ctx.getTemporalConfig().getDefaultTimeFormat();
+ break;
+ case DATE_TIME:
+ fmtStr = ctx.getTemporalConfig().getDefaultDateTimeFormat();
+ break;
+ default:
+ throw new EvalException("Unexpected date/time type " + type);
+ }
+ return ctx.createDateFormat(fmtStr);
}
/**