/*
 * ====================================================================
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 *
 */

package org.apache.hc.core5.util;

/**
 * @since 4.3
 */
public final class TextUtils {

    private TextUtils() {
        // Do not allow utility class to be instantiated.
    }

    /**
     * Returns true if the parameter is null or of zero length
     */
    public static boolean isEmpty(final CharSequence s) {
        if (s == null) {
            return true;
        }
        return s.length() == 0;
    }

    /**
     * Returns true if the parameter is null or contains only whitespace
     */
    public static boolean isBlank(final CharSequence s) {
        if (s == null) {
            return true;
        }
        for (int i = 0; i < s.length(); i++) {
            if (!Character.isWhitespace(s.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * @since 4.4
     */
    public static boolean containsBlanks(final CharSequence s) {
        if (s == null) {
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            if (Character.isWhitespace(s.charAt(i))) {
                return true;
            }
        }
        return false;
    }

    public static String toHexString(final byte[] bytes) {
        if (bytes == null) {
            return null;
        }
        final StringBuilder buffer = new StringBuilder();
        for (int i = 0; i < bytes.length; i++) {
            final byte b = bytes[i];
            if (b < 16) {
                buffer.append('0');
            }
            buffer.append(Integer.toHexString(b & 0xff));
        }
        return buffer.toString();
    }

}

@@ -1507,114 +1507,530 @@
     
-if 
+return length
 (s
+)
  == 
-null) %7B
+0;%0A    %7D%0A%0A    /**%0A     * %3Cp%3EChecks if a CharSequence is empty (%22%22), null or whitespace only.%3C/p%3E
 %0A     
+*%0A
      
-  return
+* %3Cp%3EWhitespace is defined by %7B@link Character#isWhitespace(char)%7D.%3C/p%3E%0A     *%0A     * %3Cpre%3E%0A     * TextUtils.isBlank(null)      =
  true
-;
 %0A     
-   %7D%0A        return s.length() == 0;%0A    %7D%0A%0A    /**
+* TextUtils.isBlank(%22%22)        = true%0A     * TextUtils.isBlank(%22 %22)       = true%0A     * TextUtils.isBlank(%22abg%22)     = false%0A     * TextUtils.isBlank(%22  abg  %22) = false%0A     * %3C/pre%3E%0A     *%0A     * @param s  the CharSequence to check, may be null
 %0A     * 
 Retu
@@ -2025,36 +2025,44 @@
 %0A     * 
-R
+@r
 eturn
-s
+ %7B@code
  true
+%7D
  if the 
 paramete
@@ -2057,42 +2057,38 @@
 the 
-parameter is null or contains only
+CharSequence is null, empty or
  whi
@@ -2094,16 +2094,21 @@
 itespace
+ only
 %0A     */
@@ -2170,37 +2170,77 @@
 ) %7B%0A        
-if (s == null
+final int strLen = length(s);%0A        if (strLen == 0
 ) %7B%0A        
@@ -2291,33 +2291,29 @@
 i = 0; i %3C s
-.length()
+trLen
 ; i++) %7B%0A   
@@ -2439,32 +2439,436 @@
 rn true;%0A    %7D%0A%0A
+    /**%0A     * Gets a CharSequence length or %7B@code 0%7D if the CharSequence is%0A     * %7B@code null%7D.%0A     *%0A     * @param cs%0A     *            a CharSequence or %7B@code null%7D%0A     * @return CharSequence length or %7B@code 0%7D if the CharSequence is%0A     *         %7B@code null%7D.%0A     * @since 5.1%0A     */%0A    public static int length(final CharSequence cs) %7B%0A        return cs == null ? 0 : cs.length();%0A    %7D%0A%0A
     /**%0A     * @
@@ -2962,21 +2962,61 @@
     
-if (s == null
+final int strLen = length(s);%0A        if (strLen == 0
 ) %7B%0A

improve Text Utils methods