<commit_before><?php

/**
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2012, webtischlerei <http://www.webtischlerei.de>
 * 
 * @category Moraso
 * @package Util
 * @subpackage String
 * 
 * @since 1.2.4-1
 */
class Moraso_Util_String {

    /**
     * The perfect PHP clean url generator
     * 
     * Here is an example:
     * <pre><code>
     * <?php
     * $slug = Moraso_Util_String::slugify("Hällö Foo");
     * 
     * echo $slug; // haelloe-foo
     * ?>
     * </code></pre>
     * 
     * @example http://www.webtischlerei.de/moraso-cms/doc/functions/util/string/slugify.html How to use this function
     * @since 1.2.4-1
     * @param string $string String to slugify
     * @return string $slug Slugified string
     */
    public static function slugify($string) {

        $in_charset = mb_detect_encoding($string);
        $out_charset = 'ASCII//TRANSLIT';

        $slug_trim = trim($string);

        $slug_tolower = strtolower($slug_trim);

        $specialCharactersSearch = array('ä', 'ö', 'ü', 'à', 'ç', 'è', 'é', 'ê', 'ß');
        $specialCharactersReplace = array('ae', 'ou', 'ue', 'a', 'c', 'e', 'e', 'e', 'ss');

        $slug_specialCharactersReplaced = str_replace($specialCharactersSearch, $specialCharactersReplace, $slug_tolower);

        $slug_iconv = iconv($in_charset, $out_charset, $slug_specialCharactersReplaced);

        $slug_whitespace = preg_replace("%[^-/+|\w ]%", '', $slug_iconv);

        return preg_replace("/[\/_|+ -]+/", '-', $slug_whitespace);
    }

    /**
     * Creates a random string
     * 
     * Here is an example:
     * <pre><code>
     * <?php
     * $random = Moraso_Util_String::random(8, 'avd75FGW');
     * 
     * echo $random; // v5GFav7W
     * ?>
     * </code></pre>
     * 
     * @example http://www.webtischlerei.de/moraso-cms/doc/functions/util/string/random.html How to use this function
     * @since 1.2.5-1
     * @param int $length Length of random string
     * @return string $character Characters to create random string
     */
    public static function random($length = 16, $character = null) {

        if (empty($character)) {
            $character = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        }
        $character_count = strlen($character);

        $random = '';
        for ($i = 0; $i < $length; $i++) {
            $random .= $character[mt_rand(0, $character_count - 1)];
        }

        return $random;
    }

}<commit_msg>Umlaute-Bug entfernt<commit_after><?php

/**
 * @author <NAME> <<EMAIL>>
 * @copyright (c) 2012, webtischlerei <http://www.webtischlerei.de>
 * 
 * @category Moraso
 * @package Util
 * @subpackage String
 * 
 * @since 1.2.4-1
 */
class Moraso_Util_String {

    /**
     * The perfect PHP clean url generator
     * 
     * Here is an example:
     * <pre><code>
     * <?php
     * $slug = Moraso_Util_String::slugify("Hällö Foo");
     * 
     * echo $slug; // haelloe-foo
     * ?>
     * </code></pre>
     * 
     * @example http://www.webtischlerei.de/moraso-cms/doc/functions/util/string/slugify.html How to use this function
     * @since 1.2.4-1
     * @param string $string String to slugify
     * @return string $slug Slugified string
     */
    public static function slugify($string) {

        $in_charset = mb_detect_encoding($string);
        $out_charset = 'ASCII//TRANSLIT';

        $slug_trim = trim($string);

        $slug_tolower = mb_strtolower($slug_trim, 'UTF-8');

        $specialCharactersSearch = array('ä', 'ö', 'ü', 'à', 'ç', 'è', 'é', 'ê', 'ß');
        $specialCharactersReplace = array('ae', 'ou', 'ue', 'a', 'c', 'e', 'e', 'e', 'ss');

        $slug_specialCharactersReplaced = str_replace($specialCharactersSearch, $specialCharactersReplace, $slug_tolower);

        $slug_iconv = iconv($in_charset, $out_charset, $slug_specialCharactersReplaced);

        $slug_whitespace = preg_replace("%[^-/+|\w ]%", '', $slug_iconv);

        return preg_replace("/[\/_|+ -]+/", '-', $slug_whitespace);
    }

    /**
     * Creates a random string
     * 
     * Here is an example:
     * <pre><code>
     * <?php
     * $random = Moraso_Util_String::random(8, 'avd75FGW');
     * 
     * echo $random; // v5GFav7W
     * ?>
     * </code></pre>
     * 
     * @example http://www.webtischlerei.de/moraso-cms/doc/functions/util/string/random.html How to use this function
     * @since 1.2.5-1
     * @param int $length Length of random string
     * @return string $character Characters to create random string
     */
    public static function random($length = 16, $character = null) {

        if (empty($character)) {
            $character = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
        }
        $character_count = strlen($character);

        $random = '';
        for ($i = 0; $i < $length; $i++) {
            $random .= $character[mt_rand(0, $character_count - 1)];
        }

        return $random;
    }

}
{'fraction_non_alphanumeric': 0.16379833974488764, 'fraction_numerical': 0.014780319902814336, 'mean_word_length': 2.546302943287868, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '219989', 'n_tokens_mistral': 1782, 'n_tokens_neox': 1698, 'n_words': 344}