List of usage examples for java.lang Character isWhitespace
public static boolean isWhitespace(int codePoint)
From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.java
/** * Process a token representing a right parentheses. * @param ast the token representing a right parentheses *//*ww w . ja v a2s. co m*/ protected void processRight(DetailAST ast) { final String line = getLines()[ast.getLineNo() - 1]; final int before = ast.getColumnNo() - 1; if (before >= 0) { if (option == PadOption.NOSPACE && Character.isWhitespace(line.charAt(before)) && !CommonUtils.hasWhitespaceBefore(before, line)) { log(ast.getLineNo(), before, WS_PRECEDED, CLOSE_PARENTHESIS); } else if (option == PadOption.SPACE && !Character.isWhitespace(line.charAt(before)) && line.charAt(before) != OPEN_PARENTHESIS) { log(ast.getLineNo(), ast.getColumnNo(), WS_NOT_PRECEDED, CLOSE_PARENTHESIS); } } }
From source file:net.sf.jabref.logic.layout.format.RTFChars.java
@Override public String format(String field) { StringBuilder sb = new StringBuilder(""); StringBuilder currentCommand = null; boolean escaped = false; boolean incommand = false; for (int i = 0; i < field.length(); i++) { char c = field.charAt(i); if (escaped && (c == '\\')) { sb.append('\\'); escaped = false;/*from w w w . j a v a2 s . c om*/ } else if (c == '\\') { escaped = true; incommand = true; currentCommand = new StringBuilder(); } else if (!incommand && ((c == '{') || (c == '}'))) { // Swallow the brace. } else if (Character.isLetter(c) || Globals.SPECIAL_COMMAND_CHARS.contains(String.valueOf(c))) { escaped = false; if (incommand) { // Else we are in a command, and should not keep the letter. currentCommand.append(c); testCharCom: if ((currentCommand.length() == 1) && Globals.SPECIAL_COMMAND_CHARS.contains(currentCommand.toString())) { // This indicates that we are in a command of the type // \^o or \~{n} if (i >= (field.length() - 1)) { break testCharCom; } String command = currentCommand.toString(); i++; c = field.charAt(i); String combody; if (c == '{') { StringInt part = getPart(field, i, true); i += part.i; combody = part.s; } else { combody = field.substring(i, i + 1); } String result = RTF_CHARS.get(command + combody); if (result != null) { sb.append(result); } incommand = false; escaped = false; } } else { sb.append(c); } } else { testContent: if (!incommand || (!Character.isWhitespace(c) && (c != '{') && (c != '}'))) { sb.append(c); } else { assert incommand; // First test for braces that may be part of a LaTeX command: if ((c == '{') && (currentCommand.length() == 0)) { // We have seen something like \{, which is probably the start // of a command like \{aa}. Swallow the brace. continue; } else if ((c == '}') && (currentCommand.length() > 0)) { // Seems to be the end of a command like \{aa}. Look it up: String command = currentCommand.toString(); String result = RTF_CHARS.get(command); if (result != null) { sb.append(result); } incommand = false; escaped = false; continue; } // Then look for italics etc., // but first check if we are already at the end of the string. if (i >= field.length() - 1) { break testContent; } if (((c == '{') || (c == ' ')) && (currentCommand.length() > 0)) { String command = currentCommand.toString(); // Then test if we are dealing with a italics or bold // command. If so, handle. if ("em".equals(command) || "emph".equals(command) || "textit".equals(command) || "it".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\i ").append(part.s).append('}'); } else if ("textbf".equals(command) || "bf".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\b ").append(part.s).append('}'); } else { LOGGER.info("Unknown command " + command); } if (c == ' ') { // command was separated with the content by ' ' // We have to add the space a } } else { sb.append(c); } } incommand = false; escaped = false; } } char[] chars = sb.toString().toCharArray(); sb = new StringBuilder(); for (char c : chars) { if (c < 128) { sb.append(c); } else { sb.append("\\u").append((long) c).append('?'); } } return sb.toString().replace("---", "{\\emdash}").replace("--", "{\\endash}").replace("``", "{\\ldblquote}") .replace("''", "{\\rdblquote}"); }
From source file:DefinitionObject.java
public boolean hasSpace(String word) { for (int i = 0; i < word.length(); i++) { if (Character.isWhitespace(word.charAt(i))) return true; }// www . j a va 2 s.c o m return false; }
From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.java
@Override public void visitToken(DetailAST ast) { final DetailAST astNode = getPreceded(ast); final String line = getLine(ast.getLineNo() - 1); final int after = getPositionAfter(astNode); if ((after >= line.length() || Character.isWhitespace(line.charAt(after))) && hasRedundantWhitespace(line, after)) { log(astNode.getLineNo(), after, MSG_KEY, astNode.getText()); }// w w w . ja v a 2 s. c om }
From source file:eu.project.ttc.resources.CharacterFootprintTermFilter.java
@Override public void load(DataResource aData) throws ResourceInitializationException { LOGGER.debug("Loading resource character footprint resource at: " + aData.getUri()); InputStream inputStream = null; try {/*www .j a v a 2 s .c o m*/ inputStream = aData.getInputStream(); List<Character> chars = new LinkedList<Character>(); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); int c; while ((c = br.read()) != -1) { if (!Character.isWhitespace((char) c)) chars.add((char) c); } this.allowedChars = new char[chars.size()]; for (int i = 0; i < chars.size(); i++) this.allowedChars[i] = chars.get(i); br.close(); } catch (IOException e) { LOGGER.error("Could not load resource character footprint resource due to an exception."); LOGGER.warn("Continuing with the TrueFilter (always accept terms)"); this.allowedChars = null; } catch (Exception e) { LOGGER.warn("PB loading " + aData.getUri() + ". Continuing with the TrueFilter (always accept terms)"); this.allowedChars = null; return; } finally { if (inputStream != null) try { inputStream.close(); } catch (IOException e) { LOGGER.error("Could not close input stream."); } } }
From source file:net.sf.jabref.exporter.layout.format.RTFChars.java
@Override public String format(String field) { StringBuffer sb = new StringBuffer(""); StringBuffer currentCommand = null; boolean escaped = false; boolean incommand = false; for (int i = 0; i < field.length(); i++) { char c = field.charAt(i); if (escaped && (c == '\\')) { sb.append('\\'); escaped = false;//from ww w . j av a2 s. c o m } else if (c == '\\') { escaped = true; incommand = true; currentCommand = new StringBuffer(); } else if (!incommand && ((c == '{') || (c == '}'))) { // Swallow the brace. } else if (Character.isLetter(c) || Globals.SPECIAL_COMMAND_CHARS.contains(String.valueOf(c))) { escaped = false; if (incommand) { // Else we are in a command, and should not keep the letter. currentCommand.append(c); testCharCom: if ((currentCommand.length() == 1) && Globals.SPECIAL_COMMAND_CHARS.contains(currentCommand.toString())) { // This indicates that we are in a command of the type // \^o or \~{n} if (i >= (field.length() - 1)) { break testCharCom; } String command = currentCommand.toString(); i++; c = field.charAt(i); String combody; if (c == '{') { StringInt part = getPart(field, i, true); i += part.i; combody = part.s; } else { combody = field.substring(i, i + 1); } String result = RTF_CHARS.get(command + combody); if (result != null) { sb.append(result); } incommand = false; escaped = false; } } else { sb.append(c); } } else { // if (!incommand || ((c!='{') && !Character.isWhitespace(c))) testContent: if (!incommand || (!Character.isWhitespace(c) && (c != '{') && (c != '}'))) { sb.append(c); } else { assert incommand; // First test for braces that may be part of a LaTeX command: if ((c == '{') && (currentCommand.length() == 0)) { // We have seen something like \{, which is probably the start // of a command like \{aa}. Swallow the brace. continue; } else if ((c == '}') && (currentCommand.length() > 0)) { // Seems to be the end of a command like \{aa}. Look it up: String command = currentCommand.toString(); String result = RTF_CHARS.get(command); if (result != null) { sb.append(result); } incommand = false; escaped = false; continue; } // Then look for italics etc., // but first check if we are already at the end of the string. if (i >= (field.length() - 1)) { break testContent; } if (((c == '{') || (c == ' ')) && (currentCommand.length() > 0)) { String command = currentCommand.toString(); // Then test if we are dealing with a italics or bold // command. If so, handle. if ("em".equals(command) || "emph".equals(command) || "textit".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\i ").append(part.s).append('}'); } else if ("textbf".equals(command)) { StringInt part = getPart(field, i, c == '{'); i += part.i; sb.append("{\\b ").append(part.s).append('}'); } else { LOGGER.info("Unknown command " + command); } if (c == ' ') { // command was separated with the content by ' ' // We have to add the space a } } else { sb.append(c); } } incommand = false; escaped = false; } } char[] chars = sb.toString().toCharArray(); sb = new StringBuffer(); for (char c : chars) { if (c < 128) { sb.append(c); } else { sb.append("\\u").append((long) c).append('?'); } } return sb.toString().replaceAll("---", "{\\\\emdash}").replaceAll("--", "{\\\\endash}") .replaceAll("``", "{\\\\ldblquote}").replaceAll("''", "{\\\\rdblquote}"); }
From source file:importer.filters.Filter.java
/** * Get the first word of a line//from w w w.j av a2 s . c o m * @param line the line in question * @return */ protected String getFirstWord(String line) { int i; int len = line.length(); for (i = 0; i < line.length(); i++) { if (!Character.isWhitespace(line.charAt(i))) break; } int j = i; for (; i < len; i++) { if (!Character.isLetter(line.charAt(i)) || line.charAt(i) == '-') break; } return line.substring(j, i); }
From source file:com.maddyhome.idea.vim.helper.StringHelper.java
/** * Set the text of an XML element, safely encode it if needed. */// w w w. j av a 2s . co m @NotNull public static Element setSafeXmlText(@NotNull Element element, @NotNull String text) { final Character first = firstCharacter(text); final Character last = lastCharacter(text); if (!StringHelper.isXmlCharacterData(text) || first != null && Character.isWhitespace(first) || last != null && Character.isWhitespace(last)) { element.setAttribute("encoding", "base64"); final String encoded = new String(Base64.encodeBase64(text.getBytes())); element.setText(encoded); } else { element.setText(text); } return element; }
From source file:com.runstate.util.XmlW.java
static private int getIndexOpeningTag(String tag, String text, int start) { // consider whitespace? int idx = text.indexOf("<" + tag, start); if (idx == -1) { return -1; }/*from www.j a v a2s . c o m*/ 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:com.evolveum.midpoint.cli.common.ToolsUtils.java
private static String makeSafelyPrintable(String text, int maxSize) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (!XMLChar.isValid(c)) { sb.append('.'); } else if (Character.isWhitespace(c)) { sb.append(' '); } else {/*from ww w.j a v a 2s .c o m*/ sb.append(c); } if (i == maxSize) { sb.append("..."); break; } } return sb.toString(); }