/** * Abbreviate name. * @param buf buffer to append abbreviation. * @param nameStart start of name to abbreviate. */ public void abbreviate(final int nameStart, final StringBuffer buf) { int i = count; for(int pos = buf.indexOf(".", nameStart); pos != -1; pos = buf.indexOf(".", pos + 1)) { if(--i == 0) { buf.delete(nameStart, pos + 1); break; } } } }
/** * Returns true if this CDATA section contains the illegal character * sequence "]]>". Such nodes must be {@link #split} before they are * serialized. */ public boolean needsSplitting() { return buffer.indexOf("]]>") != -1; }
/** * Returns true if this comment contains the illegal character sequence * "--". Such nodes may not be serialized. */ public boolean containsDashDash() { return buffer.indexOf("--") != -1; } }
/** * filter out the first comment line * @param stringBuffer the string buffer * @return true if filtered successfully, false otherwise */ static boolean filterPropertiesComment(StringBuffer stringBuffer) { //check whether has comment in the first line if (stringBuffer.charAt(0) != '#') { return false; } int commentLineIndex = stringBuffer.indexOf("\n"); if (commentLineIndex == -1) { return false; } stringBuffer.delete(0, commentLineIndex + 1); return true; } }
private int replaceHolder( StringBuffer dateBuffer, Boolean inPattern ) { String placeHolder = inPattern ? ESCAPED_NANOSECOND_PLACEHOLDER : NANOSECOND_PLACEHOLDER; int placeholderPosition = dateBuffer.indexOf( placeHolder ); if ( placeholderPosition == -1 ) { return 0; } dateBuffer.delete( placeholderPosition, placeholderPosition + placeHolder.length() ); return placeholderPosition; }
/** * Unicode编码转汉字 */ public static String UnicodeToChs(String s) { StringBuffer sb = new StringBuffer(s); int pos; while ((pos = sb.indexOf("\\u")) > -1) { String tmp = sb.substring(pos, pos + 6); sb.replace(pos, pos + 6, Character.toString((char) Integer.parseInt(tmp.substring(2), 16))); } s = sb.toString(); return s; } }
/** * Detects if session ID exist in the URL. It works more reliable * than <code>servletRequest.isRequestedSessionIdFromURL()</code>. */ protected boolean isRequestedSessionIdFromURL(final HttpServletRequest servletRequest) { if (servletRequest.isRequestedSessionIdFromURL()) { return true; } HttpSession session = servletRequest.getSession(false); if (session != null) { String sessionId = session.getId(); StringBuffer requestUri = servletRequest.getRequestURL(); return requestUri.indexOf(sessionId) != -1; } return false; }
/** * Performs the replace operation. * @return The position of the last character that was inserted as * replacement. */ private int replace() { String t = getToken(); int found = inputBuffer.indexOf(t); int pos = -1; final int tokenLength = t.length(); final int replaceValueLength = replaceValue.length(); while (found >= 0) { inputBuffer.replace(found, found + tokenLength, replaceValue); pos = found + replaceValueLength; found = inputBuffer.indexOf(t, pos); ++replaceCount; } return pos; } }
if (xmlProlog.substring(0, 5).equals("<?xml")) { final int xmlPrologEnd = xmlProlog.indexOf("?>"); if (xmlPrologEnd > 0) {
public String getNextWord() { Random rnd = new Random(); StringBuffer sb = new StringBuffer(); StringBuffer chars = new StringBuffer(characters); int l = minLength + (maxLength > minLength ? rnd.nextInt(maxLength - minLength) : 0); for (int i = 0; i < l; i++) { int j = rnd.nextInt(chars.length()); char c = chars.charAt(j); if (wideCharacters.indexOf(c) != -1) { for (int k = 0; k < wideCharacters.length(); k++) { int idx = chars.indexOf(String.valueOf(wideCharacters.charAt(k))); if (idx != -1) { chars.deleteCharAt(idx); } } } sb.append(c); } return sb.toString(); }
String tagOpen = "<elevation>"; String tagClose = "</elevation>"; if (respStr.indexOf(tagOpen) != -1) { int start = respStr.indexOf(tagOpen) + tagOpen.length(); int end = respStr.indexOf(tagClose); String value = respStr.substring(start, end); result = (double)(Double.parseDouble(value)*3.2808399); // convert from meters to feet
private void writeFractional(StringBuffer result, StringBuffer output) { int digit; int strip; if (fractionalSpecials.size() > 0) { String decimalSeparator = Character.toString(getDecimalFormatSymbols().getDecimalSeparator()); digit = result.indexOf(decimalSeparator) + 1; if (exponent != null) { strip = result.indexOf("e") - 1; } else { strip = result.length() - 1; } while (strip > digit && result.charAt(strip) == '0') { strip--; } for (Special s : fractionalSpecials) { char resultCh = result.charAt(digit); if (resultCh != '0' || s.ch == '0' || digit < strip) { output.setCharAt(s.pos, resultCh); } else if (s.ch == '?') { // This is when we're in trailing zeros, and the format is '?'. // We still strip out remaining '#'s later output.setCharAt(s.pos, ' '); } digit++; } } }
/** * Outputs to the final destination as many full line pairs as * there are in the pending output, removing those lines from * their respective buffers. This method terminates when at * least one of the two column buffers is empty. */ private void outputFullLines() throws IOException { for (;;) { int leftLen = leftBuf.indexOf("\n"); if (leftLen < 0) { return; } int rightLen = rightBuf.indexOf("\n"); if (rightLen < 0) { return; } if (leftLen != 0) { out.write(leftBuf.substring(0, leftLen)); } if (rightLen != 0) { writeSpaces(out, leftWidth - leftLen); out.write(rightBuf.substring(0, rightLen)); } out.write('\n'); leftBuf.delete(0, leftLen + 1); rightBuf.delete(0, rightLen + 1); } }
private String extractSessionId() { final int prefix = getRequestURL().indexOf(URL_SESSION_IDENTIFIER); if (prefix != -1) { final int start = prefix + URL_SESSION_IDENTIFIER.length(); int suffix = getRequestURL().indexOf("?", start); if (suffix < 0) { suffix = getRequestURL().indexOf("#", start); } if (suffix <= prefix) { return getRequestURL().substring(start); } return getRequestURL().substring(start, suffix); } return null; } }
if (buf.indexOf("where") == -1) { operand = " where ";
int xmlPrologEnd = xmlProlog.indexOf( "?>" ); if ( xmlPrologEnd > 0 )
int pos = 0; while (pos<qB.length()) { pos = qB.indexOf(prefix,pos); if (pos<0) break;