Example usage for java.lang Character isLetter

List of usage examples for java.lang Character isLetter

Introduction

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

Prototype

public static boolean isLetter(int codePoint) 

Source Link

Document

Determines if the specified character (Unicode code point) is a letter.

Usage

From source file:boa.BoaMain.java

protected static String pascalCase(final String string) {
    final StringBuilder pascalized = new StringBuilder();

    boolean upper = true;
    for (final char c : string.toCharArray())
        if (Character.isDigit(c) || c == '_') {
            pascalized.append(c);//  www  .j a va 2  s . co  m
            upper = true;
        } else if (!Character.isDigit(c) && !Character.isLetter(c)) {
            upper = true;
        } else if (Character.isLetter(c)) {
            pascalized.append(upper ? Character.toUpperCase(c) : c);
            upper = false;
        }

    return pascalized.toString();
}

From source file:com.ikanow.infinit.e.harvest.utils.DateUtility.java

public synchronized static long parseDate(String sDate) {
    if (null == _allowedDatesArray_startsWithLetter) {
        _allowedDatesArray_startsWithLetter = new String[] { DateFormatUtils.SMTP_DATETIME_FORMAT.getPattern(),

                "MMM d, yyyy hh:mm a", "MMM d, yyyy HH:mm", "MMM d, yyyy hh:mm:ss a", "MMM d, yyyy HH:mm:ss",
                "MMM d, yyyy hh:mm:ss.SS a", "MMM d, yyyy HH:mm:ss.SS",

                "EEE MMM dd HH:mm:ss zzz yyyy", "EEE MMM dd yyyy HH:mm:ss zzz",
                "EEE MMM dd yyyy HH:mm:ss 'GMT'Z (zzz)", };
        _allowedDatesArray_numeric_1 = new String[] { "yyyy-MM-dd'T'HH:mm:ss'Z'",
                DateFormatUtils.ISO_DATE_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATE_TIME_ZONE_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(),
                DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() };

        _allowedDatesArray_numeric_2 = new String[] { "yyyyMMdd", "yyyyMMdd hh:mm a", "yyyyMMdd HH:mm",
                "yyyyMMdd hh:mm:ss a", "yyyyMMdd HH:mm:ss", "yyyyMMdd hh:mm:ss.SS a", "yyyyMMdd HH:mm:ss.SS",
                // Julian, these are unlikely
                "yyyyDDD", "yyyyDDD hh:mm a", "yyyyDDD HH:mm", "yyyyDDD hh:mm:ss a", "yyyyDDD HH:mm:ss",
                "yyyyDDD hh:mm:ss.SS a", "yyyyDDD HH:mm:ss.SS", };
        _allowedDatesArray_stringMonth = new String[] { "dd MMM yy", "dd MMM yy hh:mm a", "dd MMM yy HH:mm",
                "dd MMM yy hh:mm:ss a", "dd MMM yy HH:mm:ss", "dd MMM yy hh:mm:ss.SS a",
                "dd MMM yy HH:mm:ss.SS", };
        _allowedDatesArray_numericMonth = new String[] { "MM dd yy", "MM dd yy hh:mm a", "MM dd yy HH:mm",
                "MM dd yy hh:mm:ss a", "MM dd yy HH:mm:ss", "MM dd yy hh:mm:ss.SS a", "MM dd yy HH:mm:ss.SS", };
    }/*from   ww w . java 2s.c o  m*/

    // Starts with day or month:

    String sDateTmp = sDate;
    if (Character.isLetter(sDate.charAt(0))) {
        try {
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_startsWithLetter);
            return date.getTime();
        } catch (Exception e) {
        } // keep going         
    } //TESTED
    else if (Character.isLetter(sDate.charAt(5))) {

        // month must be string, doesn't start with day though

        try {
            int index = sDate.indexOf(':');
            if (index > 0) {
                sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " "))
                        .append(sDate.substring(index)).toString();
            } else {
                sDate = sDate.replaceAll("[ ./-]", " ");
            }
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_stringMonth);
            return date.getTime();
        } catch (Exception e) {
        } // keep going                              
    } //TESTED
    else {

        // Starts with a number most likely...

        int n = 0;
        for (; n < 4; ++n) {
            if (!Character.isDigit(sDate.charAt(n))) {
                break;
            }
        }
        if (4 == n) {

            // (Probably starts with a year)            

            // One of the formal formats starting with a year            

            try {
                Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_1);
                return date.getTime();
            } catch (Exception e) {
            } // keep going

            // Something more ad hoc starting with a year                        

            try {
                int index = sDate.indexOf(':');
                if (index > 0) {
                    sDate = new StringBuffer(sDate.substring(0, index).replace("-", ""))
                            .append(sDate.substring(index)).toString();
                } else {
                    sDate = sDate.replace("-", "");
                }
                Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numeric_2);
                return date.getTime();
            } catch (Exception e) {
            } // keep going                     
        } //TESTED

        // Probably starts with a day         

        try {
            int index = sDate.indexOf(':');
            if (index > 0) {
                sDate = new StringBuffer(sDate.substring(0, index).replaceAll("[./-]", " "))
                        .append(sDate.substring(index)).toString();
            } else {
                sDate = sDate.replaceAll("[./-]", " ");
            }
            Date date = DateUtils.parseDate(sDate, _allowedDatesArray_numericMonth);
            return date.getTime();
        } //TESTED
        catch (Exception e) {
        } // keep going                     

    }
    sDate = sDateTmp;

    // If we're here, nothing's worked, try "natural language processing"

    try {
        return Chronic.parse(sDate).getBeginCalendar().getTime().getTime();
    } //TESTED
    catch (Exception e2) {
        // Error all the way out
        throw new RuntimeException("Can't parse: " + sDate);
    } //TESTED
}

From source file:de.l3s.boilerpipe.sax.XpathExtractor.java

public static int countWords(String s) {

    int wordCount = 0;

    boolean word = false;
    int endOfLine = s.length() - 1;

    for (int i = 0; i < s.length(); i++) {
        // if the char is a letter, word = true.
        if (Character.isLetter(s.charAt(i)) && i != endOfLine) {
            word = true;/*from   w  ww  .  ja  va  2 s  .  com*/
            // if char isn't a letter and there have been letters before,
            // counter goes up.
        } else if (!Character.isLetter(s.charAt(i)) && word) {
            wordCount++;
            word = false;
            // last word of String; if it doesn't end with a non letter, it
            // wouldn't count without this.
        } else if (Character.isLetter(s.charAt(i)) && i == endOfLine) {
            wordCount++;
        }
    }
    return wordCount;
}

From source file:org.nuxeo.ecm.core.convert.plugins.text.extractors.HtmlParser.java

private String filterAndJoin(String text) {
    boolean space = false;
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);

        if (c == '\n' || c == ' ' || Character.isWhitespace(c)) {
            if (!space) {
                space = true;//w  w  w.java2 s .  c o m
                buffer.append(' ');
            }
            continue;
        }
        if (!Character.isLetter(c) && !Character.isDigit(c)) {
            if (!space) {
                space = true;
                buffer.append(' ');
            }
            continue;
        }
        space = false;
        buffer.append(c);
    }
    return buffer.toString();
}

From source file:stroom.streamstore.server.fs.FileSystemUtil.java

public static String encodeFileName(String fileName) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < fileName.length(); i++) {
        char c = fileName.charAt(i);
        if (Character.isLetter(c) || Character.isDigit(c) || c == '.' || c == ' ' || c == '-' || c == '_') {
            builder.append(c);//from   w w  w  .  j av  a2  s.  c o m
        } else {
            builder.append("#");
            builder.append(StringUtils.leftPad(Integer.toHexString(c), 3, '0'));
        }
    }
    return builder.toString();
}

From source file:biz.gabrys.lesscss.extended.compiler.source.LocalSource.java

static boolean isAbsolutePath(final String path, final boolean windowsOperatingSystem) {
    if (path != null && path.indexOf('\0') > -1) {
        return false;
    }/*from  w  w w.j a va2  s. c o  m*/

    final String normalizedPath = FilenameUtils.normalize(path, true);
    if (StringUtils.isEmpty(normalizedPath)) {
        return false;
    }

    final char separator = '/';
    final char firstChar = normalizedPath.charAt(0);
    if (!windowsOperatingSystem) {
        return firstChar == separator;
    }

    if (!Character.isLetter(firstChar)) {
        return false;
    }

    final int colonIndex = normalizedPath.indexOf(':');
    return colonIndex == 1 && normalizedPath.length() > 2 && normalizedPath.charAt(2) == separator;
}

From source file:org.marketcetera.util.misc.RandomStringsTest.java

private static void testStrId(int len, String s) {
    int[] ucps = StringUtils.toUCPArray(s);
    assertEquals(len, ucps.length);//w  w  w.  ja  va  2  s.  co m
    if (len >= 1) {
        assertTrue("Value was " + Integer.toHexString(ucps[0]), Character.isLetter(ucps[0]));
    }
    if (len >= 2) {
        assertTrue("Value was " + Integer.toHexString(ucps[1]), Character.isDigit(ucps[1]));
    }
    for (int i = 2; i < len; i++) {
        assertTrue("Value was " + Integer.toHexString(ucps[i]), Character.isLetterOrDigit(ucps[i]));
    }
}

From source file:org.apache.archiva.web.startup.Banner.java

public static String decode(String encoded) {
    StringBuilder decoded = new StringBuilder();
    int enlen = encoded.length();
    for (int i = 0; i < enlen; i++) {
        char c = encoded.charAt(i);
        if (c == '$') {
            char nc = encoded.charAt(i + 1);
            if (nc == '$') {
                decoded.append('$');
                i++;/*from  ww  w .j  a  va 2 s.  c o m*/
            } else if (nc == '.') {
                decoded.append('\\');
                i++;
            } else if (nc == 'n') {
                decoded.append(eol);
                i++;
            } else if (Character.isDigit(nc)) {
                int count = 0;
                int nn = i + 1;
                while (Character.isDigit(nc)) {
                    count = (count * 10);
                    count += (nc - '0');
                    nc = encoded.charAt(++nn);
                }
                for (int d = 0; d < count; d++) {
                    decoded.append(nc);
                }
                i = nn;
            }
        } else if (Character.isLetter(c)) {
            decoded.append(rot13(c));
        } else {
            decoded.append(c);
        }
    }

    return decoded.toString();
}

From source file:com.pfarrell.utils.misc.TextTools.java

/**
 * make a string with only letters/*from   ww  w .  j av  a2 s .co  m*/
 * @param arg  string
 * @return string with only letters, no punct, space, digits, etc.
 */
public static String justLetters(String arg) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < arg.length(); i++) {
        int c = arg.codePointAt(i);
        if (Character.isLetter(c)) {
            sb.appendCodePoint(c);
        }
    }
    return sb.toString();
}

From source file:de.micromata.genome.gwiki.plugin.wikilink_1_0.GWikiWikiLinkFragment.java

public static GWikiFragment parseText(GWikiFragmentText textFrag) {
    String text = textFrag.getSource();
    ParseState state = ParseState.Start;
    int startLink = 0;
    GWikiFragmentChildContainer fcc = new GWikiFragmentChildContainer();
    boolean startWord = true;
    for (int i = 0; i < text.length(); ++i) {
        char c = text.charAt(i);

        switch (state) {
        case Start:
            boolean ws = Character.isWhitespace(c);
            if (ws == true || Character.isLetter(c) == false) {
                // addTextFrag(fcc, text.substring(startLink, i));
                // startLink = i;
                startWord = ws;//from   www  . j  a v  a 2s. c o m
                continue;
            }

            if (startWord == true && Character.isUpperCase(c) == true) {
                if (startLink != i) {
                    addTextFrag(fcc, text.substring(startLink, i));
                }
                startLink = i;
                state = ParseState.InWikiLink;
                break;
            }
            startWord = ws;
            break;
        case InWikiLink:
            if (Character.isLetter(c) == false) {
                String k = text.substring(startLink, i);
                if (isWikiLinkWord(k) == true) {
                    fcc.addChild(new GWikiWikiLinkFragment(k));
                } else {
                    addTextFrag(fcc, k);
                }

                startLink = i;
                state = ParseState.Start;
            }

            break;
        }
    }
    if (startLink < text.length()) {
        String k = text.substring(startLink);
        if (state == ParseState.InWikiLink && isWikiLinkWord(k) == true) {
            fcc.addChild(new GWikiWikiLinkFragment(k));
        } else {
            addTextFrag(fcc, k);
        }
    }
    return unfoldParsed(fcc);
}