Example usage for java.lang Character isLetterOrDigit

List of usage examples for java.lang Character isLetterOrDigit

Introduction

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

Prototype

public static boolean isLetterOrDigit(int codePoint) 

Source Link

Document

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

Usage

From source file:org.dasein.cloud.nimbula.network.SecurityList.java

private String toSecurityListName(String rawName) throws CloudException, InternalException {
    StringBuilder str = new StringBuilder();

    rawName = rawName.toLowerCase();//w w  w. ja va2  s .  c  om
    for (int i = 0; i < rawName.length(); i++) {
        char c = rawName.charAt(i);

        if (Character.isLetterOrDigit(c)) {
            str.append(c);
        }
    }
    ProviderContext ctx = provider.getContext();

    if (ctx == null) {
        throw new CloudException("No context was set for this request");
    }
    if (str.length() > 0) {
        String acct = ctx.getAccountNumber();

        try {
            String user = new String(ctx.getAccessPublic(), "utf-8");

            return ("/" + acct + "/" + user + "/" + str.toString());
        } catch (UnsupportedEncodingException e) {
            throw new InternalException(e);
        }
    }
    throw new CloudException("Invalid name: " + rawName);
}

From source file:org.dhatim.smooks.scripting.groovy.GroovyContentHandlerFactory.java

private String getElementName(SmooksResourceConfiguration configuration) {
    String elementName = configuration.getTargetElement();

    for (int i = 0; i < elementName.length(); i++) {
        if (!Character.isLetterOrDigit(elementName.charAt(i))) {
            return elementName + "_Mangled";
        }// w  w w.  j a v a2  s  .co m
    }

    return elementName;
}

From source file:org.cryptomator.ui.model.Vault.java

/**
 * Tries to form a similar string using the regular latin alphabet.
 * /*from   w w w  . j av a2 s.c  o  m*/
 * @param string
 * @return a string composed of a-z, A-Z, 0-9, and _.
 */
public static String normalize(String string) {
    String normalized = Normalizer.normalize(string, Form.NFD);
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < normalized.length(); i++) {
        char c = normalized.charAt(i);
        if (Character.isWhitespace(c)) {
            if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
                builder.append('_');
            }
        } else if (c < 127 && Character.isLetterOrDigit(c)) {
            builder.append(c);
        } else if (c < 127) {
            if (builder.length() == 0 || builder.charAt(builder.length() - 1) != '_') {
                builder.append('_');
            }
        }
    }
    return builder.toString();
}

From source file:com.df.kia.procedures.CarRecogniseLayout.java

private void init(final Context context) {
    rootView = LayoutInflater.from(context).inflate(R.layout.car_recognise_layout, this);

    deleteLastLicensePhoto();//  www  .j  a v a 2s .  c o  m

    mCarSettings = InputProceduresLayout.mCarSettings;

    licenseRecognise = new LicenseRecognise(context, AppCommon.licensePhotoPath);

    licenseImageView = (ImageView) findViewById(R.id.licenseImage);
    licenseImageView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            licenseRecognise.takePhoto(mHandler);
        }
    });

    // 
    recogniseButton = (Button) rootView.findViewById(R.id.recognise_button);
    recogniseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // ???
            if (!mCarSettings.getBrandString().equals("")) {
                reRecognise(R.string.reRecognise1);
            } else if (!getEditViewText(rootView, R.id.plateNumber_edit).equals("")) {
                reRecognise(R.string.reRecognise);
            } else {
                //fillInDummyData();
                if (licensePhotoExist())
                    recogniseLicense();
                else
                    Toast.makeText(context, "???", Toast.LENGTH_SHORT).show();
            }
        }
    });

    // vin
    Button vinConfirmButton = (Button) rootView.findViewById(R.id.vinConfirm_button);
    vinConfirmButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // VIN??
            if (getEditViewText(rootView, R.id.vin_edit).equals("")) {
                Toast.makeText(rootView.getContext(), "VIN?", Toast.LENGTH_SHORT).show();
            } else {
                checkVinAndGetCarSettings();
            }
        }
    });

    // ?
    Button brandSelectButton = (Button) rootView.findViewById(R.id.brand_select_button);
    brandSelectButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            selectCarManually();
        }
    });

    vehicleTypeEdit = (EditText) rootView.findViewById(R.id.vehicleType_edit);
    vehicleTypeEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.vehicleType_items, R.id.vehicleType_edit);
                break;
            }
            return false;
        }
    });

    useCharacterEdit = (EditText) rootView.findViewById(R.id.useCharacter_edit);
    useCharacterEdit.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                choose(R.array.useCharacter_items, R.id.useCharacter_edit);
                break;
            }
            return false;
        }
    });

    // vin???
    InputFilter alphaNumericFilter = new InputFilter() {
        @Override
        public CharSequence filter(CharSequence arg0, int arg1, int arg2, Spanned arg3, int arg4, int arg5) {
            for (int k = arg1; k < arg2; k++) {
                if (!Character.isLetterOrDigit(arg0.charAt(k))) {
                    return "";
                }
            }
            return null;
        }
    };

    EditText vin_edit = (EditText) findViewById(R.id.vin_edit);
    vin_edit.setFilters(new InputFilter[] { alphaNumericFilter, new InputFilter.AllCaps(),
            new InputFilter.LengthFilter(17) });

    EditText plateNumberEdit = (EditText) findViewById(R.id.plateNumber_edit);
    plateNumberEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(10) });

    EditText licenseModelEdit = (EditText) findViewById(R.id.licenseModel_edit);
    licenseModelEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(22) });

    EditText engineSerialEdit = (EditText) findViewById(R.id.engineSerial_edit);
    engineSerialEdit
            .setFilters(new InputFilter[] { new InputFilter.AllCaps(), new InputFilter.LengthFilter(17) });

    vehicleModel = MainActivity.vehicleModel;
}

From source file:be.brunoparmentier.wifikeyshare.ui.activities.WifiNetworkActivity.java

private static void setPasswordRestrictions(EditText editText) {
    // Source: http://stackoverflow.com/a/4401227
    InputFilter filter = new InputFilter() {

        @Override/*from  w  w  w  .  ja va  2 s. c o m*/
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart,
                int dend) {
            // TODO: check that the filter follows WEP/WPA recommendations
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))) {
                    return "";
                }
            }
            return null;
        }
    };
    editText.setFilters(new InputFilter[] { filter });
}

From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java

public static boolean isLetterOrDigitWithExceptions(String input) {
    // validate for intentCode
    boolean validValue = true;
    if (input != null && !input.equals("Chemical / Drug") && !input.equals("Growth Factor")
            && !input.equals("Signaling Molecule")) {
        for (int i = 0; i < input.length(); i++) {
            if (!Character.isLetterOrDigit(input.charAt(i)))
                return false;
        }//from w  w w  .ja  va 2 s .c  o m
    } else if (input.equals("Chemical / Drug")) {
        input = "ChemicalDrug";
        for (int i = 0; i < input.length(); i++) {
            if (!Character.isLetterOrDigit(input.charAt(i)))
                return false;
        }
    } else if (input.equals("Growth Factor")) {
        input = "GrowthFactor";
        for (int i = 0; i < input.length(); i++) {
            if (!Character.isLetterOrDigit(input.charAt(i)))
                return false;
        }
    } else if (input.equals("Signaling Molecule")) {
        input = "SignalingMolecule";
        for (int i = 0; i < input.length(); i++) {
            if (!Character.isLetterOrDigit(input.charAt(i)))
                return false;
        }
    }

    return true;
}

From source file:com.tasktop.internal.hp.qc.core.model.comments.mylyn3_8.HtmlStreamTokenizer_m3_8.java

/**
 * Replaces (in-place) HTML escapes in a StringBuffer with their corresponding characters.
 * /*from w  ww.j  av a  2  s  .c  o  m*/
 * @deprecated use {@link StringEscapeUtils#unescapeHtml(String)} instead
 */
@Deprecated
public static StringBuffer unescape(StringBuffer sb) {
    int i = 0; // index into the unprocessed section of the buffer
    int j = 0; // index into the processed section of the buffer

    while (i < sb.length()) {
        char ch = sb.charAt(i);
        if (ch == '&') {
            int start = i;
            String escape = null;
            for (i = i + 1; i < sb.length(); i++) {
                ch = sb.charAt(i);
                if (!Character.isLetterOrDigit(ch) && !(ch == '#' && i == (start + 1))) {
                    escape = sb.substring(start + 1, i);
                    break;
                }
            }
            if (i == sb.length() && i != (start + 1)) {
                escape = sb.substring(start + 1);
            }
            if (escape != null) {
                Character character = parseReference(escape);
                if (character != null && !((0x0A == character || 0x0D == character || 0x09 == ch)
                        || (character >= 0x20 && character <= 0xD7FF)
                        || (character >= 0xE000 && character <= 0xFFFD)
                        || (character >= 0x10000 && character <= 0x10FFFF))) {
                    // Character is an invalid xml character
                    // http://www.w3.org/TR/REC-xml/#charsets
                    character = null;
                }
                if (character != null) {
                    ch = character.charValue();
                } else {
                    // not an HTML escape; rewind
                    i = start;
                    ch = '&';
                }
            }
        }
        sb.setCharAt(j, ch);
        i++;
        j++;
    }

    sb.setLength(j);
    return sb;
}

From source file:com.l2jfree.gameserver.util.Util.java

public static boolean isAlphaNumeric(String text) {
    if (text == null)
        return false;
    boolean result = true;
    char[] chars = text.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (!Character.isLetterOrDigit(chars[i])) {
            result = false;/*from   w w w .j av a2  s  .  co m*/
            break;
        }
    }
    return result;
}

From source file:org.opendatakit.common.utils.WebUtils.java

/**
 * Useful static method for constructing a UPPER_CASE persistence layer name
 * from a camelCase name. This inserts an underscore before a leading capital
 * letter and toUpper()s the resulting string. The transformation maps
 * multiple camelCase names to the same UPPER_CASE name so it is not
 * reversible.//from w  w  w  . ja  v a 2s . co  m
 * <ul>
 * <li>thisURL => THIS_URL</li>
 * <li>thisUrl => THIS_URL</li>
 * <li>myFirstObject => MY_FIRST_OBJECT</li>
 * </ul>
 *
 * @param name
 * @return
 */
public static final String unCamelCase(String name) {
    StringBuilder b = new StringBuilder();
    boolean lastCap = true;
    for (int i = 0; i < name.length(); ++i) {
        char ch = name.charAt(i);
        if (Character.isUpperCase(ch)) {
            if (!lastCap) {
                b.append('_');
            }
            lastCap = true;
            b.append(ch);
        } else if (Character.isLetterOrDigit(ch)) {
            lastCap = false;
            b.append(Character.toUpperCase(ch));
        } else {
            throw new IllegalArgumentException("Argument is not a valid camelCase name: " + name);
        }
    }
    return b.toString();
}

From source file:com.evanmclean.evlib.text.FuzzyCompare.java

/**
 * Remove any leading or tailing non-alphanumeric (in particular, punctuation)
 * characters./*  w  ww.  j  a v  a2 s. c  om*/
 * 
 * @param word
 * @return
 */
private String trim(final String word) {
    final int len = word.length();
    int end = len;
    while ((end > 0) && (!Character.isLetterOrDigit(word.charAt(end - 1))))
        --end;
    int start = 0;
    while ((start < end) && (!Character.isLetterOrDigit(word.charAt(start))))
        ++start;
    if ((start <= 0) && (end >= len))
        return word;
    return word.substring(start, end);
}