content: package com.bihe0832.android.lib.utils;
  
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  /**
   * Created by zixie on 16/11/21.
   */
  public class TextFactoryCore {
  
  
      /**
       * 过滤字符串的空格
       */
      public static String trimSpace(String str) {
          if (null == str) {
              return null;
          }
          String dest = "";
          Pattern p = Pattern.compile("\\s*|\t|\r|\n");
          Matcher m = p.matcher(str);
          dest = m.replaceAll("");
          return dest;
      }
  
      public static Pattern getSafePattern(String key) {
          return Pattern.compile(escapeExprSpecialWord(key));
      }
  
      /**
       * 转义正则特殊字符 （$()*+.[]?\^{},|）
       *
       * @param keyword
       * @return
       */
      public static String escapeExprSpecialWord(String keyword) {
          if (isNotBlank(keyword)) {
              String[] fbsArr = {"\\", "$", "(", ")", "*", "+", ".", "[", "]", "?", "^", "{", "}", "|"};
              for (String key : fbsArr) {
                  if (keyword.contains(key)) {
                      keyword = keyword.replace(key, "\\" + key);
                  }
              }
          }
          return keyword;
      }
  
      public static boolean isBlank(String str) {
          int strLen;
          if (str == null || (strLen = str.length()) == 0) {
              return true;
          }
          for (int i = 0; i < strLen; i++) {
              if ((Character.isWhitespace(str.charAt(i)) == false)) {
                  return false;
              }
          }
          return true;
      }
  
      public static boolean isNotBlank(String str) {
          return !isBlank(str);
      }
  }
  