Example usage for java.lang Character isWhitespace

List of usage examples for java.lang Character isWhitespace

Introduction

In this page you can find the example usage for java.lang Character isWhitespace.

Prototype

public static boolean isWhitespace(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is white space according to Java.

Usage

From source file:com.google.dart.tools.ui.internal.text.dart.DartAutoIndentStrategy_NEW.java

/**
 * Returns the indentation of the line <code>line</code> in <code>document</code>. The returned
 * string may contain pairs of leading slashes that are considered part of the indentation. The
 * space before the asterisk in a Dart doc comment is not considered part of the indentation.
 * //from   w ww  .j a  va  2s  .c o m
 * @param document the document
 * @param line the line
 * @return the indentation of <code>line</code> in <code>document</code>
 * @throws BadLocationException if the document is changed concurrently
 */
private static String getCurrentIndent(Document document, int line) throws BadLocationException {
    IRegion region = document.getLineInformation(line);
    int from = region.getOffset();
    int endOffset = region.getOffset() + region.getLength();

    // go behind line comments
    int to = from;
    while (to < endOffset - 2 && document.get(to, 2).equals(LINE_COMMENT)) {
        to += 2;
    }

    while (to < endOffset) {
        char ch = document.getChar(to);
        if (!Character.isWhitespace(ch)) {
            break;
        }
        to++;
    }

    // don't count the space before Dart doc, asterisk-style comment lines
    if (to > from && to < endOffset - 1 && document.get(to - 1, 2).equals(" *")) { //$NON-NLS-1$
        String type = TextUtilities.getContentType(document, DartPartitions.DART_PARTITIONING, to, true);
        if (type.equals(DartPartitions.DART_DOC) || type.equals(DartPartitions.DART_MULTI_LINE_COMMENT)) {
            to--;
        }
    }

    return document.get(from, to - from);
}

From source file:MainClass.java

/**
 * Prints the file/*from   ww w .  j a v a 2 s  .  c  o  m*/
 */
void print() {
    // Start the print job
    if (printer.startJob(fileName)) {
        // Determine print area, with margins
        bounds = computePrintArea(printer);
        xPos = bounds.x;
        yPos = bounds.y;

        // Create the GC
        gc = new GC(printer);

        // Determine line height
        lineHeight = gc.getFontMetrics().getHeight();

        // Determine tab width--use three spaces for tabs
        int tabWidth = gc.stringExtent(" ").x;

        // Print the text
        printer.startPage();
        buf = new StringBuffer();
        char c;
        for (int i = 0, n = contents.length(); i < n; i++) {
            // Get the next character
            c = contents.charAt(i);

            // Check for newline
            if (c == '\n') {
                printBuffer();
                printNewline();
            }
            // Check for tab
            else if (c == '\t') {
                xPos += tabWidth;
            } else {
                buf.append(c);
                // Check for space
                if (Character.isWhitespace(c)) {
                    printBuffer();
                }
            }
        }
        printer.endPage();
        printer.endJob();
        gc.dispose();
    }
}

From source file:de.jcup.egradle.sdk.builder.action.javadoc.RemoveWhitespacesAndStarsFromJavadocAction.java

String removeWhitespacesAndStars(String line) {
    StringBuilder sb = new StringBuilder();

    boolean firstNonWhitespaceWorked = false;
    for (char c : line.toCharArray()) {
        if (!firstNonWhitespaceWorked) {
            if (Character.isWhitespace(c)) {
                continue;
            }//from  w ww.  ja  va  2 s  .  c o m
            firstNonWhitespaceWorked = true;
            if (c == '*') {
                continue;
            }
            /* other first char will be appended */
        }
        sb.append(c);
    }
    String result = sb.toString();
    return result;
}

From source file:com.alibaba.citrus.expr.jexl.JexlExpressionFactory.java

/**
 * ?context??/*w w w.ja va 2 s.  c om*/
 *
 * @return <code>true</code>
 */
protected boolean isValidContextVariableName(String varName) {
    for (int i = 0; i < varName.length(); i++) {
        char ch = varName.charAt(i);

        if (Character.isWhitespace(ch) || ch == '[') {
            return false;
        }
    }

    return true;
}

From source file:com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyForIteratorPadCheck.java

@Override
public void visitToken(DetailAST ast) {
    if (ast.getChildCount() == 0) {
        //empty for iterator. test pad after semi.
        final DetailAST semi = ast.getPreviousSibling();
        final String line = getLines()[semi.getLineNo() - 1];
        final int after = semi.getColumnNo() + 1;
        //don't check if at end of line
        if (after < line.length()) {
            if (option == PadOption.NOSPACE && Character.isWhitespace(line.charAt(after))) {
                log(semi.getLineNo(), after, WS_FOLLOWED, SEMICOLON);
            } else if (option == PadOption.SPACE && !Character.isWhitespace(line.charAt(after))) {
                log(semi.getLineNo(), after, WS_NOT_FOLLOWED, SEMICOLON);
            }/*from w w  w  . j a va  2  s  .  c  o  m*/
        }
    }
}

From source file:DropReceivedLines.java

/** process one file, given an open LineReader */
public void process(BufferedReader is, PrintWriter out) throws IOException {
    try {//  w ww.j a  v  a 2s. c o m
        String lin;

        // If line begins with "Received:", ditch it, and its continuations
        while ((lin = is.readLine()) != null) {
            if (lin.startsWith("Received:")) {
                do {
                    lin = is.readLine();
                } while (lin.length() > 0 && Character.isWhitespace(lin.charAt(0)));
            }
            out.println(lin);
        }
        is.close();
        out.close();
    } catch (IOException e) {
        System.out.println("IOException: " + e);
    }
}

From source file:com.screenslicer.core.scrape.Dissect.java

private static void dedupStrings(String[] strings, boolean fromLeft) {
    for (int i = 0; i < strings.length; i++) {
        if (strings[i] == null || strings[i].trim().isEmpty()) {
            return;
        }/*from  w ww.  ja v  a 2 s . c o  m*/
    }
    int len = 0;
    for (int i = 0; i < strings.length; i++) {
        strings[i] = " " + (fromLeft ? strings[i] : StringUtils.reverse(strings[i])) + " ";
    }
    if (strings != null && strings.length > 0 && strings[0] != null) {
        for (int i = 0; i < strings[0].length(); i++) {
            char c = strings[0].charAt(i);
            boolean match = true;
            for (int j = 1; j < strings.length; j++) {
                if (strings[j] == null || i >= strings[j].length() || strings[j].charAt(i) != c) {
                    match = false;
                    break;
                }
            }
            if (match) {
                ++len;
            } else {
                break;
            }
        }
    }
    for (int i = 0; len > 0 && i < strings.length; i++) {
        if (!Character.isWhitespace(strings[i].charAt(len - 1))) {
            --len;
            i = 0;
        }
    }
    for (int i = 0; len > 0 && i < strings.length; i++) {
        strings[i] = strings[i].substring(len);
    }
    for (int i = 0; i < strings.length; i++) {
        strings[i] = (fromLeft ? strings[i] : StringUtils.reverse(strings[i])).trim();
    }
}

From source file:com.atlassian.jira.license.JiraLicenseStoreImpl.java

private String removeWhitespace(final String licenseString) {
    if (StringUtils.isBlank(licenseString)) {
        return licenseString;
    }//from  w w w . ja  v  a  2s.c o  m
    StringBuilder sb = new StringBuilder();
    for (char ch : licenseString.toCharArray()) {
        if (!Character.isWhitespace(ch)) {
            sb.append(ch);
        }
    }
    return sb.toString();
}

From source file:com.esofthead.mycollab.core.utils.FileUtils.java

public static boolean isValidFileName(String name) {
    if (name.equals(".") || name.equals("..")) //$NON-NLS-1$ //$NON-NLS-2$
        return false;
    //empty names are not valid
    final int length = name.length();
    if (length == 0)
        return false;
    final char lastChar = name.charAt(length - 1);
    // filenames ending in dot are not valid
    if (lastChar == '.')
        return false;
    // file names ending with whitespace are truncated (bug 118997)
    if (Character.isWhitespace(lastChar))
        return false;
    int dot = name.indexOf('.');
    //on windows, filename suffixes are not relevant to name validity
    String basename = dot == -1 ? name : name.substring(0, dot);
    if (Arrays.binarySearch(INVALID_RESOURCE_BASENAMES, basename.toLowerCase()) >= 0)
        return false;
    return Arrays.binarySearch(INVALID_RESOURCE_FULLNAMES, name.toLowerCase()) < 0;
}

From source file:ar.com.zauber.commons.spring.test.impl.TamperdataHttpServletRequestFactory.java

/** hace el trabajo sucio 
 * @throws UnsupportedEncodingException */
private HttpServletRequest parse(final XMLStreamReader reader)
        throws XMLStreamException, UnsupportedEncodingException {
    final MockHttpServletRequest ret = new MockHttpServletRequest();
    ret.setMethod("POST");
    String header = null;//  w  ww .  ja  v  a2 s. c  o  m
    String postHeader = null;
    int event;
    while ((event = reader.next()) != XMLStreamConstants.END_DOCUMENT) {
        if (event == XMLStreamConstants.START_ELEMENT) {
            final String name = reader.getLocalName();
            if (name.equals("tdRequestHeader") || name.equals("tdPostHeader")) {
                header = reader.getAttributeValue(0);
            } else if (name.equals("tdPostElements")) {
                ret.setMethod("POST");
            } else if (name.equals("tdPostElement")) {
                postHeader = reader.getAttributeValue(0);
            }
        } else if (event == XMLStreamConstants.CHARACTERS) {
            String text = reader.getText();
            if (text.length() > 1 && Character.isWhitespace(text.charAt(0))) {
                text = text.substring(1);
            }
            if (text.length() > 1 && Character.isWhitespace(text.charAt(text.length() - 1))) {
                text = text.substring(0, text.length() - 1);
            }

            final String value = URLDecoder.decode(URLDecoder.decode(text, encoding), encoding);
            if (header != null) {
                ret.addHeader(header, value);
            } else if (postHeader != null) {
                ret.addParameter(postHeader, value);
            }
            header = null;
            postHeader = null;
        } else {
            header = null;
            postHeader = null;
        }
    }
    reader.close();
    return ret;
}