Code Duplication    Length = 48-48 lines in 2 locations

includes/libraries/protect/AntiXSS/UTF8.php 2 locations

@@ 2962-3009 (lines=48) @@
2959
   *                   <strong>2</strong> for UTF-16BE.
2960
   *                   </p>
2961
   */
2962
  public static function is_utf16($str)
2963
  {
2964
    $str = self::remove_bom($str);
2965
2966
    if (self::is_binary($str) === true) {
2967
2968
      $maybeUTF16LE = 0;
2969
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2970
      if ($test) {
2971
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2972
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2973
        if ($test3 === $test) {
2974
          $strChars = self::count_chars($str, true);
2975
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2976
            if (in_array($test3char, $strChars, true) === true) {
2977
              $maybeUTF16LE++;
2978
            }
2979
          }
2980
        }
2981
      }
2982
2983
      $maybeUTF16BE = 0;
2984
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2985
      if ($test) {
2986
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2987
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2988
        if ($test3 === $test) {
2989
          $strChars = self::count_chars($str, true);
2990
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2991
            if (in_array($test3char, $strChars, true) === true) {
2992
              $maybeUTF16BE++;
2993
            }
2994
          }
2995
        }
2996
      }
2997
2998
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2999
        if ($maybeUTF16LE > $maybeUTF16BE) {
3000
          return 1;
3001
        }
3002
3003
        return 2;
3004
      }
3005
3006
    }
3007
3008
    return false;
3009
  }
3010
3011
  /**
3012
   * Check if the string is UTF-32.
@@ 3022-3069 (lines=48) @@
3019
   *                   <strong>2</strong> for UTF-32BE.
3020
   *                   </p>
3021
   */
3022
  public static function is_utf32($str)
3023
  {
3024
    $str = self::remove_bom($str);
3025
3026
    if (self::is_binary($str) === true) {
3027
3028
      $maybeUTF32LE = 0;
3029
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
3030
      if ($test) {
3031
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
3032
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
3033
        if ($test3 === $test) {
3034
          $strChars = self::count_chars($str, true);
3035
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3036
            if (in_array($test3char, $strChars, true) === true) {
3037
              $maybeUTF32LE++;
3038
            }
3039
          }
3040
        }
3041
      }
3042
3043
      $maybeUTF32BE = 0;
3044
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
3045
      if ($test) {
3046
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
3047
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
3048
        if ($test3 === $test) {
3049
          $strChars = self::count_chars($str, true);
3050
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3051
            if (in_array($test3char, $strChars, true) === true) {
3052
              $maybeUTF32BE++;
3053
            }
3054
          }
3055
        }
3056
      }
3057
3058
      if ($maybeUTF32BE !== $maybeUTF32LE) {
3059
        if ($maybeUTF32LE > $maybeUTF32BE) {
3060
          return 1;
3061
        }
3062
3063
        return 2;
3064
      }
3065
3066
    }
3067
3068
    return false;
3069
  }
3070
3071
  /**
3072
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.