org.sagacity.sqltoy.plugins.function.impl.Trim Maven / Gradle / Ivy
/**
*
*/
package org.sagacity.sqltoy.plugins.function.impl;
import java.util.regex.Pattern;
import org.sagacity.sqltoy.plugins.function.IFunction;
import org.sagacity.sqltoy.utils.DataSourceUtils.DBType;
/**
* @project sqltoy-orm
* @description 字符串去除两边的空白
* @author zhongxuchen
* @version v1.0,Date:2013-3-21
*/
public class Trim extends IFunction {
private static Pattern regex = Pattern.compile("(?i)\\Wtrim\\(");
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.config.function.IFunction#dialects()
*/
@Override
public String dialects() {
return ALL;
}
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.config.function.IFunction#regex()
*/
@Override
public Pattern regex() {
return regex;
}
/*
* (non-Javadoc)
*
* @see org.sagacity.sqltoy.config.function.IFunction#wrap(int,
* java.lang.String[])
*/
@Override
public String wrap(int dialect, String functionName, boolean hasArgs, String... args) {
if (args == null || args.length == 0) {
return super.IGNORE;
}
if (dialect == DBType.SQLSERVER) {
return "rtrim(ltrim(" + args[0] + "))";
}
if (dialect == DBType.H2) {
return "trim(both ' ' from " + args[0] + ")";
}
return super.IGNORE;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy