Java tutorial
//package com.java2s; /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.text.TextUtils; import java.util.Arrays; import java.util.HashSet; import java.util.Set; public class Main { private static final Set<Character> sUnAcceptableAsciiInV21WordSet = new HashSet<>( Arrays.asList('[', ']', '=', ':', '.', ',', ' ')); /** * <p> * Returns true when the given String is categorized as "word" specified in vCard spec 2.1. * </p> * <p> * vCard 2.1 specifies:<br /> * word = <any printable 7bit us-ascii except []=:., > * </p> */ public static boolean isV21Word(final String value) { if (TextUtils.isEmpty(value)) { return true; } final int asciiFirst = 0x20; final int asciiLast = 0x7E; // included final int length = value.length(); for (int i = 0; i < length; i = value.offsetByCodePoints(i, 1)) { final int c = value.codePointAt(i); if (!(asciiFirst <= c && c <= asciiLast) || sUnAcceptableAsciiInV21WordSet.contains((char) c)) { return false; } } return true; } }