Returns true if the passed string is valid in the $charset encoding.

Either uses mb_check_encoding, or iconv if it's not a supported mb
encoding.

@param type $str
@param type $charset
773092
public function checkEncoding($str, $charset)
    {
        $mb = $this->getMbCharset($charset);
        if ($mb !== false) {
            return mb_check_encoding($str, $mb);
        }
        $ic = $this->getIconvAlias($charset);
        return (@iconv($ic, $ic, $str) !== false);
    }
1097657
public function setCharset($charset)
    {
        if (GenericValidator::validateCharset($charset)) {
            $this->charset = $charset;
            return true;
        }
        return false;
    }
863003
public static final String encode(String str, Charset charset)
    {
        return encode(str, charset.name());
    }
100025
@Override
    public boolean isCharsetSupported(String charset) {
        if (null == charset) {
            return false;
        }
        Boolean supported = this.supportedEncodingsCache.get(charset);
        if (supported != null) {
            return supported.booleanValue();
        }
        try {
            new String(TEST_CHAR, charset);
            supported = Boolean.TRUE;
        } catch (UnsupportedEncodingException e) {
            supported = Boolean.FALSE;
        }
        this.supportedEncodingsCache.put(charset, supported);
        return supported.booleanValue();
    }
608651
public static function alphabetic(string $str, string $encoding = null) : bool
    {
        return static::matchesPattern($str, '^[[:alpha:]]*$', $encoding);
    }
102203
public static function isRoman(string $str) : bool
    {
        $str    = strtoupper(Parser::replaceRoman($str));
        $ary    = Parser::strToArray($str);
        $result = true;
        foreach ($ary as $key => $value) {
            $code = Mbstring::mb_ord($value);
            if ($code >= 97 && 122) {
                $value = strtoupper($value);
            }
            if (array_key_exists($value, self::$romans)) {
                continue;
            } else {
                $result = false;
                break;
            }
        }
        if ($result) {
            foreach (self::$romans as $key => $value) {
                while (mb_strpos($str, $key) === 0) {
                    $str = mb_substr($str, strlen($key));
                }
            }
            $result = mb_strlen($str) === 0;
        }
        return $result;
    }
965134
public static void setCharsetEncoding(String charset) {
		try {

			String test = "123456890";
			test.getBytes(charset);
			CHARSET_ENCODING = charset;
			encode = true;
		} catch (UnsupportedEncodingException ex) {
			// Reset the encoding to default
			CHARSET_ENCODING = "";
			encode = false;
		}
	}
84621
public static function hexadecimal(string $str, string $encoding = null) : bool
    {
        return static::matchesPattern($str, '^[[:xdigit:]]*$', $encoding);
    }
162422
public function charset($charset, $convert = true)
    {
        $oldcharset = $this->_charset;
        $this->_charset = Horde_String::upper($charset);

        if (!$convert || ($oldcharset == $this->_charset)) {
            return;
        }

        foreach (array('and', 'or') as $item) {
            if (isset($this->_search[$item])) {
                foreach ($this->_search[$item] as &$val) {
                    $val->charset($charset, $convert);
                }
            }
        }

        foreach (array('header', 'text') as $item) {
            if (isset($this->_search[$item])) {
                foreach ($this->_search[$item] as $key => $val) {
                    $new_val = Horde_String::convertCharset($val['text'], $oldcharset, $this->_charset);
                    if (Horde_String::convertCharset($new_val, $this->_charset, $oldcharset) != $val['text']) {
                        throw new Horde_Imap_Client_Exception_SearchCharset($this->_charset);
                    }
                    $this->_search[$item][$key]['text'] = $new_val;
                }
            }
        }
    }
1185957
private function strContainsFromCharset($sStr, $sCharset)
    {
        if (empty($this->aCharset[$sCharset])) {
            return true;
        }

        return preg_match('/[' . preg_quote($this->aCharset[$sCharset], '/') . ']/', $sStr);
    }
1059756
public function isAcceptCharset($charset)
    {
        if ($this->hasHeader('Accept-Charset')) {
            return $this->isAccept($this->getHeader('Accept-Charset'), $charset);
        }
        return false;
    }
562273
static function is_utf8($str)
    {
        $c=0; $b=0;
        $bits=0;
        $len=strlen($str);
        for($i=0; $i<$len; $i++)
        {
            $c=ord($str[$i]);
            if($c > 128)
            {
                if(($c >= 254)) return false;
                elseif($c >= 252) $bits=6;
                elseif($c >= 248) $bits=5;
                elseif($c >= 240) $bits=4;
                elseif($c >= 224) $bits=3;
                elseif($c >= 192) $bits=2;
                else return false;
                if(($i+$bits) > $len) return false;
                while($bits > 1)
                {
                    $i++;
                    $b=ord($str[$i]);
                    if($b < 128 || $b > 191) return false;
                    $bits--;
                }
            }
        }
        return true;
    }
1083113
public function detect($str, $encodingList = ['UTF-8', 'CP1252'])
	{
		$charset = mb_detect_encoding($str, $encodingList);
		if ($charset === false)
		{
			// could not detect charset
			return false;
		}

		$this->from = $charset;
		return true;
	}
722710
public static function ensureUTF8($str) {
		if($str == NULL) {
			return NULL;
		}
		$enc = mb_detect_encoding($str, array('ISO-8859-1', 'ISO-8859-15', 'UTF-8', 'ASCII'));
		if($enc !== FALSE) {
			if($enc == 'ISO-8859-1' || $enc == 'ISO-8859-15') {
				$str = mb_convert_encoding($str, 'UTF-8', $enc);
			}
		}
		return $str;
	}
1217866
public static function utf7_to_utf8($str)
    {
        $Index_64 = array(
            0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
            0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
            0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0,
            1,1,1,1, 1,1,1,1, 1,1,0,0, 0,0,0,0,
            0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
            1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
            0,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1,
            1,1,1,1, 1,1,1,1, 1,1,1,0, 0,0,0,0,
        );

        $u7len = strlen($str);
        $str   = strval($str);
        $res   = '';

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

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

                    if (!$Index_64[ord($u7)]) {
                        break;
                    }

                    $ch .= $u7;
                }

                if ($ch == '') {
                    if ($u7 == '-') {
                        $res .= '+';
                    }

                    continue;
                }

                $res .= self::utf16_to_utf8(base64_decode($ch));
            }
            else {
                $res .= $u7;
            }
        }

        return $res;
    }
1043911
public static function ucwords($str, $encoding = 'UTF-8') {
        $encoding or $encoding = 'UTF-8';
        return function_exists('mb_convert_case') ? mb_convert_case($str, MB_CASE_TITLE, $encoding) : ucwords(strtolower($str));
    }
1254951
private static function isValidXmlTagName($str)
    {
        static $validTagRegex = null;

        if ($validTagRegex === null) {
            $invalidTagChars = "!\"#$%&'()*+,\\/;<=>?@[\\]\\\\^`{|}~";
            $invalidTagStartChars = $invalidTagChars . "\\-.0123456789";
            $validTagRegex = "/^[^" . $invalidTagStartChars . "][^" . $invalidTagChars . "]*$/";
        }

        $result = preg_match($validTagRegex, $str);
        return !empty($result);
    }