List of usage examples for java.lang StringBuilder insert
@Override public StringBuilder insert(int offset, double d)
From source file:by.heap.remark.convert.TextCleaner.java
/** * Configures the basic escapes based on the configured options. * @param options Options that will affect what is escaped. *//*from w ww . jav a2 s .co m*/ private void setupEscapes(Options options) { escapes = new ArrayList<Escape>(); // confusingly, this replaces single backslashes with double backslashes. // Man, I miss Groovy's slashy strings in these moments... escapes.add(new Escape("\\\\", "\\\\\\\\")); // creates an set of characters that are universally escaped. // these characters are wrapped in \Q...\E to ensure they aren't treated as special characters. StringBuilder chars = new StringBuilder("([\\Q`*_{}[]#"); if (options.tables.isConvertedToText() && !options.tables.isRenderedAsCode()) { chars.append('|'); } chars.append("\\E])"); escapes.add(new Escape(chars.toString(), "\\\\$1")); // finally, escape certain characters only if they are leading characters StringBuilder leadingChars = new StringBuilder("^( ?+)([\\Q-+"); if (options.definitionLists) { leadingChars.append(':'); } leadingChars.append("\\E])"); escapes.add(new Escape(leadingChars.toString(), "$1\\\\$2")); // setup the leading character reverser // this is a bit of a hack to undo leading character escapes. unescapeLeadingChars = Pattern.compile(leadingChars.insert(6, "\\\\").toString()); }
From source file:com.edgenius.wiki.render.GroupProcessor.java
/** * Insert a group key as macro parameter * @param start /*from w w w. j a v a 2s . com*/ * @param sb */ public void insertGroupKey(int start, StringBuilder sb) { Macro macro = childrenMap.get(start); if (macro == null) { AuditLogger.error("Unable to find macro in position"); return; } int sep; String first = ":"; String last = ""; for (sep = start; sep < sb.length(); sep++) { char c = sb.charAt(sep); if (c == '}') { break; } if (c == ' ') continue; if (c == ':') { sep++; first = ""; last = "|"; break; } } //insert after macro name, such as "{table" and the space after macro name will be next char of insertion. sb.insert(sep, first + Macro.GROUP_KEY + "=" + getGroupKey(start) + last); }
From source file:de.axelfaust.alfresco.nashorn.repo.loaders.AlfrescoClasspathURLStreamHandler.java
protected List<String> getOrCreatePrecedenceChain(final String script, final boolean allowExtension) { final Pair<String, Boolean> key = new Pair<String, Boolean>(script, Boolean.valueOf(allowExtension)); List<String> precendenceChain = this.precedenceChainByScript.get(key); if (precendenceChain == null) { precendenceChain = new ArrayList<String>(); this.precedenceChainByScript.put(key, precendenceChain); if (script.endsWith(".js") || script.endsWith(".nashornjs")) { precendenceChain.add(script); } else {/*www . j ava 2 s . co m*/ final StringBuilder pathBuilder = new StringBuilder(script); final int basePathLength = this.basePath != null ? this.basePath.trim().length() : 0; final int extensionPathLength = allowExtension && this.extensionPath != null ? this.extensionPath.trim().length() : 0; for (final String suffix : SUFFIX_PRECEDENCE_LIST) { if (suffix != null) { pathBuilder.append(suffix); } if (extensionPathLength > 0) { if (basePathLength > 0) { pathBuilder.insert(basePathLength, '/'); pathBuilder.insert(basePathLength + 1, this.extensionPath); } else { pathBuilder.insert(0, this.extensionPath); pathBuilder.insert(extensionPathLength, '/'); } precendenceChain.add(pathBuilder.toString()); if (basePathLength > 0) { pathBuilder.delete(basePathLength, basePathLength + extensionPathLength + 1); } else { pathBuilder.delete(0, extensionPathLength + 1); } } precendenceChain.add(pathBuilder.toString()); if (suffix != null) { pathBuilder.delete(pathBuilder.length() - suffix.length(), pathBuilder.length()); } } } } return precendenceChain; }
From source file:com.mediaworx.intellij.opencmsplugin.sync.SyncJob.java
private void doDeleteFromVfs(SyncEntity entity) { StringBuilder confirmation = new StringBuilder("DELETE ").append(entity.getVfsPath()) .append(" (not in the RFS) - "); if (adapter.deleteResource(entity.getVfsPath())) { confirmation.append(" SUCCESS"); console.info(confirmation.toString()); } else {/*ww w .ja va 2 s.c o m*/ confirmation.insert(0, "ERROR: "); confirmation.append(" FAILED!"); console.error(confirmation.toString()); } }
From source file:com.redhat.rhn.frontend.taglibs.list.SelectableColumnTag.java
private String getIgnorableParentIds() { ListTag parent = (ListTag) BodyTagSupport.findAncestorWithClass(this, ListTag.class); if (!parent.isParentAnElement()) { StringBuilder buf = new StringBuilder(); for (Object current : parent.getPageData()) { if (RhnListTagFunctions.isExpandable(current)) { if (buf.length() > 0) { buf.append(","); }/*from w w w . java 2s . com*/ buf.append("'"); buf.append(makeCheckboxId(listName, ListTagHelper.getObjectId(current))); buf.append("'"); } } buf.insert(0, "["); buf.append("]"); return buf.toString(); } return "[]"; }
From source file:cz.lbenda.dataman.db.sql.SQLEditorController.java
/** Return text which will be executed. * @param onCaretPosition return executed text on caret position */ public String[] getExecutedText(boolean onCaretPosition) { CodeArea codeArea = textEditor.getCodeArea(); String text = textEditor.getSelectedText(); if (text == null || "".equals(text)) { text = textEditor.getText();//from ww w . j a va 2 s . c o m if (onCaretPosition) { int caretPosition = codeArea.caretPositionProperty().getValue(); String bf = "", af = ""; if (caretPosition > 0) { bf = text.substring(0, caretPosition); } if (caretPosition < text.length()) { af = text.substring(caretPosition, text.length()); } String[] bfs = bf.split("\n"); String[] afs = af.split("\n"); StringBuilder sb = new StringBuilder(); boolean rowStart = caretPosition == 0 || bf.charAt(bf.length() - 1) == '\n'; boolean skipBf = caretPosition == 0; if (!skipBf && rowStart) { int prevRecord = bf.substring(0, bf.length() - 1).lastIndexOf("\n"); if (prevRecord >= 0) { skipBf = StringUtils.isBlank(bf.substring(prevRecord, bf.length() - 1)); } } if (!skipBf) { for (int i = bfs.length - 1; i >= 0 && StringUtils.isNoneBlank(bfs[i]); i--) { if (i == bfs.length - 1 && !rowStart) { sb.insert(0, bfs[i]); } else { sb.insert(0, bfs[i] + "\n"); } } } for (int i = 0; i < afs.length && StringUtils.isNoneBlank(afs[i]); i++) { sb.append(afs[i]).append("\n"); } text = sb.toString(); } } return SQLSExecutor.splitSQLS(text); }
From source file:com.splicemachine.db.impl.sql.compile.QueryTreeNode.java
/** * Format a node that has been converted to a String for printing * as part of a tree. This method indents the String to the given * depth by inserting tabs at the beginning of the string, and also * after every newline.// w w w. j ava 2 s.c o m * * @param nodeString The node formatted as a String * @param depth The depth to indent the given node * @return The node String reformatted with tab indentation */ public static String formatNodeString(String nodeString, int depth) { if (SanityManager.DEBUG) { StringBuilder nodeStringBuffer = new StringBuilder(nodeString); int pos; char c; char[] indent = new char[depth]; /* ** Form an array of tab characters for indentation. */ while (depth > 0) { indent[depth - 1] = '\t'; depth--; } /* Indent the beginning of the string */ nodeStringBuffer.insert(0, indent); /* ** Look for newline characters, except for the last character. ** We don't want to indent after the last newline. */ for (pos = 0; pos < nodeStringBuffer.length() - 1; pos++) { c = nodeStringBuffer.charAt(pos); if (c == '\n') { /* Indent again after each newline */ nodeStringBuffer.insert(pos + 1, indent); } } return nodeStringBuffer.toString(); } else { return ""; } }
From source file:Heuristics.TermLevelHeuristics.java
public boolean isQuestionMarkAtEndOfStatus(String status) { List<String> terms = new ArrayList(); Collections.addAll(terms, status.split(" ")); StringBuilder sb = new StringBuilder(); boolean cleanEnd = false; ListIterator<String> termsIterator = terms.listIterator(terms.size()); while (termsIterator.hasPrevious() & !cleanEnd) { String string = termsIterator.previous(); if (!cleanEnd && (string.contains("/") || string.startsWith("#") || string.startsWith("@") || string.equals("\\|") || string.equals("") || string.contains("via") || string.equals("..."))) { continue; } else {/*from w w w . ja v a 2 s . c o m*/ cleanEnd = true; } sb.insert(0, string); } status = sb.toString().trim(); if (status.length() == 0) { return false; } else { return ("?".equals(String.valueOf(status.charAt(status.length() - 1)))) ? true : false; } }
From source file:com.mediaworx.intellij.opencmsplugin.sync.SyncJob.java
private void doDeleteFromRfs(SyncEntity entity) { StringBuilder confirmation = new StringBuilder("DELETE ").append(entity.getVfsPath()).append(" from ") .append(entity.getOcmsModule().getLocalVfsRoot()).append(" (not in the VFS) - "); File rfsFile = entity.getFile(); if (FileUtils.deleteQuietly(rfsFile)) { confirmation.append(" SUCCESS"); console.info(confirmation.toString()); } else {//from w w w . j a v a 2 s . c o m confirmation.insert(0, "ERROR: "); confirmation.append(" FAILED!"); console.error(confirmation.toString()); } }
From source file:com.nway.spring.jdbc.SqlExecutor.java
/** * * @param sql/*from w w w . ja v a 2 s . co m*/ * SQL * @return */ private String buildPaginationCountSql(String sql) { StringBuilder countSql = new StringBuilder(sql); if (SQL_ORDER_BY_PATTERN.matcher(countSql).matches()) { countSql.delete(countSql.lastIndexOf(" ORDER "), countSql.length()); } int firstFromIndex = firstFromIndex(sql, 0); String selectedColumns = countSql.substring(0, firstFromIndex + 1); if (selectedColumns.indexOf(" DISTINCT ") == -1 && !SQL_TOP_PATTERN.matcher(selectedColumns).matches()) { countSql = countSql.delete(0, firstFromIndex).insert(0, "SELECT COUNT(1)"); } else { countSql.insert(0, "SELECT COUNT(1) FROM (").append(')'); } return countSql.toString(); }