package com.ejlchina.searcher.util;

public class StringUtils {


	public static boolean isBlank(String str) {
		if (str == null) {
			return true;
		}
		int len = str.length();
		if (len == 0) {
			return true;
		}
		for (int i = 0; i < len; i++) {
			switch (str.charAt(i)) {
			case ' ':
			case '\t':
			case '\n':
			case '\r':
				break;
			default:
				return false;
			}
		}
		return true;
	}
	
	public static String firstCharToUpperCase(String string) {
		if (string == null || string.length() == 0) {
			return string;
		}
		char first = string.charAt(0);
		first = (char) (first - 32);
		if (string.length() == 1) {
			return String.valueOf(first);
		}
		return first + string.substring(1);
	}
    
	
	/**
	 * 查找 src 里包含几个 target
	 * @param src 源字符串
	 * @param from 开始计数下标（包含）
	 * @param to 结束计数下标（不包含）
	 * @param targets 目标字符
	 * @return 个数
	 */
	public static int containCount(String src, int from, int to, char[] targets) {
		int count = 0;
		if (src != null) {
			from = Math.max(from, 0);
			to = Math.min(to, src.length());
			for (int i = from; i < to; i ++) {
				char c = src.charAt(i);
				boolean contained = false;
				for (char target : targets) {
					if (c == target) {
						contained = true;
						break;
					}
				}
				if (contained) {
					count++;
				}
			}
		}
		return count;
	}
	
	
	public static String[] toUpperCase(String[] ts) {
		for (int i = 0; i < ts.length; i++) {
			if (ts[i] != null) {
				ts[i] = ts[i].toUpperCase();
			}
		}
		return ts;
	}
	
}

@@ -559,16 +559,55 @@
 rAt(0);%0A
+%09%09if (first %3E= 'a' && first %3C= 'z') %7B%0A%09
 %09%09first 
@@ -629,16 +629,17 @@
  - 32);%0A
+%09
 %09%09if (st
@@ -659,24 +659,25 @@
  == 1) %7B%0A%09%09%09
+%09
 return Strin
@@ -696,18 +696,20 @@
 rst);%0A%09%09
+%09
 %7D%0A
+%09
 %09%09return
@@ -742,17 +742,398 @@
 1);%0A
+%09
 %09%7D%0A
-    %0A%09
+%09%09return string;%0A%09%7D%0A%0A%09public static String firstCharToLoweCase(String string) %7B%0A%09%09if (string == null %7C%7C string.length() == 0) %7B%0A%09%09%09return string;%0A%09%09%7D%0A%09%09char first = string.charAt(0);%0A%09%09if (first %3E= 'A' && first %3C= 'Z') %7B%0A%09%09%09first = (char) (first + 32);%0A%09%09%09if (string.length() == 1) %7B%0A%09%09%09%09return String.valueOf(first);%0A%09%09%09%7D%0A%09%09%09return first + string.substring(1);%0A%09%09%7D%0A%09%09return string;%0A%09%7D%0A
 %0A%09/*

优化 StringUtils