List of usage examples for org.apache.commons.lang.text StrBuilder length
public int length()
From source file:bboss.org.apache.velocity.runtime.parser.node.NodeUtils.java
/** * complete node literal// w ww .j av a 2 s .com * @param t * @return A node literal. */ public static String tokenLiteral(Token t) { // Look at kind of token and return "" when it's a multiline comment if (t.kind == ParserConstants.MULTI_LINE_COMMENT) { return ""; } else if (t.specialToken == null || t.specialToken.image.startsWith("##")) { return t.image; } else { StrBuilder special = getSpecialText(t); if (special.length() > 0) { return special.append(t.image).toString(); } return t.image; } }
From source file:com.applerox.jack.AppleCommands.AppleCommands.java
public static String finalArg(String[] strings, int pos) { StrBuilder sb = new StrBuilder(); for (int i = pos; i < strings.length; i++) { sb.append(strings[i]);/*from w w w . j av a 2s .co m*/ sb.append(" "); } return sb.substring(0, sb.length() - 1); }
From source file:com.antsdb.saltedfish.sql.vdm.ExprUtil.java
/** * <p>Unescapes any Java literals found in the <code>String</code> to a * <code>Writer</code>.</p> * * <p>For example, it will turn a sequence of <code>'\'</code> and * <code>'n'</code> into a newline character, unless the <code>'\'</code> * is preceded by another <code>'\'</code>.</p> * //from ww w .ja v a 2s .co m * <p>A <code>null</code> string input has no effect.</p> * * @see http://dev.mysql.com/doc/refman/5.7/en/string-literals.html * * @param out the <code>Writer</code> used to output unescaped characters * @param str the <code>String</code> to unescape, may be null * @throws IllegalArgumentException if the Writer is <code>null</code> * @throws IOException if error occurs on underlying Writer */ public static void unescapeJava(Writer out, String str) throws IOException { if (out == null) { throw new IllegalArgumentException("The Writer must not be null"); } if (str == null) { return; } int sz = str.length(); StrBuilder unicode = new StrBuilder(4); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { // if in unicode, then we're reading unicode // values in somehow unicode.append(ch); if (unicode.length() == 4) { // unicode now contains the four hex digits // which represents our unicode character try { int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe); } } continue; } if (hadSlash) { // handle an escaped value hadSlash = false; switch (ch) { case '0': out.write(0); break; case '\'': out.write('\''); break; case '\"': out.write('"'); break; case 'b': out.write('\b'); break; case 'n': out.write('\n'); break; case 'r': out.write('\r'); break; case 't': out.write('\t'); break; case 'Z': out.write(26); break; case '\\': out.write('\\'); break; case '%': out.write('%'); break; case '_': out.write('_'); break; case 'u': { // uh-oh, we're in unicode country.... inUnicode = true; break; } default: out.write(ch); } continue; } else if (ch == '\\') { hadSlash = true; continue; } out.write(ch); } if (hadSlash) { // then we're in the weird case of a \ at the end of the // string, let's output it anyway. out.write('\\'); } }
From source file:bboss.org.apache.velocity.runtime.parser.node.NodeUtils.java
/** * Utility method to interpolate context variables * into string literals. So that the following will * work:// ww w .j a v a 2 s. c o m * * #set $name = "candy" * $image.getURI("${name}.jpg") * * And the string literal argument will * be transformed into "candy.jpg" before * the method is executed. * * @deprecated this method isn't called by any class * * @param argStr * @param vars * @return Interpoliation result. * @throws MethodInvocationException */ public static String interpolate(String argStr, Context vars) throws MethodInvocationException { // if there's nothing to replace, skip this (saves buffer allocation) if (argStr.indexOf('$') == -1) return argStr; StrBuilder argBuf = new StrBuilder(); for (int cIdx = 0, is = argStr.length(); cIdx < is;) { char ch = argStr.charAt(cIdx); if (ch == '$') { StrBuilder nameBuf = new StrBuilder(); for (++cIdx; cIdx < is; ++cIdx) { ch = argStr.charAt(cIdx); if (ch == '_' || ch == '-' || Character.isLetterOrDigit(ch)) nameBuf.append(ch); else if (ch == '{' || ch == '}') continue; else break; } if (nameBuf.length() > 0) { Object value = vars.get(nameBuf.toString()); if (value == null) argBuf.append("$").append(nameBuf.toString()); else argBuf.append(value.toString()); } } else { argBuf.append(ch); ++cIdx; } } return argBuf.toString(); }
From source file:de.iteratec.iteraplan.presentation.tags.StringEscapeUtilsFunction.java
public static void unescapeJava(Writer out, String str) throws IOException { if (out == null) { throw new IllegalArgumentException("The Writer must not be null"); }/*from w w w . j av a 2 s . co m*/ if (str == null) { return; } int sz = str.length(); StrBuilder unicode = new StrBuilder(4); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { // if in unicode, then we're reading unicode // values in somehow unicode.append(ch); if (unicode.length() == 4) { // unicode now contains the four hex digits // which represents our unicode character try { int value = Integer.parseInt(unicode.toString(), 16); out.write((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe); } } continue; } if (hadSlash) { hadSlash = false; switch (ch) { case '\\': out.write('\\'); break; case '\'': out.write('\''); break; case '\"': out.write('"'); break; case 'r': out.write('\r'); break; case 'f': out.write('\f'); break; case 't': out.write('\t'); break; case 'n': out.write('\n'); break; case 'b': out.write('\b'); break; case 'u': { inUnicode = true; break; } default: out.write(ch); break; } continue; } else if (ch == '\\') { hadSlash = true; continue; } out.write(ch); } if (hadSlash) { out.write('\\'); } }
From source file:com.hmsinc.epicenter.integrator.service.event.AbstractHL7EventHandler.java
/** * @param adt/* w ww . j ava 2 s. co m*/ * @return * @throws HL7Exception */ protected static String extractReason(final ADT_A01 adt) { String ret = null; final CE complaint = adt.getPV2().getAdmitReason(); final StrBuilder reasonBuf = new StrBuilder(); final String complaintId = StringUtils.trimToNull(complaint.getIdentifier().getValue()); final String complaintText = StringUtils.trimToNull(complaint.getText().getValue()); if (complaintId != null && isValidComplaint(complaintId)) { reasonBuf.append(complaintId); } if (complaintText != null && isValidComplaint(complaintText)) { if (reasonBuf.length() > 0) { reasonBuf.append(" "); } reasonBuf.append(complaintText); } ret = StringUtils.trimToNull(reasonBuf.toString()); return ret; }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelper.java
/** * Builds the WHERE clause for comparison filter. This is the base case of * the recursive building of the WHERE clause of the sql query. * * @param whereClause A string builder representing the WHERE clause of the SQL query. * @param queryFilter The query filter.//from ww w. j a v a 2 s. c o m */ private static void buildWhereCluaseForComparisonFilter(StrBuilder whereClause, QueryFilter queryFilter) { StrBuilder first = new StrBuilder(); StrBuilder second = new StrBuilder(); // Build the left part and the right part of the clause according to the filter's type. if (queryFilter instanceof ColumnColumnFilter) { ColumnColumnFilter filter = (ColumnColumnFilter) queryFilter; first.append(getColumnId(filter.getFirstColumn())); second.append(getColumnId(filter.getSecondColumn())); } else { // The filter is a ColumnValueFilter ColumnValueFilter filter = (ColumnValueFilter) queryFilter; first.append(getColumnId(filter.getColumn())); second.append(filter.getValue().toString()); if ((filter.getValue().getType() == ValueType.TEXT) || (filter.getValue().getType() == ValueType.DATE) || (filter.getValue().getType() == ValueType.DATETIME) || (filter.getValue().getType() == ValueType.TIMEOFDAY)) { second.insert(0, "\""); second.insert(second.length(), "\""); } } whereClause.append(buildWhereClauseFromRightAndLeftParts(first, second, ((ComparisonFilter) queryFilter).getOperator())); }
From source file:com.google.visualization.datasource.util.SqlDataSourceHelperTest.java
/** * Tests the building of the SQL query LIMIT and OFFSET clauses from the Gviz * query.//from w ww.j a v a 2s.c om * * @throws InvalidQueryException When there is an error in the query. */ public void testBuildLimitAndOffsetClauses() throws InvalidQueryException { Query query = new Query(); int limit = 2; int offset = 3; // Only offset, default limit. query.setRowOffset(offset); StrBuilder queryStringBuilder = new StrBuilder(); SqlDataSourceHelper.appendLimitAndOffsetClause(query, queryStringBuilder); assertEquals(" OFFSET " + offset, queryStringBuilder.toString()); // Both limit and offset. query.setRowLimit(limit); queryStringBuilder.delete(0, queryStringBuilder.length()); SqlDataSourceHelper.appendLimitAndOffsetClause(query, queryStringBuilder); assertEquals("LIMIT " + limit + " OFFSET " + offset, queryStringBuilder.toString()); // Only limit. query = new Query(); queryStringBuilder.delete(0, queryStringBuilder.length()); query.setRowLimit(limit); SqlDataSourceHelper.appendLimitAndOffsetClause(query, queryStringBuilder); assertEquals("LIMIT " + limit, queryStringBuilder.toString()); // No limit and no offset. query = new Query(); queryStringBuilder.delete(0, queryStringBuilder.length()); SqlDataSourceHelper.appendLimitAndOffsetClause(query, queryStringBuilder); assertEquals("", queryStringBuilder.toString()); }
From source file:net.ymate.platform.webmvc.util.StringEscapeUtils.java
public static String unescapeJava(String str) { if (str == null) { return null; }/*w w w . j av a2s. co m*/ int sz = str.length(); StringBuilder out = new StringBuilder(); StrBuilder unicode = new StrBuilder(4); boolean hadSlash = false; boolean inUnicode = false; for (int i = 0; i < sz; i++) { char ch = str.charAt(i); if (inUnicode) { unicode.append(ch); if (unicode.length() == 4) { try { int value = Integer.parseInt(unicode.toString(), 16); out.append((char) value); unicode.setLength(0); inUnicode = false; hadSlash = false; } catch (NumberFormatException nfe) { throw new NestableRuntimeException("Unable to parse unicode value: " + unicode, nfe); } } continue; } if (hadSlash) { hadSlash = false; switch (ch) { case '\\': out.append('\\'); break; case '\'': out.append('\''); break; case '\"': out.append('"'); break; case 'r': out.append('\r'); break; case 'f': out.append('\f'); break; case 't': out.append('\t'); break; case 'n': out.append('\n'); break; case 'b': out.append('\b'); break; case 'u': { inUnicode = true; break; } default: out.append(ch); break; } continue; } else if (ch == '\\') { hadSlash = true; continue; } out.append(ch); } if (hadSlash) { out.append('\\'); } return out.toString(); }
From source file:org.eclipse.skalli.core.search.LuceneIndex.java
static private void addTerm(StrBuilder query, StrBuilder term, boolean isSimpleTerm) { term.trim();// w w w. j a v a 2s . c o m if (term.length() > 0) { if (query.length() > 0) { query.append(' '); } if (term.equals(AND) || term.equals(OR) || term.equals(NOT) || term.equals(TO)) { isSimpleTerm = false; } if (isSimpleTerm) { query.append('('); query.append('"').append(term).append('"'); query.append(' ').append(term).append('*'); query.append(' ').append(term).append('~'); query.append(')'); } else { query.append(term); } } }