Java Char Convert To convertCharToSimpleRegex(String str, char lastChar, char currentChar)

Here you can find the source of convertCharToSimpleRegex(String str, char lastChar, char currentChar)

Description

convert Char To Simple Regex

License

Open Source License

Parameter

Parameter Description
str a parameter
lastChar a parameter
currentChar a parameter

Declaration

private static String convertCharToSimpleRegex(String str, char lastChar, char currentChar) 

Method Source Code

//package com.java2s;
/*//from  w ww.  j ava2  s .c om
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

public class Main {
    /**
     * 
     * @param str
     * @param lastChar
     * @param currentChar
     */
    private static String convertCharToSimpleRegex(String str, char lastChar, char currentChar) {
        if (Character.isLetter(currentChar)) {
            if (Character.isLetter(lastChar)) {
                //nothing, just go ahead
            } else if (Character.isDigit(lastChar)) {
                str += "N";
            } else {
                if (lastChar != '\0') {
                    str += Character.toString(lastChar);
                }
            }
        } else if (Character.isDigit(currentChar)) {
            if (Character.isLetter(lastChar)) {
                str += "W";
            } else if (Character.isDigit(lastChar)) {
                //nothing, just go ahead
            } else {
                if (lastChar != '\0') {
                    str += Character.toString(lastChar);
                }
            }
        } else {
            if (Character.isLetter(lastChar)) {
                str += "W";
            } else if (Character.isDigit(lastChar)) {
                str += "N";
            } else {
                if (lastChar != '\0') {
                    str += Character.toString(lastChar);
                }
            }
        }
        return str;
    }
}

Related

  1. convertCharsToUnicodeChars(final String s, final boolean toLowerCase)
  2. convertCharToBoolean(final char value)
  3. convertCharToCharacterArray(final Object originalArray)
  4. convertCharToInt(char input)
  5. convertCharToShort(final char[] tmp, final short[] buffer)