upper

@param   string  $str       required
@param   string  $encoding  default UTF-8
@return  string
503468
public static function upper($str, $encoding = null) {
        $encoding or $encoding = \Fuel::$encoding;
        return function_exists('mb_strtoupper') ? mb_strtoupper($str, $encoding) : strtoupper($str);
    }
308591
public static function upperCaseFirst($str, $encoding = null)
    {
        return (string) Stringy::create($str, $encoding)->upperCaseFirst();
    }
84621
public static function hexadecimal(string $str, string $encoding = null) : bool
    {
        return static::matchesPattern($str, '^[[:xdigit:]]*$', $encoding);
    }
1269524
public static function is_utf8($str) {
		if (\is_numeric($str) || \is_bool($str)) {
			return true;
		}
		elseif (\is_string($str)) {
			return (bool) \preg_match('//u', $str);
		}

		return false;
	}
807350
public static function Utf7ImapToUtf8($str)
    {
        if ($str instanceof Horde_Imap_Client_Mailbox) {
            return $str->utf8;
        }

        $str = strval($str);

        /* Try mbstring, if available, which should be faster. Don't use the
         * IMAP utf7_* functions because they are known to be buggy. */
        if (is_null(self::$_mbstring)) {
            self::$_mbstring = extension_loaded('mbstring');
        }
        if (self::$_mbstring) {
            return @mb_convert_encoding($str, 'UTF-8', 'UTF7-IMAP');
        }

        $p = '';
        $ptr = &self::$_index64;

        for ($i = 0, $u7len = strlen($str); $u7len > 0; ++$i, --$u7len) {
            $u7 = $str[$i];
            if ($u7 === '&') {
                $u7 = $str[++$i];
                if (--$u7len && ($u7 === '-')) {
                    $p .= '&';
                    continue;
                }

                $ch = 0;
                $k = 10;
                for (; $u7len > 0; ++$i, --$u7len) {
                    $u7 = $str[$i];

                    if ((ord($u7) & 0x80) || ($b = $ptr[ord($u7)]) === -1) {
                        break;
                    }

                    if ($k > 0) {
                        $ch |= $b << $k;
                        $k -= 6;
                    } else {
                        $ch |= $b >> (-$k);
                        if ($ch < 0x80) {
                            /* Printable US-ASCII */
                            if ((0x20 <= $ch) && ($ch < 0x7f)) {
                                throw new Horde_Imap_Client_Exception(
                                    Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                                    Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                                );
                            }
                            $p .= chr($ch);
                        } else if ($ch < 0x800) {
                            $p .= chr(0xc0 | ($ch >> 6)) .
                                  chr(0x80 | ($ch & 0x3f));
                        } else {
                            $p .= chr(0xe0 | ($ch >> 12)) .
                                  chr(0x80 | (($ch >> 6) & 0x3f)) .
                                  chr(0x80 | ($ch & 0x3f));
                        }

                        $ch = ($b << (16 + $k)) & 0xffff;
                        $k += 10;
                    }
                }

                /* Non-zero or too many extra bits -OR-
                 * Base64 not properly terminated -OR-
                 * Adjacent Base64 sections. */
                if (($ch || ($k < 6)) ||
                    (!$u7len || $u7 !== '-') ||
                    (($u7len > 2) &&
                     ($str[$i + 1] === '&') &&
                     ($str[$i + 2] !== '-'))) {
                    throw new Horde_Imap_Client_Exception(
                        Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                        Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                    );
                }
            } elseif ((ord($u7) < 0x20) || (ord($u7) >= 0x7f)) {
                /* Not printable US-ASCII */
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."),
                    Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION
                );
            } else {
                $p .= $u7;
            }
        }

        return $p;
    }
721852
private function _strtoupper($str)
    {
        $str = html_entity_decode($str, ENT_COMPAT, $this->charset);
        $str = mb_strtoupper($str);
        $str = htmlspecialchars($str, ENT_COMPAT, $this->charset);

        return $str;
    }
703591
public function lower($str, $encoding = null)
	{
		$encoding or $encoding = $this->encoding;

		return function_exists('mb_strtolower')
			? mb_strtolower($str, $encoding)
			: strtolower($str);
	}
1297527
public function toString(string $encoding='utf8')
    {
        $output = '';
        $input = $this->data;

        switch ($encoding) {
            case 'hex':
            foreach ($input as $data)  {
                $hex = dechex($data);

                // pad zero
                if ((strlen($hex) % 2) !== 0) {
                    $hex = '0' . $hex;
                }
                $output .= $hex;
            }
            break;
            case 'ascii':
            foreach ($input as $data)  {
                $output .= chr($data);
            }
            break;
            case 'utf8':
            // $length = count($input);

            // for ($i = array_keys($input)[0]; $i < $length; $i += 3) {
            //     $output .= chr($input[$i]) . chr($input[$i + 1]) . chr($input[$i + 2]);
            // }
            // change to bytes string
            foreach ($input as $data)  {
                $output .= chr($data);
            }
            break;
            default:
            throw new InvalidArgumentException('ToString encoding must be valid.');
            break;
        }
        return $output;
    }
968970
public static function uppercase(string $str, string $encoding = null) : bool
    {
        return static::matchesPattern($str, '^[[:upper:]]*$', $encoding);
    }
253252
public static function fromString($str, $encoding = self::ENCODING){
		
		if(!\is_string($str)){
			throw new \InvalidArgumentException('$str must be a PHP string');
		}
		
		if(!\is_string($encoding)){
			throw new \InvalidArgumentException('$encoding must be a string');
		}
		
		return new static($str, $encoding);
		
	}
1115291
public static function utf16_to_utf8($str)
    {
        $len = strlen($str);
        $dec = '';

        for ($i = 0; $i < $len; $i += 2) {
            $c = ord($str[$i]) << 8 | ord($str[$i + 1]);
            if ($c >= 0x0001 && $c <= 0x007F) {
                $dec .= chr($c);
            }
            else if ($c > 0x07FF) {
                $dec .= chr(0xE0 | (($c >> 12) & 0x0F));
                $dec .= chr(0x80 | (($c >>  6) & 0x3F));
                $dec .= chr(0x80 | (($c >>  0) & 0x3F));
            }
            else {
                $dec .= chr(0xC0 | (($c >>  6) & 0x1F));
                $dec .= chr(0x80 | (($c >>  0) & 0x3F));
            }
        }

        return $dec;
    }
27938
public static function lcfirst($str, $encoding = null)
    {
        $encoding = $encoding === null ? mb_internal_encoding() : $encoding;

        switch (static::strlen($str, $encoding)) {
            case 0:
                return '';
                break;
            case 1:
                return static::strtolower($str, $encoding);
                break;
            default:
                preg_match('/^(.{1})(.*)$/us', $str, $matches);

                return static::strtolower($matches[1], $encoding) . $matches[2];
                break;
        }
    }
205046
public static function pop(string &$str, string $encoding = null)
    {
        $encoding = $encoding ?: mb_internal_encoding();

        $last = mb_substr($str, -1, null, $encoding);
        $str = mb_substr($str, 0, -1, $encoding);

        return $last;
    }
605541
private static function utf8ToHexSequence( $str ) {
		$buf = '';
		foreach ( preg_split( '//u', $str, -1, PREG_SPLIT_NO_EMPTY ) as $cp ) {
			$buf .= sprintf( '%04x ', self::utf8ToCodepoint( $cp ) );
		}

		return rtrim( $buf );
	}
655217
public static function get($encoding) {
        if (isset(self::$aliases[strtolower($encoding)])) {
            return self::$aliases[strtolower($encoding)];
        } else {
            return $encoding;
        }
    }
29094
private static function utf8ToUnicode($str) {
    $new = array();
    $len = iconv_strlen($str);
    for ($n = 0; $n < $len; $n++) {
      $char = iconv_substr($str, $n, 1);
      $new[] = self::uniord($char);
    }
    return $new;
  }
938461
protected function preTransliterate($str)
    {
        $str = $this->escapeLatinCharacters($str);
        $str = mb_convert_kana($str, 'c', 'UTF-8');

        return $str;
    }