/** * 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; } }
public static void print(int number, List<Integer> primeFactors) { StringBuffer sb = new StringBuffer(number + "="); for (int factor : primeFactors) { sb.append(factor).append('*'); } if (sb.charAt(sb.length() - 1) == '*') { sb.deleteCharAt(sb.length() - 1); } System.out.println(sb); }
private boolean isPreviousChar(StringBuffer string, int index, char c) { boolean matches = false; if( index > 0 && index < string.length() ) { matches = string.charAt(index - 1) == c; } return matches; }
private boolean isNextChar(StringBuffer string, int index, char c) { boolean matches = false; if( index >= 0 && index < string.length() - 1 ) { matches = string.charAt(index + 1) == c; } return matches; }
/** * Removes a backslash from every pair of backslashes. */ private static String unescape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length() - 1; i++) { char c1 = buf.charAt(i); char c2 = buf.charAt(i + 1); if (c1 == '\\' && c2 == '\\') { buf.deleteCharAt(i); } } return buf.toString(); }
/** * Removes a backslash from every pair of backslashes. */ private static String unescape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length() - 1; i++) { char c1 = buf.charAt(i); char c2 = buf.charAt(i + 1); if (c1 == '\\' && c2 == '\\') { buf.deleteCharAt(i); } } return buf.toString(); }
/** * Inserts a backslash before every comma and backslash. */ private static String escape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length(); i++) { char c = buf.charAt(i); if (c == ',' || c == '\\') { buf.insert(i, '\\'); i++; } } return buf.toString(); }
/** * <p>Remove the last field separator from the buffer.</p> * * @param buffer the <code>StringBuffer</code> to populate * @since 2.0 */ protected void removeLastFieldSeparator(final StringBuffer buffer) { final int len = buffer.length(); final int sepLen = fieldSeparator.length(); if (len > 0 && sepLen > 0 && len >= sepLen) { boolean match = true; for (int i = 0; i < sepLen; i++) { if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) { match = false; break; } } if (match) { buffer.setLength(len - sepLen); } } }
public String stripCR( StringBuffer sbsql ) { // DB2 Can't handle \n in SQL Statements... if ( !supportsNewLinesInSQL() ) { // Remove CR's for ( int i = sbsql.length() - 1; i >= 0; i-- ) { if ( sbsql.charAt( i ) == '\n' || sbsql.charAt( i ) == '\r' ) { sbsql.setCharAt( i, ' ' ); } } } return sbsql.toString(); }
/** * <p>Remove the last field separator from the buffer.</p> * * @param buffer the <code>StringBuffer</code> to populate * @since 2.0 */ protected void removeLastFieldSeparator(StringBuffer buffer) { int len = buffer.length(); int sepLen = fieldSeparator.length(); if (len > 0 && sepLen > 0 && len >= sepLen) { boolean match = true; for (int i = 0; i < sepLen; i++) { if (buffer.charAt(len - 1 - i) != fieldSeparator.charAt(sepLen - 1 - i)) { match = false; break; } } if (match) { buffer.setLength(len - sepLen); } } }
/** * Inserts a backslash before every comma and backslash. */ private static String escape(String s) { StringBuffer buf = new StringBuffer(s); for (int i = 0; i < buf.length(); i++) { char c = buf.charAt(i); if (c == ',' || c == '\\') { buf.insert(i, '\\'); i++; } } return buf.toString(); }
/** * Gets HEADER portion of packet. * @param timeStamp number of milliseconds after the standard base time. * @return HEADER portion of packet, will be zero-length string if header is false. * @since 1.2.15 */ private String getPacketHeader(final long timeStamp) { if (header) { StringBuffer buf = new StringBuffer(dateFormat.format(new Date(timeStamp))); // RFC 3164 says leading space, not leading zero on days 1-9 if (buf.charAt(4) == '0') { buf.setCharAt(4, ' '); } buf.append(getLocalHostname()); buf.append(' '); return buf.toString(); } return ""; }
/** Tests if this string ends with a character. @param ch the character to test for @return true if and only if this string ends with ch */ boolean endsWith(char ch) { assert checkInvariants(); int len = string.length(); return (0 != len) && (string.charAt(len - 1) == ch); }
public static String getPrintableText(List<Candidate> candidates) { StringBuffer sb = new StringBuffer(); sb.append("["); for (Candidate candidate : candidates) { IRealization r = candidate.realization; sb.append(r.getCanonicalName()); sb.append(","); } if (sb.charAt(sb.length() - 1) != '[') sb.deleteCharAt(sb.length() - 1); sb.append("]"); return sb.toString(); }
private boolean prog_magic_wrong() { if ((reg_match == null ? reg_mmatch.regprog.program : reg_match.regprog.program).charAt(0) != REGMAGIC) { VimPlugin.showMessage(MessageHelper.message(Msg.e_re_corr)); return true; } return false; }
public char get(int x, int y){ if(x > getWidth() - 1 || y > getHeight() - 1 || x < 0 || y < 0) return 0; return rows.get(y).charAt(x); }
public char get(Cell cell){ if(cell.x > getWidth() - 1 || cell.y > getHeight() - 1 || cell.x < 0 || cell.y < 0) return 0; return rows.get(cell.y).charAt(cell.x); }
private static boolean shouldAppendSpace(StringBuffer text, char firstCharToAppend) { final boolean result; if (text.length() == 0) { result = false; } else { final char last = text.charAt(text.length() - 1); result = (last == ':' || firstCharToAppend == '@' || Character.isAlphabetic(last) || Character.isAlphabetic(firstCharToAppend)) && !Character.isWhitespace(last); } return result; }