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.puppycrawl.tools.checkstyle.checks.javadoc.JavadocStyleCheck.java

/**
 * Trims any trailing whitespace or the end of Javadoc comment string.
 * @param builder the StringBuilder to trim.
 *///from  w  ww . j  av a 2 s  . co m
private static void trimTail(StringBuilder builder) {
    int index = builder.length() - 1;
    while (true) {
        if (Character.isWhitespace(builder.charAt(index))) {
            builder.deleteCharAt(index);
        } else if (builder.charAt(index) == '/' && builder.charAt(index - 1) == '*') {
            builder.deleteCharAt(index);
            builder.deleteCharAt(index - 1);
            index--;
            while (builder.charAt(index - 1) == '*') {
                builder.deleteCharAt(index - 1);
                index--;
            }
        } else {
            break;
        }
        index--;
    }
}

From source file:de.codesourcery.geoip.trace.TracePath.java

private static String squashWhitespace(String input) {

    StringBuilder out = new StringBuilder();
    boolean previousCharWasWhitespace = false;
    for (int i = 0; i < input.length(); i++) {
        char c = input.charAt(i);
        if (!Character.isWhitespace(c)) {
            out.append(c);// www.j a  v a 2s . c  om
            previousCharWasWhitespace = false;
        } else {
            if (!previousCharWasWhitespace) {
                out.append(c);
                previousCharWasWhitespace = true;
            }
        }
    }
    return out.toString();
}

From source file:com.igormaznitsa.jcp.directives.AbstractDirectiveHandlerAcceptanceTest.java

private void println(final String str, final boolean showWhitespaces) {
    for (final char chr : str.toCharArray()) {
        if (Character.isWhitespace(chr)) {
            System.out.print(showWhitespaces ? '.' : chr);
        } else {//from  w w  w  . ja va2s  .  c  om
            System.out.print(chr);
        }
    }
    System.out.println();
}

From source file:com.textocat.textokit.morph.ruscorpora.RusCorporaXmlContentHandler.java

private void ensureTrailingWhitespace() {
    if (textBuilder.length() > 0) {
        char lastChar = textBuilder.charAt(textBuilder.length() - 1);
        if (!Character.isWhitespace(lastChar)) {
            textBuilder.append(' ');
        }//  w  w w .j  a  v a  2  s  .c  o m
    }
}

From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.AttachmentUtils.java

public static boolean prepareMessagePart(WsdlAttachmentContainer container, MimeMultipart mp,
        MessageXmlPart messagePart, StringToStringMap contentIds) throws Exception, MessagingException {
    boolean isXop = false;

    XmlObjectTreeModel treeModel = null;
    XmlCursor cursor = messagePart.newCursor();
    XmlObject rootXmlObject = cursor.getObject();

    try {/*from  ww w.ja v a2 s.c o  m*/
        while (!cursor.isEnddoc()) {
            if (cursor.isContainer()) {
                // could be an attachment part (as of "old" SwA specs which
                // specify a content
                // element referring to the attachment)
                if (messagePart.isAttachmentPart()) {
                    String href = cursor.getAttributeText(XOP_HREF_QNAME);
                    if (href != null && href.length() > 0) {
                        contentIds.put(messagePart.getPart().getName(), href);
                    }

                    break;
                }

                XmlObject xmlObj = cursor.getObject();
                SchemaType schemaType = xmlObj.schemaType();
                if (schemaType.isNoType()) {
                    if (treeModel == null) {
                        treeModel = new XmlObjectTreeModel(messagePart.getSchemaType().getTypeSystem(),
                                rootXmlObject);
                    }

                    XmlTreeNode tn = treeModel.getXmlTreeNode(xmlObj);
                    if (tn != null)
                        schemaType = tn.getSchemaType();
                }

                if (AttachmentUtils.isSwaRefType(schemaType)) {
                    String textContent = XmlUtils.getNodeValue(cursor.getDomNode());
                    if (StringUtils.hasContent(textContent) && textContent.startsWith("cid:")) {
                        textContent = textContent.substring(4);

                        try {
                            // is the textcontent already a URI?
                            new URI(textContent);
                            contentIds.put(textContent, textContent);
                        } catch (RuntimeException e) {
                            // not a URI.. try to create one..
                            String contentId = textContent + "@soapui.org";
                            cursor.setTextValue("cid:" + contentId);
                            contentIds.put(textContent, contentId);
                        }
                    }
                } else if (AttachmentUtils.isXopInclude(schemaType)) {
                    String contentId = cursor.getAttributeText(new QName("href"));
                    if (contentId != null && contentId.length() > 0) {
                        contentIds.put(contentId, contentId);
                        isXop = true;

                        Attachment[] attachments = container.getAttachmentsForPart(contentId);
                        if (attachments.length == 1) {
                            XmlCursor cur = cursor.newCursor();
                            if (cur.toParent()) {
                                String contentType = getXmlMimeContentType(cur);
                                if (contentType != null && contentType.length() > 0)
                                    attachments[0].setContentType(contentType);
                            }

                            cur.dispose();
                        }
                    }
                } else {
                    // extract contentId
                    String textContent = XmlUtils.getNodeValue(cursor.getDomNode());
                    if (StringUtils.hasContent(textContent)) {
                        Attachment attachment = null;
                        boolean isXopAttachment = false;

                        // is content a reference to a file?
                        if (container.isInlineFilesEnabled() && textContent.startsWith("file:")) {
                            String filename = textContent.substring(5);
                            if (container.isMtomEnabled()) {
                                MimeBodyPart part = new PreencodedMimeBodyPart("binary");
                                String xmimeContentType = getXmlMimeContentType(cursor);

                                if (StringUtils.isNullOrEmpty(xmimeContentType))
                                    xmimeContentType = ContentTypeHandler.getContentTypeFromFilename(filename);

                                part.setDataHandler(new DataHandler(new XOPPartDataSource(new File(filename),
                                        xmimeContentType, schemaType)));
                                part.setContentID("<" + filename + ">");
                                mp.addBodyPart(part);

                                isXopAttachment = true;
                            } else {
                                if (new File(filename).exists()) {
                                    inlineData(cursor, schemaType, new FileInputStream(filename));
                                } else {
                                    Attachment att = getAttachmentForFilename(container, filename);
                                    if (att != null)
                                        inlineData(cursor, schemaType, att.getInputStream());
                                }
                            }
                        } else {
                            Attachment[] attachmentsForPart = container.getAttachmentsForPart(textContent);
                            if (textContent.startsWith("cid:")) {
                                textContent = textContent.substring(4);
                                attachmentsForPart = container.getAttachmentsForPart(textContent);

                                Attachment[] attachments = attachmentsForPart;
                                if (attachments.length == 1) {
                                    attachment = attachments[0];
                                } else if (attachments.length > 1) {
                                    attachment = buildMulitpartAttachment(attachments);
                                }

                                isXopAttachment = container.isMtomEnabled();
                                contentIds.put(textContent, textContent);
                            }
                            // content should be binary data; is this an XOP element
                            // which should be serialized with MTOM?
                            else if (container.isMtomEnabled() && (SchemaUtils.isBinaryType(schemaType)
                                    || SchemaUtils.isAnyType(schemaType))) {
                                if ("true".equals(System.getProperty("soapui.mtom.strict"))) {
                                    if (SchemaUtils.isAnyType(schemaType)) {
                                        textContent = null;
                                    } else {
                                        for (int c = 0; c < textContent.length(); c++) {
                                            if (Character.isWhitespace(textContent.charAt(c))) {
                                                textContent = null;
                                                break;
                                            }
                                        }
                                    }
                                }

                                if (textContent != null) {
                                    MimeBodyPart part = new PreencodedMimeBodyPart("binary");
                                    String xmimeContentType = getXmlMimeContentType(cursor);

                                    part.setDataHandler(new DataHandler(
                                            new XOPPartDataSource(textContent, xmimeContentType, schemaType)));

                                    textContent = "http://www.soapui.org/" + System.nanoTime();

                                    part.setContentID("<" + textContent + ">");
                                    mp.addBodyPart(part);

                                    isXopAttachment = true;
                                }
                            } else if (container.isInlineFilesEnabled() && attachmentsForPart != null
                                    && attachmentsForPart.length > 0) {
                                attachment = attachmentsForPart[0];
                            }
                        }

                        // add XOP include?
                        if (isXopAttachment && container.isMtomEnabled()) {
                            buildXopInclude(cursor, textContent);
                            isXop = true;
                        }
                        // inline?
                        else if (attachment != null) {
                            inlineAttachment(cursor, schemaType, attachment);
                        }
                    }
                }
            }

            cursor.toNextToken();
        }
    } finally {
        cursor.dispose();
    }

    return isXop;
}

From source file:gov.va.vinci.leo.ae.ExampleWhitespaceTokenizer.java

/**
 * Given a character c return the type definition from the
 * list of public static type definitions in this class.
 *
 * @param c/*  w  w w. j a  va  2s .c o  m*/
 * @return type definition for the character c
 */
private static int characterType(char c) {
    switch (Character.getType(c)) {
    //letters
    case Character.UPPERCASE_LETTER:
    case Character.LOWERCASE_LETTER:
    case Character.TITLECASE_LETTER:
    case Character.MODIFIER_LETTER:
    case Character.OTHER_LETTER:
    case Character.NON_SPACING_MARK:
    case Character.ENCLOSING_MARK:
    case Character.COMBINING_SPACING_MARK:
    case Character.PRIVATE_USE:
    case Character.SURROGATE:
    case Character.MODIFIER_SYMBOL:
        return TK_LETTER;
    //numbers
    case Character.DECIMAL_DIGIT_NUMBER:
    case Character.LETTER_NUMBER:
    case Character.OTHER_NUMBER:
        return TK_NUMBER;
    //Regular Whitespace
    case Character.SPACE_SEPARATOR:
        return TK_WHITESPACE;
    //Punctuation
    case Character.DASH_PUNCTUATION:
    case Character.START_PUNCTUATION:
    case Character.END_PUNCTUATION:
    case Character.OTHER_PUNCTUATION:
        return TK_PUNCTUATION;
    //Simple NewLine
    case Character.LINE_SEPARATOR:
    case Character.PARAGRAPH_SEPARATOR:
        return TK_NEWLINE;
    //Other types of "control" characters
    case Character.CONTROL:
        if (c == '\n' || c == '\r')
            return TK_NEWLINE;
        if (Character.isWhitespace(c)) //Tab char is a "Control" character
            return TK_WHITESPACE;
        return TK_CONTROL;
    default:
        if (Character.isWhitespace(c)) {
            return TK_WHITESPACE;
        } //if
        return TK_UNKNOWN;
    }//switch
}

From source file:de.fau.cs.osr.utils.StringUtils.java

public static String trimRight(String text) {
    int length = text.length();

    while ((0 < length) && (Character.isWhitespace(text.charAt(length - 1))))
        --length;/*from  www .j  a v  a2 s .c o  m*/

    if (length < text.length()) {
        return text.substring(0, length);
    } else {
        return text;
    }
}

From source file:CSVParser.java

/**
 * precondition: sb.length() > 0/*from ww  w .  j  av  a  2s.c o  m*/
 * @param sb A sequence of characters to examine
 * @return true if every character in the sequence is whitespace
 */
protected boolean isAllWhiteSpace(CharSequence sb) {
    boolean result = true;
    for (int i = 0; i < sb.length(); i++) {
        char c = sb.charAt(i);

        if (!Character.isWhitespace(c)) {
            return false;
        }
    }
    return result;
}

From source file:importer.handler.post.stages.Discriminator.java

/**
 * Is a string nothing by white space?/*  w  w  w  . j a  va2 s . c  o m*/
 * @param str the string in question
 * @return true if that is all it is
 */
static boolean isWhitespace(String str) {
    for (int i = 0; i < str.length(); i++)
        if (!Character.isWhitespace(str.charAt(i)))
            return false;
    return true;
}

From source file:info.novatec.testit.livingdoc.html.HtmlEntitiesDecoder.java

private void decodeMarkup() {
    StringBuilder buffer = new StringBuilder();

    for (int index = 0; index < content.length(); index++) {
        char ch = content.charAt(index);

        if (isEntityCandidate(ch)) {
            int endIndex = findEntityEnd(index);

            if (endIndex == -1) {
                buffer.append(ch);//  w  w w.j  a v a2s.c  om
                continue;
            }

            String entity = getEntity(index, endIndex);

            if (Character.isWhitespace(entity.charAt(1))) {
                buffer.append(ch);
                continue;
            }

            Integer iso = decodeEntity(entity);

            buffer.append(iso == null ? entity : (char) iso.intValue());

            index = endIndex;
        } else {
            buffer.append(ch);
        }
    }

    content = buffer.toString();
}