<commit_before><?php

namespace Kunstmaan\NodeBundle\Helper;

/**
 * Sulgifier is a helper to slugify a certain string
 */
class Slugifier
{
    /**
     * Slugify a string
     *
     * @param string $text    Text to slugify
     * @param string $default Default return value (override when slugify would return an empty string)
     *
     * @return string
     */
    public static function slugify($text, $default = 'n-a')
    {
        $text = preg_replace('#[^\\pL\d\/]+#u', '-', $text); // replace non letter or digits by -
        $text = trim($text, '-'); //trim

        // transliterate
        if (function_exists('iconv')) {
            $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
        }

        $text = strtolower($text); // lowercase
        $text = preg_replace('#[^-\w\/]+#', '', $text); // remove unwanted characters

        if (empty($text)) {
            return empty($default) ? '' : $default;
        }<commit_msg>fix slugifier: iconv doesn't work as aspected when locale is C or POSIX, see http://www.php.net/manual/en/function.iconv.php<commit_after><?php

namespace Kunstmaan\NodeBundle\Helper;

/**
 * Sulgifier is a helper to slugify a certain string
 */
class Slugifier
{
    /**
     * Slugify a string
     *
     * @param string $text    Text to slugify
     * @param string $default Default return value (override when slugify would return an empty string)
     *
     * @return string
     */
    public static function slugify($text, $default = 'n-a')
    {

        $text = preg_replace('#[^\\pL\d\/]+#u', '-', $text); // replace non letter or digits by -
        $text = trim($text, '-'); //trim

        // transliterate
        if (function_exists('iconv')) {
            $previouslocale = setlocale(LC_CTYPE, 0);
            setlocale(LC_CTYPE, 'en_US.UTF8');
            $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
            setlocale(LC_CTYPE, $previouslocale);
        }

        $text = strtolower($text); // lowercase
        $text = preg_replace('#[^-\w\/]+#', '', $text); // remove unwanted characters

        if (empty($text)) {
            return empty($default) ? '' : $default;
        }
{'fraction_non_alphanumeric': 0.15857605177993528, 'fraction_numerical': 0.0018492834026814608, 'mean_word_length': 2.2590361445783134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '7141369', 'n_tokens_mistral': 683, 'n_tokens_neox': 652, 'n_words': 177}