Example usage for org.apache.commons.lang CharUtils CR

List of usage examples for org.apache.commons.lang CharUtils CR

Introduction

In this page you can find the example usage for org.apache.commons.lang CharUtils CR.

Prototype

char CR

To view the source code for org.apache.commons.lang CharUtils CR.

Click Source Link

Document

carriage return CR ('\r').

Usage

From source file:de.hybris.platform.jobs.RemovedItemPKProcessorTest.java

private InputStream buildUpStream(final Object... args) {
    //ByteInputStream  bis = new ByteInputStream();
    final StringBuilder builder = new StringBuilder(1000);
    for (final Object arg : args) {
        builder.append(arg).append(CharUtils.CR);
    }//from w  w  w  .j a va 2 s.c o  m
    return new ByteArrayInputStream(builder.toString().getBytes());
}

From source file:com.dtolabs.rundeck.core.cli.CLIUtils.java

public static void escapeUnixShellChars(StringBuilder out, String str) {
    if (StringUtils.containsNone(str, UNIX_SHELL_CHARS)) {
        if (str != null) {
            out.append(str);//ww  w .j  av  a2 s . c  om
        }
        return;
    }
    for (int i = 0; i < str.length(); i++) {
        char c = str.charAt(i);
        if (UNIX_SHELL_CHARS.indexOf(c) >= 0) {
            out.append('\\');
        } else if (WS_CHARS.indexOf(c) >= 0) {
            out.append('\\');
            if (c == CharUtils.CR) {
                out.append('r');
            } else if (c == CharUtils.LF) {
                out.append('n');
            } else if (c == '\t') {
                out.append('t');
            }
            continue;
        }
        out.append(c);
    }
}

From source file:com.test.stringtest.StringUtils.java

/**
 * <p>Removes one newline from end of a String if it's there,
 * otherwise leave it alone.  A newline is &quot;<code>\n</code>&quot;,
 * &quot;<code>\r</code>&quot;, or &quot;<code>\r\n</code>&quot;.</p>
 *
 * <p>NOTE: This method changed in 2.0.
 * It now more closely matches Perl chomp.</p>
 *
 * <pre>/*  ww w.j  a  v  a 2  s .  c  om*/
 * StringUtils.chomp(null)          = null
 * StringUtils.chomp("")            = ""
 * StringUtils.chomp("abc \r")      = "abc "
 * StringUtils.chomp("abc\n")       = "abc"
 * StringUtils.chomp("abc\r\n")     = "abc"
 * StringUtils.chomp("abc\r\n\r\n") = "abc\r\n"
 * StringUtils.chomp("abc\n\r")     = "abc\n"
 * StringUtils.chomp("abc\n\rabc")  = "abc\n\rabc"
 * StringUtils.chomp("\r")          = ""
 * StringUtils.chomp("\n")          = ""
 * StringUtils.chomp("\r\n")        = ""
 * </pre>
 *
 * @param str  the String to chomp a newline from, may be null
 * @return String without newline, <code>null</code> if null String input
 */
public static String chomp(String str) {
    if (isEmpty(str)) {
        return str;
    }

    if (str.length() == 1) {
        char ch = str.charAt(0);
        if (ch == CharUtils.CR || ch == CharUtils.LF) {
            return EMPTY;
        }
        return str;
    }

    int lastIdx = str.length() - 1;
    char last = str.charAt(lastIdx);

    if (last == CharUtils.LF) {
        if (str.charAt(lastIdx - 1) == CharUtils.CR) {
            lastIdx--;
        }
    } else if (last != CharUtils.CR) {
        lastIdx++;
    }
    return str.substring(0, lastIdx);
}

From source file:com.test.stringtest.StringUtils.java

/**
 * <p>Remove the last character from a String.</p>
 *
 * <p>If the String ends in <code>\r\n</code>, then remove both
 * of them.</p>//from w w w .  ja  v a 2s  .  co  m
 *
 * <pre>
 * StringUtils.chop(null)          = null
 * StringUtils.chop("")            = ""
 * StringUtils.chop("abc \r")      = "abc "
 * StringUtils.chop("abc\n")       = "abc"
 * StringUtils.chop("abc\r\n")     = "abc"
 * StringUtils.chop("abc")         = "ab"
 * StringUtils.chop("abc\nabc")    = "abc\nab"
 * StringUtils.chop("a")           = ""
 * StringUtils.chop("\r")          = ""
 * StringUtils.chop("\n")          = ""
 * StringUtils.chop("\r\n")        = ""
 * </pre>
 *
 * @param str  the String to chop last character from, may be null
 * @return String without last character, <code>null</code> if null String input
 */
public static String chop(String str) {
    if (str == null) {
        return null;
    }
    int strLen = str.length();
    if (strLen < 2) {
        return EMPTY;
    }
    int lastIdx = strLen - 1;
    String ret = str.substring(0, lastIdx);
    char last = str.charAt(lastIdx);
    if (last == CharUtils.LF) {
        if (ret.charAt(lastIdx - 1) == CharUtils.CR) {
            return ret.substring(0, lastIdx - 1);
        }
    }
    return ret;
}

From source file:org.itstechupnorth.walrus.base.ArticleBuffer.java

public void textLine(String line) {
    buffer.append(line);
    buffer.append(CharUtils.CR);
    buffer.append(CharUtils.LF);
}

From source file:org.itstechupnorth.walrus.text.wiki.micro.MicroWikiPullParser.java

private WikiState seekNext() {
    if (buffer.hasRemaining()) {
        Token last = Token.OTHER;//from   www .  j a v  a2  s  . c o  m
        while (buffer.hasRemaining()) {
            char next = buffer.get();
            if (next != '=') {
                if (last == Token.EQEQ) {
                    backstep();
                    return next(Token.EQEQ);
                } else if (last == Token.EQEQEQ) {
                    backstep();
                    return next(Token.EQEQEQ);
                } else if (last == Token.EQ4) {
                    backstep();
                    return next(Token.EQ4);
                } else if (last == Token.EQ5) {
                    backstep();
                    return next(Token.EQ5);
                } else if (last == Token.EQ6) {
                    backstep();
                    return next(Token.EQ6);
                }
            }
            switch (next) {
            case '}':
                if (last == Token.CLOSED_CURLY) {
                    return next(Token.CLOSED_CURLY);
                }
                last = Token.CLOSED_CURLY;
                break;
            case '{':
                if (last == Token.OPEN_CURLY) {
                    return next(Token.OPEN_CURLY);
                }
                last = Token.OPEN_CURLY;
                break;
            case ']':
                if (last == Token.CLOSED_SQUARE) {
                    return next(Token.CLOSED_SQUARE);
                }
                last = Token.CLOSED_SQUARE;
                break;
            case '[':
                if (last == Token.OPEN_SQUARE) {
                    return next(Token.OPEN_SQUARE);
                }
                last = Token.OPEN_SQUARE;
                break;
            case '#':
                return next(Token.HASH);
            case '*':
                return next(Token.STAR);
            case '|':
                return next(Token.PIPE);
            case CharUtils.CR:
                if (last == Token.CR) {
                    return next(Token.CR);
                } else if (last == Token.CRLF) {
                    last = Token.CRLFCR;
                } else {
                    last = Token.CR;
                }
                break;
            case CharUtils.LF:
                if (last == Token.LF) {
                    return next(Token.LF);
                } else if (last == Token.CRLFCR) {
                    return next(Token.CRLFCR);
                } else if (last == Token.CR) {
                    last = Token.CRLF;
                } else {
                    last = Token.LF;
                }
                break;
            case '=':
                if (last == Token.EQ) {
                    last = Token.EQEQ;
                } else if (last == Token.EQEQ) {
                    last = Token.EQEQEQ;
                } else if (last == Token.EQEQEQ) {
                    last = Token.EQ4;
                } else if (last == Token.EQ4) {
                    last = Token.EQ5;
                } else if (last == Token.EQ5) {
                    last = Token.EQ6;
                } else {
                    last = Token.EQ;
                }
                break;
            default:
                last = Token.OTHER;
                break;
            }

        }
        if (last == Token.EQEQ) {
            return next(Token.EQEQ);
        } else if (last == Token.EQEQEQ) {
            return next(Token.EQEQEQ);
        } else if (last == Token.EQ4) {
            return next(Token.EQ4);
        } else if (last == Token.EQ5) {
            return next(Token.EQ5);
        } else if (last == Token.EQ6) {
            return next(Token.EQ6);
        }
    }
    textEnd = buffer.position();
    return WikiState.END;
}

From source file:org.itstechupnorth.walrus.text.wiki.neo.MicroWikiPullParserStateTest.java

public void testCR() throws Exception {
    WikiPullParser parser = new MicroWikiPullParser("[[" + CharUtils.CR);
    assertEquals(WikiState.OPEN_SQUARE, parser.next());
    assertEquals(WikiState.END, parser.next());
}

From source file:org.itstechupnorth.walrus.text.wiki.neo.MicroWikiPullParserStateTest.java

public void testCRLF() throws Exception {
    WikiPullParser parser = new MicroWikiPullParser("[[" + CharUtils.CR + CharUtils.LF);
    assertEquals(WikiState.OPEN_SQUARE, parser.next());
    assertEquals(WikiState.END, parser.next());
}

From source file:org.itstechupnorth.walrus.text.wiki.neo.MicroWikiPullParserStateTest.java

public void testCRCR() throws Exception {
    WikiPullParser parser = new MicroWikiPullParser("[[" + CharUtils.CR + CharUtils.CR);
    assertEquals(WikiState.OPEN_SQUARE, parser.next());
    assertEquals(WikiState.EMPTY_LINE, parser.next());
    assertEquals(WikiState.END, parser.next());
}

From source file:org.itstechupnorth.walrus.text.wiki.neo.MicroWikiPullParserStateTest.java

public void testCRLFCRLF() throws Exception {
    WikiPullParser parser = new MicroWikiPullParser(
            "[[" + CharUtils.CR + CharUtils.LF + CharUtils.CR + CharUtils.LF);
    assertEquals(WikiState.OPEN_SQUARE, parser.next());
    assertEquals(WikiState.EMPTY_LINE, parser.next());
    assertEquals(WikiState.END, parser.next());
}