private String format(String src) { StringBuffer result = new StringBuffer(); char[] srcArray = src.toCharArray(); for (int index = 0; index < src.length(); index++) { result.append(srcArray[index]); if (BRACE_LEFT.equals(String.valueOf(srcArray[index]))) { // { result.append(appendLINE_BREAKAndTAB(++TABLength)); // continue; } if (BRACE_RIGHT.equals(String.valueOf(srcArray[index]))) { // } result.insert(result.length() - 1, appendLINE_BREAKAndTAB(--TABLength)); // continue; } if (BRACKET_LEFT.equals(String.valueOf(srcArray[index]))) { // [ result.append(appendLINE_BREAKAndTAB(++TABLength)); // continue; } if (BRACKET_RIGHT.equals(String.valueOf(srcArray[index]))) { // ] result.insert(result.length() - 1, appendLINE_BREAKAndTAB(--TABLength)); // continue; } if (COMMA.equals(String.valueOf(srcArray[index]))) { // , result.append(appendLINE_BREAKAndTAB(TABLength)); // continue; } } return result.toString(); }
private void wire(String header, InputStream instream) throws IOException { StringBuffer buffer = new StringBuffer(); int ch; while ((ch = instream.read()) != -1) { if (ch == 13) { buffer.append("[\\r]"); } else if (ch == 10) { buffer.append("[\\n]\""); buffer.insert(0, "\""); buffer.insert(0, header); log.debug(buffer.toString()); buffer.setLength(0); } else if ((ch < 32) || (ch > 127)) { buffer.append("[0x"); buffer.append(Integer.toHexString(ch)); buffer.append("]"); } else { buffer.append((char) ch); } } if (buffer.length() > 0) { buffer.append("\""); buffer.insert(0, "\""); buffer.insert(0, header); log.debug(buffer.toString()); } }
/** * Returns the nl expression of a property name * * @param s property name * @return String NL-representation */ public static String getNLExpression(String s) { StringBuffer result = new StringBuffer(s); if (s.length() < 3) return s; // LET'S ASSUME FOR NOW THAT ONLY HAPPENS WITH ABBREVIATIONS, WHICH SHOULD BE // CAPITALISED ANYWAY String sub = result.substring(result.length() - 2); // get the last two characters if (sub.equals("Of") || (result.indexOf("For") == (result.length() - 3))) { if (!result.substring(0, 2).toLowerCase().equals("is")) result.insert(0, "Is "); } else if ((sub.equals("By") || sub.equals("As")) && !result.substring(0, 2).toLowerCase().equals("is")) result.insert(0, "Is "); for (int i = 1; i < result.length(); i++) { // replace all capitals with lowercase letters, and add spaces if needed char c = result.charAt(i); if (Character.isUpperCase(c)) { result.setCharAt(i, Character.toLowerCase(c)); if (!(result.charAt(i - 1) == ' ') && !(result.charAt(i - 1) == '_')) result.insert(i, ' '); // insert a space } } result.setCharAt( 0, Character.toUpperCase(result.charAt(0))); // set first character to upper case return result.toString().replaceAll("_", " "); // replace all underscores with spaces }
@Override public void characters(char[] ch, int start, int length) throws SAXException { if (inCell) { StringBuffer t = new StringBuffer(new String(ch, start, length)); // Quote if not all numbers if (all_nums.matcher(t).matches()) { super.characters(ch, start, length); } else { for (int i = t.length() - 1; i >= 0; i--) { if (t.charAt(i) == '\"') { // Double up double quotes t.insert(i, '\"'); i--; } } t.insert(0, '\"'); t.append('\"'); char[] c = t.toString().toCharArray(); super.characters(c, 0, c.length); } } else { super.characters(ch, start, length); } }
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (Beans.isDesignTime()) { super.insertString(offs, str, a); return; } if (!validateEntry) { super.insertString(offs, str, a); validateEntry = true; return; } StringBuffer sb = new StringBuffer(getText(0, getLength())); sb.insert(offs, str); if (sb.toString().equals("-")) { super.insertString(offs, str, a); stringValue = null; value = null; } else { String text = sb.toString(); if (text.equals("-.")) sb.insert(1, "0"); else if (text.equals(".")) sb.insert(0, "0"); Number num = decode(sb.toString()); if (num != null) { super.insertString(offs, str, a); if (text.equals("-.") || text.equals(".")) super.insertString(offs, "0", a); stringValue = sb.toString(); value = num; } } }
/** * Returns the taxonomy hierarchy of this taxon entry in the form: most specific; less specific; * ...; least specific. It follows the chain up the tree as far as it can, and will stop at the * first one it comes to that returns null for getParentNCBITaxID(). If this taxon entry has no * scientific name, you will get the string ".". * * @return the display name as described above. */ public String getNameHierarchy() { StringBuffer sb = new StringBuffer(); boolean first = true; Integer parent = this.getParentNCBITaxID(); while (parent != null) { NCBITaxon t = (NCBITaxon) RichObjectFactory.getObject(SimpleNCBITaxon.class, new Object[] {parent}); Set sciNames = t.getNames(NCBITaxon.SCIENTIFIC); // System.out.println("SimpleNCBITaxon2.getNameHierarchy-t:"+t+", t.isTaxonHidden? // "+t.isTaxonHidden()+", isRoot? "+isRoot(t)+", sciNames:"+sciNames); if (sciNames.size() > 0) { if (!t.isTaxonHidden() && !isRoot(t)) { // root is NOT hidden - but also not displayed if (!first) sb.insert(0, "; "); else first = false; sb.insert(0, (String) sciNames.iterator().next()); } // Don't get into endless loop if child's parent is itself. if (t.getParentNCBITaxID().equals(new Integer(t.getNCBITaxID()))) parent = null; else parent = t.getParentNCBITaxID(); } // Also don't go up past a parent that doesn't have a name. else parent = null; } sb.append("."); return sb.toString(); }
// output an escape sequence for the given character code. protected static int do_escaped(PrintWriter out, char c) { StringBuffer escape = new StringBuffer(); if (c <= 0xFF) { escape.append(Integer.toOctalString(c)); while (escape.length() < 3) { escape.insert(0, '0'); } } else { escape.append(Integer.toHexString(c)); while (escape.length() < 4) { escape.insert(0, '0'); } escape.insert(0, 'u'); } escape.insert(0, '\\'); out.print(escape.toString()); // return size of bytes this takes up in UTF-8 encoding. if (c == 0) { return 2; } if (c >= 0x01 && c <= 0x7F) { return 1; } if (c >= 0x80 && c <= 0x7FF) { return 2; } return 3; }
/** * Redirects the user to the current url over HTTPS * * @param request a HttpServletRequest * @param response a HttpServletResponse * @param urlStr * @param nonSslPort the port Non-SSL requests should be forwarded to * @throws ServletException * @throws IOException */ public static void redirectOverNonSSL( HttpServletRequest request, HttpServletResponse response, String urlStr, int nonSslPort) throws ServletException, IOException { StringBuffer url = new StringBuffer(urlStr); // Make sure we're on http if (url.charAt(4) == 's') url.deleteCharAt(4); // If there is a non-ssl port, make sure we're on it, // otherwise assume we're already on the right port if (nonSslPort > 0) { int portStart = url.indexOf(":", 8) + 1; int portEnd = url.indexOf("/", 8); if (portEnd == -1) // If their isn't a trailing slash, then the end is the last char portEnd = url.length() - 1; if (portStart > 0 && portStart < portEnd) { // If we detected a : before the trailing slash or end of url, delete the // port url.delete(portStart, portEnd); } else { url.insert(portEnd, ':'); // If the url didn't have a port, add in the : portStart = portEnd; } url.insert(portStart, nonSslPort); // Insert the right port where it should be } LogFactory.getLog(ServletUtils.class).debug("redirectOverSSL sending 301: " + url.toString()); sendPermanentRedirect(response, url.toString()); }
public static void insertStyles(StringBuffer buffer, String[] styles) { if (styles == null || styles.length == 0) return; StringBuffer styleBuf = new StringBuffer(10 * styles.length); for (int i = 0; i < styles.length; i++) { styleBuf.append(" style=\""); // $NON-NLS-1$ styleBuf.append(styles[i]); styleBuf.append('"'); } // Find insertion index // a) within existing body tag with trailing space int index = buffer.indexOf("<body "); // $NON-NLS-1$ if (index != -1) { buffer.insert(index + 5, styleBuf); return; } // b) within existing body tag without attributes index = buffer.indexOf("<body>"); // $NON-NLS-1$ if (index != -1) { buffer.insert(index + 5, ' '); buffer.insert(index + 6, styleBuf); return; } }
public String multiply(String num1, String num2) { if (num1 == null || num1.length() == 0) { return num2; } if (num2 == null || num2.length() == 0) { return num1; } int n = num1.length(); int m = num2.length(); int[] result = new int[n + m]; num1 = new StringBuffer(num1).reverse().toString(); num2 = new StringBuffer(num2).reverse().toString(); for (int i = 0; i < n; ++i) { int a = num1.charAt(i) - '0'; for (int j = 0; j < m; ++j) { int b = num2.charAt(j) - '0'; result[i + j] += a * b; } } StringBuffer br = new StringBuffer(); int carry = 0; for (int i = 0; i < result.length; ++i) { result[i] = result[i] + carry; br.insert(0, result[i] % 10); carry = result[i] / 10; } while (carry != 0) { br.insert(0, carry % 10); carry = carry / 10; } while (br.charAt(0) == '0' && br.length() > 1) { br.deleteCharAt(0); } return br.toString(); }
public static String camelCaseToWords(String camelCase, char separator) { // special case if short string if (camelCase == null || camelCase.length() <= 2) { return camelCase; } StringBuffer sb = new StringBuffer(camelCase.length() + 3); sb.append(camelCase.charAt(0)); sb.append(camelCase.charAt(1)); for (int i = 2; i < camelCase.length(); i++) { sb.append(camelCase.charAt(i)); if (camelCase.charAt(i - 2) == separator) { continue; } else if (Character.isUpperCase(camelCase.charAt(i - 1)) && Character.isLowerCase(camelCase.charAt(i))) { sb.insert(sb.length() - 2, separator); } else if (Character.isLowerCase(camelCase.charAt(i - 2)) && Character.isUpperCase(camelCase.charAt(i - 1)) && Character.isUpperCase(camelCase.charAt(i))) { sb.insert(sb.length() - 2, separator); } } // special case if last is upper if (Character.isUpperCase(sb.charAt(sb.length() - 1)) && Character.isLowerCase(sb.charAt(sb.length() - 2))) { sb.insert(sb.length() - 1, ' '); } return sb.toString(); }
protected String[] escapePaths(String srcPath, String dstPath) { srcPath = srcPath.trim(); dstPath = dstPath.trim(); String os = System.getProperty("os.name").toLowerCase(); if (os != null && os.indexOf("windows") > -1) { srcPath = "\"" + srcPath + "\""; dstPath = "\"" + dstPath + "\""; } else { int lastidx = -1, curridx; StringBuffer buff = new StringBuffer(srcPath); while ((curridx = buff.indexOf(" ", lastidx)) > 0) { buff.insert(curridx, "\\"); lastidx = curridx + 2; } srcPath = buff.toString(); buff = new StringBuffer(dstPath); lastidx = -1; while ((curridx = buff.indexOf(" ", lastidx)) > 0) { buff.insert(curridx, "\\"); lastidx = curridx + 2; } dstPath = buff.toString(); } return new String[] {srcPath, dstPath}; }
/** * 添加报文头 CGNB专用 * * @param dgStr * @return */ public static String addDatagramHeadCGNB(String dgStr) { StringBuffer sb = new StringBuffer(dgStr); sb.insert(0, " <?xml version=\"1.0\" encoding=\"gb2312\"?><ROOT>"); sb.append("</ROOT>"); sb.insert(0, "" + (100000000 + sb.length() + "").substring(1)); return sb.toString(); }
/** * theObj is expected to be a JMenu TestObject proxy (Usually a ToggleGUITestObject). Path * information (might not have length > 0). * * <p>We are then going to go UP the tree to make the full path from menubar down to the subitem. * * <p> * * @param theObj -- The JMenu proxy to be evaluated. * @param path -- The initial path provided prior to us filling in the full path up the hierarchy. * This must be the child path of "theObj" * @return GuiSubitemTestObject, the test proxy object of "JMenuBar" or "JPopupMenu". The * parameter path will contain the full path to the ancestor whose type is "JMenuBar" or * "JPopupMenu" */ protected GuiSubitemTestObject getSubMenuItemFullPath(TestObject theObj, StringBuffer path) throws SAFSException { String debugmsg = getClass().getName() + ".getSubMenuItemFullPath() "; String text = null; TestObject proxyObj = new TestObject(theObj.getObjectReference()); GuiSubitemTestObject guiSbuitemObj = null; // Try to get the ancestor of this test object, // The ancestor must be the test proxy object of "MenuBar" or "PopupMenu" boolean isMenuBarOrPopupMenu = false; while ((!isMenuBarOrPopupMenu) && (proxyObj != null)) { if (!isMenuBarOrPopupMenu) { text = getPropertyText(proxyObj); if (path.length() > 0) path.insert(0, text + Tree.PATH_SEPARATOR); else path.insert(0, text); } proxyObj = proxyObj.getMappableParent(); isMenuBarOrPopupMenu = isMenuBar(proxyObj); } if (isMenuBarOrPopupMenu) { guiSbuitemObj = new GuiSubitemTestObject(proxyObj.getObjectReference()); } else { Log.debug( debugmsg + "Can not get ancestor of type 'Menu Bar' or 'Popup Menu' for " + theObj.getObjectClassName()); } return guiSbuitemObj; }
public static void get_assetsScript(String fn, Context c, String prefix, String postfix) { byte[] buffer; final AssetManager assetManager = c.getAssets(); try { InputStream f = assetManager.open(fn); buffer = new byte[f.available()]; f.read(buffer); f.close(); final String s = new String(buffer); final StringBuffer sb = new StringBuffer(s); if (!postfix.equals("")) { sb.append("\n\n" + postfix); } if (!prefix.equals("")) { sb.insert(0, prefix + "\n"); } sb.insert(0, "#!" + Helpers.binExist("sh") + "\n\n"); try { FileOutputStream fos; fos = c.openFileOutput(fn, Context.MODE_PRIVATE); fos.write(sb.toString().getBytes()); fos.close(); } catch (IOException e) { Log.d(TAG, "error write " + fn + " file"); e.printStackTrace(); } } catch (IOException e) { Log.d(TAG, "error read " + fn + " file"); e.printStackTrace(); } }
/** * Read in a GSSCredential from the Java applet's <param> tag. The applet param name is * "sshterm.gsscredential" and the value is the proxy credential string such as one would find in * a "/tmp/x509u_*" proxy file. */ private void readGSSCredentialFromParam() { String gsscredential = getParameter("sshterm.gsscredential"); if ((gsscredential != null) && (gsscredential.length() > 0)) { /* The call to getParameter removes all newlines. So we need * to scan the gsscredential string and add back newlines * for the -----BEGIN----- and -----END----- tags. Otherwise, * the base64 decoder cannot read in the credential. */ StringBuffer sb = new StringBuffer(gsscredential); String dashes = "-----"; String newline = System.getProperty("line.separator"); boolean foundOpeningDashes = false; int fromIndex = 0; while (fromIndex >= 0) { fromIndex = sb.indexOf(dashes, fromIndex); if (fromIndex >= 0) { if (foundOpeningDashes) { // Add newline after closing dashes sb.insert(fromIndex + dashes.length(), newline); } else { // Add newline before opening dashes, except for first if (fromIndex > 0) { sb.insert(fromIndex, newline); } } fromIndex += dashes.length(); // Skip past found dashes foundOpeningDashes = !foundOpeningDashes; } } com.sshtools.j2ssh.authentication.UserGridCredential.setParamGSSCredential(sb.toString()); } }
private int printThreadGroup(OutputSink out, ThreadGroupReference tg, int iThread) { out.println("Group " + tg.name() + ":"); List<ThreadReference> tlist = tg.threads(); int maxId = 0; int maxName = 0; for (int i = 0; i < tlist.size(); i++) { ThreadReference thr = tlist.get(i); int len = Utils.description(thr).length(); if (len > maxId) { maxId = len; } String name = thr.name(); int iDot = name.lastIndexOf('.'); if (iDot >= 0 && name.length() > iDot) { name = name.substring(iDot + 1); } if (name.length() > maxName) { maxName = name.length(); } } String maxNumString = String.valueOf(iThread + tlist.size()); int maxNumDigits = maxNumString.length(); for (int i = 0; i < tlist.size(); i++) { ThreadReference thr = tlist.get(i); char buf[] = new char[80]; for (int j = 0; j < 79; j++) { buf[j] = ' '; } buf[79] = '\0'; StringBuffer sbOut = new StringBuffer(); sbOut.append(buf); // Right-justify the thread number at start of output string String numString = String.valueOf(iThread + i + 1); sbOut.insert(maxNumDigits - numString.length(), numString); sbOut.insert(maxNumDigits, "."); int iBuf = maxNumDigits + 2; sbOut.insert(iBuf, Utils.description(thr)); iBuf += maxId + 1; String name = thr.name(); int iDot = name.lastIndexOf('.'); if (iDot >= 0 && name.length() > iDot) { name = name.substring(iDot + 1); } sbOut.insert(iBuf, name); iBuf += maxName + 1; sbOut.insert(iBuf, Utils.getStatus(thr)); sbOut.setLength(79); out.println(sbOut.toString()); } for (ThreadGroupReference tg0 : tg.threadGroups()) { if (!tg.equals(tg0)) { // TODO ref mgt iThread += printThreadGroup(out, tg0, iThread + tlist.size()); } } return tlist.size(); }
/** * Copy the pattern but quote (bracket with "[&" and "&]") the TmfTimestampFormat specific tags. * Optionally surround tags with single quotes so these fields are treated as comments by the base * class. * * <p>It also keeps track of the corresponding quoted fields so they can be properly populated * later on (by format()). * * @param pattern the 'extended' pattern * @param includeQuotes true to include quotes from pattern and add single quotes around tags * @return the quoted and bracketed pattern */ private String quoteSpecificTags(final String pattern, boolean includeQuotes) { StringBuffer result = new StringBuffer(); int length = pattern.length(); boolean inQuote = false; for (int i = 0; i < length; i++) { char c = pattern.charAt(i); if (c != '\'' || includeQuotes) { result.append(c); } if (c == '\'') { // '' is treated as a single quote regardless of being // in a quoted section. if ((i + 1) < length) { c = pattern.charAt(i + 1); if (c == '\'') { i++; result.append(c); continue; } } inQuote = !inQuote; continue; } if (!inQuote && (fSupplPatternLetters.indexOf(c) != -1)) { if (pattern.charAt(0) == fDecimalSeparator) { if (fSubSecPatternChars.indexOf(c) == -1) { // do not quote non-sub-second pattern letters in sub-second pattern continue; } } else { if (fSubSecPatternChars.indexOf(c) != -1) { // do not quote sub-second pattern letters in date and time pattern continue; } } StringBuilder pat = new StringBuilder(); pat.append(c); if (includeQuotes) { result.insert(result.length() - 1, "'"); // $NON-NLS-1$ } result.insert(result.length() - 1, fOpenBracket); while ((i + 1) < length && pattern.charAt(i + 1) == c) { result.append(c); pat.append(c); i++; } result.append(fCloseBracket); if (includeQuotes) { result.append("'"); // $NON-NLS-1$ } fSupplPatterns.add(pat.toString()); } } return result.toString(); }
/** * an Arduino does not need to know about a shield but a shield must know about a Arduino Arduino * owns the script, but a Shield needs additional support Shields are specific - but plug into a * generalized Arduino Arduino shields can not be plugged into other uCs * * <p>TODO - Program Version & Type injection - with feedback + query to load */ @Override public boolean attach(Arduino inArduino) { if (inArduino == null) { error("can't attach - arduino is invalid"); return false; } this.arduino = inArduino; // arduinoName; FIXME - get clear on diction Program Script or Sketch StringBuffer newProgram = new StringBuffer(); newProgram.append(arduino.getSketch()); // modify the program int insertPoint = newProgram.indexOf(Arduino.VENDOR_DEFINES_BEGIN); if (insertPoint > 0) { newProgram.insert(Arduino.VENDOR_DEFINES_BEGIN.length() + insertPoint, ADAFRUIT_DEFINES); } else { error("could not find insert point in MRLComm.ino"); // get info back to user return false; } insertPoint = newProgram.indexOf(Arduino.VENDOR_SETUP_BEGIN); if (insertPoint > 0) { newProgram.insert(Arduino.VENDOR_SETUP_BEGIN.length() + insertPoint, ADAFRUIT_SETUP); } else { error("could not find insert point in MRLComm.ino"); // get info back to user return false; } insertPoint = newProgram.indexOf(Arduino.VENDOR_CODE_BEGIN); if (insertPoint > 0) { newProgram.insert(Arduino.VENDOR_CODE_BEGIN.length() + insertPoint, ADAFRUIT_CODE); } else { error("could not find insert point in MRLComm.ino"); // get info back to user return false; } // set the program Sketch sketch = new Sketch("AdafruitMotorShield", newProgram.toString()); arduino.setSketch(sketch); // broadcast the arduino state - ArduinoGUI should subscribe to // setProgram broadcastState(); // state has changed let everyone know // servo9.attach(arduinoName, 9); // FIXME ??? - createServo(Integer i) // servo10.attach(arduinoName, 10); // error(String.format("couldn't find %s", arduinoName)); return true; }
/** See ISO 16022:2006, 5.2.3 and Annex C, Table C.2 */ private static int decodeAsciiSegment( BitSource bits, StringBuffer result, StringBuffer resultTrailer) throws FormatException { boolean upperShift = false; do { int oneByte = bits.readBits(8); if (oneByte == 0) { throw FormatException.getFormatInstance(); } else if (oneByte <= 128) { // ASCII data (ASCII value + 1) oneByte = upperShift ? oneByte + 128 : oneByte; upperShift = false; result.append((char) (oneByte - 1)); return ASCII_ENCODE; } else if (oneByte == 129) { // Pad return PAD_ENCODE; } else if (oneByte <= 229) { // 2-digit data 00-99 (Numeric Value + 130) int value = oneByte - 130; if (value < 10) { // padd with '0' for single digit values result.append('0'); } result.append(value); } else if (oneByte == 230) { // Latch to C40 encodation return C40_ENCODE; } else if (oneByte == 231) { // Latch to Base 256 encodation return BASE256_ENCODE; } else if (oneByte == 232 || oneByte == 233 || oneByte == 234) { // FNC1, Structured Append, Reader Programming // Ignore these symbols for now // throw ReaderException.getInstance(); } else if (oneByte == 235) { // Upper Shift (shift to Extended ASCII) upperShift = true; } else if (oneByte == 236) { // 05 Macro result.append("[)>\u001E05\u001D"); resultTrailer.insert(0, "\u001E\u0004"); } else if (oneByte == 237) { // 06 Macro result.append("[)>\u001E06\u001D"); resultTrailer.insert(0, "\u001E\u0004"); } else if (oneByte == 238) { // Latch to ANSI X12 encodation return ANSIX12_ENCODE; } else if (oneByte == 239) { // Latch to Text encodation return TEXT_ENCODE; } else if (oneByte == 240) { // Latch to EDIFACT encodation return EDIFACT_ENCODE; } else if (oneByte == 241) { // ECI Character // TODO(bbrown): I think we need to support ECI // throw ReaderException.getInstance(); // Ignore this symbol for now } else if (oneByte >= 242) { // Not to be used in ASCII encodation // ... but work around encoders that end with 254, latch back to ASCII if (oneByte == 254 && bits.available() == 0) { // Ignore } else { throw FormatException.getFormatInstance(); } } } while (bits.available() > 0); return ASCII_ENCODE; }
public String getColumn(int rowid, String val) { result.setLength(0); result.append(val); while (result.length() < columnSizeArray[rowid]) { result.append(" "); } if (rowid == 1) result.insert(0, "| "); else result.insert(0, " | "); return result.toString(); }
@Override public String call() throws Exception { boolean found = false; StringBuffer sb = new StringBuffer(); for (int i = lines.size() - 1; i >= 0 && !found; i--) { LineWithUsers line = lines.get(i); String text; if (line instanceof LineMessage) text = ((LineMessage) line).text; else if (line instanceof LineAction) text = ((LineAction) line).text; else continue; if (replacement == null) text = Colors.removeFormattingAndColors(text); matcher.reset(text); while (matcher.find() && !(single && found)) { found = true; if (replacement != null) matcher.appendReplacement(sb, replacement); else { String capture = matcher.group(); char[] chars = capture.toCharArray(); StringBuilder sb2 = new StringBuilder(); Stack<Integer> color = new Stack<Integer>(); int last = -1; for (int o = 0; o <= chars.length; o++) { for (int p = 0; p <= matcher.groupCount(); p++) { int s = matcher.start(p) - matcher.start(); int e = matcher.end(p) - matcher.start(); if (o == s) color.push(p); else if (o == e) color.pop(); } if (color.isEmpty() && last != -1) { last = -1; sb2.append(Colors.NORMAL); } else if (!color.isEmpty() && last != color.peek()) { sb2.append(groupColors[color.peek() % groupColors.length]); last = color.peek(); } if (o < chars.length) sb2.append(chars[o]); } matcher.appendReplacement(sb, sb2.toString()); } } if (found) { matcher.appendTail(sb); if (line instanceof LineAction) { sb.insert(0, "ACTION "); sb.insert(0, '\001'); sb.append('\001'); } return StringTools.limitLength(sb); } } return null; }
/** * Get a character string that uniquely identifies this node and that collates nodes into document * order * * @return a string. The string is always interned so keys can be compared using "==". */ public static String getSequentialKey(SiblingCountingNode node) { // TODO: this was designed so it could be used for sorting nodes into document // order, but is not currently used that way. StringBuffer key = new StringBuffer(); while (!(node instanceof DocumentInfo)) { key.insert(0, alphaKey(node.getSiblingPosition())); node = (SiblingCountingNode) node.getParent(); } key.insert(0, "w" + node.getDocumentNumber()); return key.toString().intern(); }
private String generateID() { StringBuffer buf = new StringBuffer(); for (Interpretation ip = this; ip != null; ip = ip.getParent()) { if (!ip.isSectionHead()) continue; if (buf.length() > 0) buf.insert(0, " "); String name = ip.action.getName(); buf.insert(0, name); } return buf.toString(); }
public String getRelativePath() { if (relativePath == null) { StringBuffer sb = new StringBuffer(); for (VirtualFile f = file; f != null && !root.equals(f); f = f.getParent()) { if (sb.length() > 0) sb.insert(0, '/'); sb.insert(0, f.getName()); } relativePath = sb.toString(); } return relativePath; }
public static String convertDN(String globusDN) { if (globusDN == null) return null; StringTokenizer tokens = new StringTokenizer(globusDN, "/"); StringBuffer buf = new StringBuffer(); while (tokens.hasMoreTokens()) { buf.insert(0, tokens.nextToken()); if (tokens.hasMoreTokens()) buf.insert(0, ", "); } return buf.toString(); }
/** Constructs the fully qualified name of this class, including package path. */ public String getFullName() { StringBuffer buf = new StringBuffer(); String packagename = getPackageName(); if (packagename != null) { buf.append(packagename); buf.append('.'); } int pos = buf.length(); for (JavaClass i = this; i != null; i = i.getParent()) { if (i != this) buf.insert(pos, '$'); buf.insert(pos, i.getName()); } return buf.toString(); }
static KeyAndString EncryptSingle(String data) throws Exception { if (!data.contains("*")) throw new Exception("no * mark."); ArrayList<MulDivAdaptTable> keys = new ArrayList<MulDivAdaptTable>(); String[] results = MulDivAdaptMgr.FirstItem(data); keys.add(MulDivAdaptMgr.GetTable(results[0])); StringBuffer newData = new StringBuffer(); newData.append(results[1]); if (Integer.valueOf(results[2]) == results[1].length()) newData.insert(Integer.valueOf(results[2]), keys.get(0).adapted); else newData.insert(Integer.valueOf(results[2]), keys.get(0).adapted + " "); data = newData.toString(); return new KeyAndString(keys.get(0), data); }
/** * Return the full path of the given page; the path is composed by the concatenation of the code * of the page starting from the root to the given page. * * @param page The page whose path must be found. * @param separator The separator of the page codes * @return The full path of the page */ public static StringBuffer getFullPath(IPage page, String separator) { if (page.isRoot()) { return new StringBuffer(page.getCode()); } IPage temp = page; StringBuffer buffer = new StringBuffer(); buffer.insert(0, temp.getCode()); while (!temp.getCode().equals(temp.getParentCode())) { temp = temp.getParent(); if (temp.isShowable()) { buffer.insert(0, temp.getCode() + separator); } } return buffer; }
/* * calculates the path of the node up in the hierarchy, example of result is project/build/plugins/plugin * level parameter designates the number of parents to climb eg. for level 2 the result would be plugins/plugin * level -1 means all the way to the top. */ public static String pathUp(Node node, int level) { StringBuffer buf = new StringBuffer(); int current = level; while (node != null && current > 0) { if (node instanceof Element) { if (buf.length() > 0) { buf.insert(0, "/"); } buf.insert(0, node.getNodeName()); current = current - 1; } node = node.getParentNode(); } return buf.toString(); }