<commit_before><?php defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    public $CI; // See https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

    public function __construct($rules = array()) {

        parent::__construct($rules);

        $this->CI->load->helper('checkbox');
    }


    // ---------------------------------------------------------------------
    // Bug fixing, see
    // http://www.mahbubblog.com/php/form-validation-callbacks-in-hmvc-in-codeigniter/
    // ---------------------------------------------------------------------

    function run($module = '', $group = '') {

        (is_object($module)) AND $this->CI = &$module;
        return parent::run($group);
    }

}<commit_msg>Reworking some validation rules for UTF-8 compatibility.<commit_after><?php defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    public $CI; // See https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home

    protected $is_utf8;

    public function __construct($rules = array()) {

        parent::__construct($rules);

        $this->is_utf8 = strtolower(config_item('charset')) == 'utf-8';

        $this->CI->load->helper('checkbox');
        $this->CI->load->helper('email');
    }


    // ---------------------------------------------------------------------
    // Bug fixing, see
    // http://www.mahbubblog.com/php/form-validation-callbacks-in-hmvc-in-codeigniter/
    // ---------------------------------------------------------------------

    function run($module = '', $group = '') {

        (is_object($module)) AND $this->CI = &$module;
        return parent::run($group);
    }


    // ---------------------------------------------------------------------
    // Reworked validation rules.
    // ---------------------------------------------------------------------

    public function valid_email($str) {

        return valid_email($str);
    }

    public function min_length($str, $val) {

        if (!is_numeric($val)) {
            return false;
        } else {
            $val = (int) $val;
        }

        return $this->is_utf8
            ? ($val <= UTF8::strlen($str))
            : ($val <= strlen($str));
    }

    public function max_length($str, $val) {

        if (!is_numeric($val)) {
            return false;
        } else {
            $val = (int) $val;
        }

        return $this->is_utf8
            ? ($val >= UTF8::strlen($str))
            : ($val >= strlen($str));
    }

    public function exact_length($str, $val) {

        if (!is_numeric($val)) {
            return false;
        } else {
            $val = (int) $val;
        }

        return $this->is_utf8
            ? (UTF8::strlen($str) === $val)
            : (strlen($str) === $val);
    }

    public function prep_url($str = '') {

        // Added by <NAME>, 08-DEC-2011.
        $str = str_ireplace('http://', 'http://', $str);
        $str = str_ireplace('https://', 'https://', $str);
        //

        if ($str == 'http://' OR $str == '') {
            return '';
        }

        if (substr($str, 0, 7) != 'http://' && substr($str, 0, 8) != 'https://') {
            $str = 'http://'.$str;
        }

        return $str;
    }

    // ---------------------------------------------------------------------

}
{'fraction_non_alphanumeric': 0.29418571015331213, 'fraction_numerical': 0.005785363031530229, 'mean_word_length': 1.3428184281842819, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 21, 'https://': 5, 'lorem ipsum': 0, 'www.': 2, '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': '931456', 'n_tokens_mistral': 980, 'n_tokens_neox': 926, 'n_words': 178}