List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:Decoder.java
private static String removeWhiteSpaces(String licenseData) { if ((licenseData == null) || (licenseData.length() == 0)) { return licenseData; }/*ww w .j a v a 2 s .co m*/ char[] chars = licenseData.toCharArray(); StringBuffer buf = new StringBuffer(chars.length); for (int i = 0; i < chars.length; i++) { if (!Character.isWhitespace(chars[i])) { buf.append(chars[i]); } } return buf.toString(); }
From source file:com.tasktop.internal.hp.qc.core.model.comments.mylyn3_8.HtmlStreamTokenizer_m3_8.java
/** * Returns the next token from the stream. *///from w w w . ja v a 2 s .com public Token_m3_8 nextToken() throws IOException, ParseException { if (pushbackToken != null) { Token_m3_8 token_m3_8 = pushbackToken; pushbackToken = null; return token_m3_8; } int closingComment = 0; textBuffer.setLength(0); whitespaceBuffer.setLength(0); do { int ch; if (pushbackChar != 0) { ch = pushbackChar; pushbackChar = 0; } else { ch = in.read(); } if (ch < 0) { State oldState = state; state = State.EOF; if (textBuffer.length() > 0 && oldState == State.TEXT) { return new Token_m3_8(textBuffer, whitespaceBuffer, false); } else { return new Token_m3_8(); } } if (state == State.TEXT) { if (ch == '<') { state = State.TAG; if (textBuffer.length() > 0) { return new Token_m3_8(textBuffer, whitespaceBuffer, false); } } else if (Character.isWhitespace((char) ch)) { pushbackChar = ch; state = State.WS; if (textBuffer.length() > 0) { return new Token_m3_8(textBuffer, whitespaceBuffer, false); } } else { textBuffer.append((char) ch); } } else if (state == State.WS) { if (!Character.isWhitespace((char) ch)) { pushbackChar = ch; state = State.TEXT; } else { whitespaceBuffer.append((char) ch); } } else if (state == State.TAG) { if (ch == '>') { state = State.TEXT; HtmlTag_m3_8 tag = new HtmlTag_m3_8(base); parseTag(textBuffer.toString(), tag, escapeTagValues); return new Token_m3_8(tag, whitespaceBuffer); } if (ch == '<' && textBuffer.length() == 0) { textBuffer.append("<<"); //$NON-NLS-1$ state = State.TEXT; } else if (ch == '-' && textBuffer.length() == 2 && textBuffer.charAt(1) == '-' && textBuffer.charAt(0) == '!') { textBuffer.setLength(0); state = State.COMMENT; } else if (ch == '\'' || ch == '"') { quoteChar = ch; textBuffer.append((char) ch); state = State.TAG_QUOTE; } else { textBuffer.append((char) ch); } } else if (state == State.TAG_QUOTE) { if (ch == '>') { pushbackChar = ch; state = State.TAG; } else { textBuffer.append((char) ch); if (ch == quoteChar) { state = State.TAG; } } } else if (state == State.COMMENT) { if (ch == '>' && closingComment >= 2) { textBuffer.setLength(textBuffer.length() - 2); closingComment = 0; state = State.TEXT; return new Token_m3_8(textBuffer, whitespaceBuffer, true); } if (ch == '-') { closingComment++; } else { closingComment = 0; } textBuffer.append((char) ch); } } while (true); }
From source file:Main.java
/** * Trim leading whitespace from the given String. * @param str the String to check/*from www .ja v a 2 s. c om*/ * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimLeadingWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuilder sb = new StringBuilder(str); while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) { sb.deleteCharAt(0); } return sb.toString(); }
From source file:com.subgraph.vega.internal.http.requests.EngineHttpResponse.java
@Override public boolean isMostlyAscii() { if (isMostlyAsciiTestDone) { return isMostlyAscii; }//from w w w .j ava 2s. c o m final String body = getBodyAsString(); if (body == null || body.isEmpty()) { isMostlyAscii = true; isMostlyAsciiTestDone = true; return true; } int total = (body.length() > 200) ? (200) : (body.length()); int printable = 0; for (int i = 0; i < total; i++) { char c = body.charAt(i); if ((c >= 0x20 && c <= 0x7F) || Character.isWhitespace(c)) printable += 1; } isMostlyAscii = ((printable * 100) / total) > 90; isMostlyAsciiTestDone = true; return isMostlyAscii; }
From source file:de.codesourcery.jasm16.emulator.Breakpoint.java
private long calculateConditionValue(IEmulator emulator) throws ParseException { final StringBuilder trimmed = new StringBuilder(); for (char c : condition.toCharArray()) { if (!Character.isWhitespace(c)) { trimmed.append(c);// ww w. j ava 2 s .c o m } } final String expanded = substitutePlaceholders(emulator, trimmed.toString()); final TermNode expression = parseCondition(expanded); final Long value = expression.calculate(new SymbolTable("calculateConditionValue(IEmulator)")); if (value == null) { throw new ParseException("Failed to evaluate condition '" + expanded + "'", 0, expanded.length()); } return value.longValue(); }
From source file:jcurl.core.io.OldConfigReader.java
/** * Read a single token./*ww w. java 2s .co m*/ * * @param read * @return - * @throws IOException */ static String readToken(final Reader read) throws IOException { final StringBuffer ret = new StringBuffer(); final int pre = 1; final int content = 2; final int comment = 3; char sep = '-'; int state = pre; for (;;) { int ch = read.read(); switch (state) { case pre: if (ch == -1) { log.debug("token=[null]"); return null; } if (Character.isWhitespace((char) ch)) continue; if ('#' == (char) ch) state = comment; else { ret.setLength(0); if ('"' == (char) ch) sep = '"'; else { sep = ' '; ret.append((char) ch); } state = content; } break; case content: final String s0 = ret.toString().trim(); if (ch == -1) { log.debug("token=[" + s0 + "]"); return s0; } if (sep == ' ' && Character.isWhitespace((char) ch)) { log.debug("token=[" + s0 + "]"); return s0; } if (sep == '"' && '"' == (char) ch) { log.debug("token=[" + s0 + "]"); return s0; } if (sep == ' ' && '#' == (char) ch) state = comment; else ret.append((char) ch); break; case comment: final String s = ret.toString().trim(); if (ch == -1) { log.debug("token=[" + s + "]"); return s; } if ('\n' == (char) ch || '\r' == (char) ch) { if (s.length() == 0) state = pre; else { log.debug("token=[" + s + "]"); return s; } } break; } } }
From source file:cc.kune.core.server.utils.XmlW.java
/** * Gets the index opening tag./*from ww w . ja v a2 s .com*/ * * @param tag * the tag * @param text * the text * @param start * the start * @return the index opening tag */ static private int getIndexOpeningTag(final String tag, final String text, final int start) { // consider whitespace? final int idx = text.indexOf("<" + tag, start); if (idx == -1) { return -1; } final char next = text.charAt(idx + 1 + tag.length()); if ((next == '>') || Character.isWhitespace(next)) { return idx; } else { return getIndexOpeningTag(tag, text, idx + 1); } }
From source file:dsd.controller.ParserControler.java
private static boolean ParseSonarData(File file, List<RawData> rawDataList) { BufferedReader br = null;//from ww w.j a v a2 s . c o m int lineCounter = 0; try { br = new BufferedReader(new FileReader(file.getPath())); RawData data = new RawData(); String line = null; boolean timestampIsLastReadLine = true; while ((line = br.readLine()) != null) { lineCounter++; if (line.length() == 0) continue; boolean lineStartsWithWhitespace = Character.isWhitespace(line.charAt(0)); if (lineStartsWithWhitespace) { data.setTimestamp( TimeCalculations.LabViewTimestampGregToMiliSeconds(Long.parseLong(line.trim()))); if (!(rawDataList.size() > 0 && rawDataList.get(rawDataList.size() - 1).getTimestamp() == data.getTimestamp())) rawDataList.add(data); else System.out.println(String.format( "Touple on line: %s skipped because of same timestamp as the previous touple\n", lineCounter)); timestampIsLastReadLine = true; data = new RawData(); } if (!lineStartsWithWhitespace && timestampIsLastReadLine) { String[] lineData = StringUtils.split(line, '\t'); if (lineData.length > 1) { if (lineData[0].trim().startsWith("R")) { if (lineData[0].trim().endsWith("E")) { if (lineData[0].contains("99.99")) { data.setSonar(99.99f); data.setSonarType(eSonarType.SonarOutOfWaterData); } else { data.setSonar((float) InputConversion.sonarConversion(Double.parseDouble( lineData[0].trim().substring(1, lineData[0].trim().length() - 1)))); data.setSonarType(eSonarType.UncertainData); } } else { data.setSonar((float) InputConversion.sonarConversion(Double.parseDouble( lineData[0].trim().substring(1, lineData[0].trim().length())))); data.setSonarType(eSonarType.CorrectData); } } else { if (lineData[0].trim().length() == 0 || lineData[0].trim().equals("E1")) { data.setSonar(0.0f); data.setSonarType(eSonarType.ErrorData); } else { data.setSonar(0.0f); data.setSonarType(eSonarType.WrongData); } } data.setTimestamp(TimeCalculations .LabViewTimestampGregToMiliSeconds(Long.parseLong(lineData[1].trim()))); timestampIsLastReadLine = true; rawDataList.add(data); data = new RawData(); } else { if (line.trim().startsWith("R")) { if (line.trim().endsWith("E")) { if (line.contains("99.99")) { data.setSonar(99.99f); data.setSonarType(eSonarType.SonarOutOfWaterData); } else { data.setSonar((float) InputConversion.sonarConversion(Double .parseDouble(line.trim().substring(1, line.trim().length() - 1)))); data.setSonarType(eSonarType.UncertainData); } } else { data.setSonar((float) InputConversion.sonarConversion( Double.parseDouble(line.trim().substring(1, line.trim().length())))); data.setSonarType(eSonarType.CorrectData); } } else { if (line.trim().length() == 0 || line.trim().equals("E1")) { data.setSonar(0.0f); data.setSonarType(eSonarType.ErrorData); } else { data.setSonar(0.0f); data.setSonarType(eSonarType.WrongData); } } timestampIsLastReadLine = false; } } else if (lineStartsWithWhitespace) { data.setSonar(0.0f); data.setSonarType(eSonarType.ErrorData); } else if (!lineStartsWithWhitespace || timestampIsLastReadLine) { System.out.println("Unexpected behaviour on line:"); } } return true; } catch (Exception e) { System.out.println(String.format("Error on line: %s\n", lineCounter)); e.printStackTrace(); } finally { try { if (br != null) br.close(); } catch (IOException ex) { ex.printStackTrace(); } } return false; }
From source file:au.org.ala.delta.directives.args.DirectiveArgsParser.java
protected List<Integer> readSet(IntegerValidator validator) throws ParseException { List<Integer> values = new ArrayList<Integer>(); while (_currentInt > 0 && !Character.isWhitespace(_currentChar)) { values.addAll(readSetComponent(validator)); }//from w w w . j ava 2 s .c o m return values; }
From source file:ca.simplegames.micro.utils.StringUtils.java
/** * Trim leading and trailing whitespace from the given String. * * @param str the String to check// w w w. ja v a 2 s. co m * @return the trimmed String * @see java.lang.Character#isWhitespace */ public static String trimWhitespace(String str) { if (!hasLength(str)) { return str; } StringBuffer buf = new StringBuffer(str); while (buf.length() > 0 && Character.isWhitespace(buf.charAt(0))) { buf.deleteCharAt(0); } while (buf.length() > 0 && Character.isWhitespace(buf.charAt(buf.length() - 1))) { buf.deleteCharAt(buf.length() - 1); } return buf.toString(); }