Converts charset of search criteria string

@param  string  $str          Search string
@param  string  $charset      Original charset
@param  string  $dest_charset Destination charset (default US-ASCII)

@return string  Search string
197724
public static function convert_criteria($str, $charset, $dest_charset='US-ASCII')
    {
        // convert strings to US_ASCII
        if (preg_match_all('/\{([0-9]+)\}\r\n/', $str, $matches, PREG_OFFSET_CAPTURE)) {
            $last = 0; $res = '';
            foreach ($matches[1] as $m) {
                $string_offset = $m[1] + strlen($m[0]) + 4; // {}\r\n
                $string = substr($str, $string_offset - 1, $m[0]);
                $string = rcube_charset::convert($string, $charset, $dest_charset);

                if ($string === false || !strlen($string)) {
                    continue;
                }

                $res .= substr($str, $last, $m[1] - $last - 1) . rcube_imap_generic::escape($string);
                $last = $m[0] + $string_offset - 1;
            }

            if ($last < strlen($str)) {
                $res .= substr($str, $last, strlen($str)-$last);
            }
        }
        // strings for conversion not found
        else {
            $res = $str;
        }

        return $res;
    }
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;
    }
151642
public static function strtolower($text, $charset='utf-8') {
        $charset = self::parse_charset($charset);

        if ($charset === 'utf-8' and function_exists('mb_strtolower')) {
            return mb_strtolower($text, 'UTF-8');
        }

        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->conv_case($charset, (string)$text, 'toLower');
        error_reporting($oldlevel);

        return $result;
    }
782214
function _filter_uri($str) {
		if ($str != '' && $this->permitted_uri_chars != '' && $this->enable_query_strings == FALSE) {
			// preg_quote() in PHP 5.3 escapes -, so the str_replace() and addition of - to preg_quote() is to maintain backwards
			// compatibility as many are unaware of how characters in the permitted_uri_chars will be parsed as a regex pattern
			if (!preg_match("|^[" . str_replace(array ('\\-','\-' ), '-', preg_quote($this->permitted_uri_chars, '-')) . "]+$|i", $str)) {
				show_error('The URI you submitted has disallowed characters.', 400);
			}
		}

		// Convert programatic characters to entities
		$bad=array ('$','(',')','%28','%29' );
		$good=array ('&#36;','&#40;','&#41;','&#40;','&#41;' );

		return str_replace($bad, $good, $str);
	}
503266
public static function htmlentities($str = '', $encodeTags = true, $isXml = false, $charset = null)
    {
        $debug = \bdk\Debug::getInstance();
        $dbWas = $debug->setCfg('collect', false);
        $debug->groupCollapsed(__FUNCTION__);
        $return = '';
        $charsetsTry = array('UTF-8','ISO-8859-1');
        $debug->log('charset', $charset);
        if (is_null($charset) && extension_loaded('mbstring')) {
            $charset = mb_detect_encoding($str, mb_detect_order(), true);
            $debug->log('charset detected', $charset);
        }
        if ($charset) {
            $charset = self::getCharset($charset);
            if ($charset == 'UTF-8' && !Str::isUtf8($str)) {
                $charset = null;
            }
        }
        if ($charset) {
            #$debug->log('will try charset '.$charset.' first');
            array_unshift($charsetsTry, $charset);
            $charsetsTry = array_unique($charsetsTry);
        }
        $debug->log('charsetsTry', implode(', ', $charsetsTry));
        $return = self::htmlentitiesApply($str, $encodeTags, $isXml, $charsetsTry);
        #$debug->log('return', $return);
        $debug->groupEnd();
        $debug->setCfg('collect', $dbWas);
        return $return;
    }
406830
public static function convertCamel($str, $separators = ['_', '-'], $delimiter = '')
	{
		$str = ucwords(str_replace($separators, ' ', $str));

		return str_replace(' ', $delimiter, $str);
	}
661090
public static function convertEncoding( $str, $to_encoding = NULL, $from_encoding = NULL )
    {
        if ( is_string($str) && $to_encoding ){
            // エンコードあり
            return mb_convert_encoding($str,$to_encoding, $from_encoding);
        }
        // エンコード無し
        return $str;
    }
1223318
protected static function _fallbackToAscii($str)
    {
        if (!isset(self::$_map)) {
            self::$_map = array(
                'À' => 'A',
                'Á' => 'A',
                'Â' => 'A',
                'Ã' => 'A',
                'Ä' => 'A',
                'Å' => 'A',
                'Æ' => 'AE',
                'à' => 'a',
                'á' => 'a',
                'â' => 'a',
                'ã' => 'a',
                'ä' => 'a',
                'å' => 'a',
                'æ' => 'ae',
                'Þ' => 'TH',
                'þ' => 'th',
                'Ç' => 'C',
                'ç' => 'c',
                'Ð' => 'D',
                'ð' => 'd',
                'È' => 'E',
                'É' => 'E',
                'Ê' => 'E',
                'Ë' => 'E',
                'è' => 'e',
                'é' => 'e',
                'ê' => 'e',
                'ë' => 'e',
                'ƒ' => 'f',
                'Ì' => 'I',
                'Í' => 'I',
                'Î' => 'I',
                'Ï' => 'I',
                'ì' => 'i',
                'í' => 'i',
                'î' => 'i',
                'ï' => 'i',
                'Ñ' => 'N',
                'ñ' => 'n',
                'Ò' => 'O',
                'Ó' => 'O',
                'Ô' => 'O',
                'Õ' => 'O',
                'Ö' => 'O',
                'Ø' => 'O',
                'ò' => 'o',
                'ó' => 'o',
                'ô' => 'o',
                'õ' => 'o',
                'ö' => 'o',
                'ø' => 'o',
                'Š' => 'S',
                'ẞ' => 'SS',
                'ß' => 'ss',
                'š' => 's',
                'ś' => 's',
                'Ù' => 'U',
                'Ú' => 'U',
                'Û' => 'U',
                'Ü' => 'U',
                'ù' => 'u',
                'ú' => 'u',
                'û' => 'u',
                'Ý' => 'Y',
                'ý' => 'y',
                'ÿ' => 'y',
                'Ž' => 'Z',
                'ž' => 'z'
            );
        }

        /* This should never return false. */
        return strtr(strval($str), self::$_map);
    }
993972
public function headerCharset($charset = null)
    {
        deprecationWarning('Email::headerCharset() is deprecated. Use Email::setHeaderCharset() or Email::getHeaderCharset() instead.');

        if ($charset === null) {
            return $this->getHeaderCharset();
        }

        $this->setHeaderCharset($charset);

        return $this->headerCharset;
    }
835641
static public function fromCamel($str) {
      $str[0] = strtolower($str[0]);
      return preg_replace_callback('/([A-Z])/', function($char) {return "_" . strtolower($char[1]);}, $str);
  }
654323
public static function utf8_to_entities($str, $dec=false, $nonnum=false) {
        static $callback = null ;

        if ($nonnum) {
            $str = self::entities_to_utf8($str, true);
        }

        // Avoid some notices from Typo3 code
        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->utf8_to_entities((string)$str);
        error_reporting($oldlevel);

        if ($dec) {
            if (!$callback) {
                $callback = function($matches) {
                    return '&#' . hexdec($matches[1]) . ';';
                };
            }
            $result = preg_replace_callback('/&#x([0-9a-f]+);/i', $callback, $result);
        }

        return $result;
    }
1020894
public static String decodeStr(String source, String charset) {
		return StrUtil.str(decode(source), charset);
	}
855826
public static function strlen($text, $charset='utf-8') {
        $charset = self::parse_charset($charset);

        if ($charset === 'utf-8') {
            if (function_exists('mb_strlen')) {
                return mb_strlen($text, 'UTF-8');
            } else {
                return iconv_strlen($text, 'UTF-8');
            }
        }

        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->strlen($charset, (string)$text);
        error_reporting($oldlevel);

        return $result;
    }
346919
public static function mapTo( $charset )
    {
        $lowerCharset = strtolower( $charset );
        return isset( self::$mapping[$lowerCharset] ) ? self::$mapping[$lowerCharset] : $charset;
    }
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;
  }
994282
private static function utf8_to_unicode( &$str )
    {
        $unicode = array();
        $values = array();
        $looking_for = 1;

        for ($i = 0; $i < strlen( $str ); $i++ ) {
            $this_value = ord( $str[ $i ] );
            if ( $this_value < 128 ) $unicode[] = $this_value;
            else {
                if ( count( $values ) == 0 ) $looking_for = ( $this_value < 224 ) ? 2 : 3;
                $values[] = $this_value;
                if ( count( $values ) == $looking_for ) {
                    $number = ( $looking_for == 3 ) ?
                        ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ):
                        ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
                    $unicode[] = $number;
                    $values = array();
                    $looking_for = 1;
                }
            }
        }
        return $unicode;
    }
82265
private function _strtoupper($str)
    {
        $str = html_entity_decode($str, ENT_COMPAT);

        if (function_exists('mb_strtoupper')) {
            $str = mb_strtoupper($str, 'UTF-8');
        } else {
            $str = strtoupper($str);
        }

        $str = htmlspecialchars($str, ENT_COMPAT);

        return $str;
    }