<commit_before><?php

class dmString extends sfInflector
{
  const ENCODING_SEPARATOR = '__DM_SPLIT__';

  protected static
    $camelizeCache = array();

  public static function escape($text, $quoteStyle = ENT_QUOTES)
  {
    return htmlspecialchars($text, $quoteStyle, 'UTF-8');
  }
  
  /**
   * Clean dirty strings
   */
  public static function unixify($text)
  {
    return strtr($text, array(
        "\r"      => ''
      , "\t"      => '  '
      , "&#8217;" => "'"
      , '“'       => '&lquot;'
      , '”'       => '&rquot;'
      , '®'       => '&reg;'
      , '‘'       => '&lsquo;'
      , '’'       => '&rsquo;'
    ));
  }

  /**
   * Adds a final 's'
   */
  public static function pluralize($word)
  {
    return $word[strlen($word)-1] == 's' ? $word : $word.'s';
  }

  public static function pluralizeNb($word, $nb, $specialPlural = false)
  {
    if($specialPlural)
    {
      return $nb > 1 ? $specialPlural : $word;
    }
    else
    {
      return $nb > 1 ? self::pluralize($word) : $word;
    }
  }

  /**
   * Returns a module formatted string
   * ModuleName => moduleName
   * module_name => moduleName
   */
  public static function modulize($something)
  {
    if ($model = self::camelize($something))
    {
      $model[0] = strtolower($model[0]);
    }
    
    return $model;
  }

  /**
   * Returns a camelized string from a lower case and underscored string by
   * upper-casing each letter preceded by an underscore.
   * modelName => ModelName
   * model_name => ModelName
   */
  public static function camelize($something)
  {
    if (is_object($something))
    {
      if ($something instanceof dmModule)
      {
        throw new dmException('dmModule should not be camelized');
      }
      
      return get_class($something);
    }

    if (!is_string($something))
    {
      if (empty($something))
      {
        return '';
      }
      
      throw new dmException('Can not camelize '.$something);
    }
    
    if (isset(self::$camelizeCache[$something]))
    {
      return self::$camelizeCache[$something];
    }

    return self::$camelizeCache[$something] = preg_replace(
      '/_(\w)/e',
      "strtoupper('\\1')",
      ucfirst($something)
    );
  }

  public static function humanize($text)
  {
    return parent::humanize(self::underscore($text));
  }

  /**
   * Transform any text into a valid slug
   * @return string slug
   */
  public static function slugify($text, $preserveSlashes = false)
  {<commit_msg>change preg_replace to preg_replace_callback<commit_after><?php

class dmString extends sfInflector
{
  const ENCODING_SEPARATOR = '__DM_SPLIT__';

  protected static
    $camelizeCache = array();

  public static function escape($text, $quoteStyle = ENT_QUOTES)
  {
    return htmlspecialchars($text, $quoteStyle, 'UTF-8');
  }
  
  /**
   * Clean dirty strings
   */
  public static function unixify($text)
  {
    return strtr($text, array(
        "\r"      => ''
      , "\t"      => '  '
      , "&#8217;" => "'"
      , '“'       => '&lquot;'
      , '”'       => '&rquot;'
      , '®'       => '&reg;'
      , '‘'       => '&lsquo;'
      , '’'       => '&rsquo;'
    ));
  }

  /**
   * Adds a final 's'
   */
  public static function pluralize($word)
  {
    return $word[strlen($word)-1] == 's' ? $word : $word.'s';
  }

  public static function pluralizeNb($word, $nb, $specialPlural = false)
  {
    if($specialPlural)
    {
      return $nb > 1 ? $specialPlural : $word;
    }
    else
    {
      return $nb > 1 ? self::pluralize($word) : $word;
    }
  }

  /**
   * Returns a module formatted string
   * ModuleName => moduleName
   * module_name => moduleName
   */
  public static function modulize($something)
  {
    if ($model = self::camelize($something))
    {
      $model[0] = strtolower($model[0]);
    }
    
    return $model;
  }

  /**
   * Returns a camelized string from a lower case and underscored string by
   * upper-casing each letter preceded by an underscore.
   * modelName => ModelName
   * model_name => ModelName
   */
  public static function camelize($something)
  {
    if (is_object($something))
    {
      if ($something instanceof dmModule)
      {
        throw new dmException('dmModule should not be camelized');
      }
      
      return get_class($something);
    }

    if (!is_string($something))
    {
      if (empty($something))
      {
        return '';
      }
      
      throw new dmException('Can not camelize '.$something);
    }
    
    if (isset(self::$camelizeCache[$something]))
    {
      return self::$camelizeCache[$something];
    }

    return self::$camelizeCache[$something] = preg_replace_callback(
      '/_(\w)/',
      function($m) {
        return strtoupper($m[1]);
      },
      ucfirst($something)
    );
  }

  public static function humanize($text)
  {
    return parent::humanize(self::underscore($text));
  }

  /**
   * Transform any text into a valid slug
   * @return string slug
   */
  public static function slugify($text, $preserveSlashes = false)
  {
{'fraction_non_alphanumeric': 0.1511720301946762, 'fraction_numerical': 0.004370282081843465, 'mean_word_length': 2.3081471747700393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4314176', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1658, 'n_words': 361}