content: /*
   * Copyright 1999-2018 Alibaba Group Holding Ltd.
   *
   * 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.
   */
  package com.alibaba.nacos.config.server.utils;
  
  /**
   * 替代common-lang中类，减少依赖
   *
   * @author Nacos
   */
  public class StringUtils {
  
      public static final int INDEX_NOT_FOUND = -1;
  
      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 isNotEmpty(String str) {
          return !StringUtils.isEmpty(str);
      }
  
      public static boolean isEmpty(String str) {
          return str == null || str.length() == 0;
      }
  
      public static String defaultIfEmpty(String str, String defaultStr) {
          return StringUtils.isEmpty(str) ? defaultStr : str;
      }
  
      public static boolean equals(String str1, String str2) {
          return str1 == null ? str2 == null : str1.equals(str2);
      }
  
      public static String substringBetween(String str, String open, String close) {
          if (str == null || open == null || close == null) {
              return null;
          }
          int start = str.indexOf(open);
          if (start != INDEX_NOT_FOUND) {
              int end = str.indexOf(close, start + open.length());
              if (end != INDEX_NOT_FOUND) {
                  return str.substring(start + open.length(), end);
              }
          }
          return null;
      }
  }
  