<commit_before><?php

// Copyright (C) 2010-2016 Combodo SARL
//
//   This file is part of iTop.
//
//   iTop is free software; you can redistribute it and/or modify	
//   it under the terms of the GNU Affero General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   iTop is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Affero General Public License for more details.
//
//   You should have received a copy of the GNU Affero General Public License
//   along with iTop. If not, see <http://www.gnu.org/licenses/>

namespace Combodo\iTop\Form\Validator;

/**
 * Description of Validator
 *
 * @author <NAME> <<EMAIL>>
 */
class Validator
{
	const VALIDATOR_NAME = 'expression';
	const DEFAULT_REGEXP = '';
	const DEFAULT_ERROR_MESSAGE = 'Core:Validator:Default';

	protected $sRegExp;
	protected $sErrorMessage;

	public static function GetName()
	{
		return static::VALIDATOR_NAME;
	}

	/**
	 *
	 * @param Closure $callback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
	 */
	public function __construct($sRegExp = null, $sErrorMessage = null)
	{
		$this->sRegExp = ($sRegExp === null) ? static::DEFAULT_REGEXP : $sRegExp;
		$this->sErrorMessage = ($sErrorMessage === null) ? static::DEFAULT_ERROR_MESSAGE : $sErrorMessage;
		$this->ComputeConstraints();
	}

	/**
	 * Returns the regular expression of the validator.
	 *
	 * @param boolean $bWithSlashes If true, surrounds $sRegExp with '/'. Used with preg_match & co
	 * @return string
	 */
	public function GetRegExp($bWithSlashes = false)
	{
		return ($bWithSlashes) ? '/' . $this->sRegExp . '/' : $this->sRegExp;
	}

	public function GetErrorMessage()
	{
		return $this->sErrorMessage;
	}<commit_msg>#497 Portal : Could not update object due to "Warning: preg_match(): Unknown modifier '/'"<commit_after><?php

// Copyright (C) 2010-2016 Combodo SARL
//
//   This file is part of iTop.
//
//   iTop is free software; you can redistribute it and/or modify	
//   it under the terms of the GNU Affero General Public License as published by
//   the Free Software Foundation, either version 3 of the License, or
//   (at your option) any later version.
//
//   iTop is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU Affero General Public License for more details.
//
//   You should have received a copy of the GNU Affero General Public License
//   along with iTop. If not, see <http://www.gnu.org/licenses/>

namespace Combodo\iTop\Form\Validator;

/**
 * Description of Validator
 *
 * @author <NAME> <<EMAIL>>
 */
class Validator
{
	const VALIDATOR_NAME = 'expression';
	const DEFAULT_REGEXP = '';
	const DEFAULT_ERROR_MESSAGE = 'Core:Validator:Default';

	protected $sRegExp;
	protected $sErrorMessage;

	public static function GetName()
	{
		return static::VALIDATOR_NAME;
	}

	/**
	 *
	 * @param Closure $callback (Used in the $oForm->AddField($sId, ..., function() use ($oManager, $oForm, '...') { ... } ); )
	 */
	public function __construct($sRegExp = null, $sErrorMessage = null)
	{
		$this->sRegExp = ($sRegExp === null) ? static::DEFAULT_REGEXP : $sRegExp;
		$this->sErrorMessage = ($sErrorMessage === null) ? static::DEFAULT_ERROR_MESSAGE : $sErrorMessage;
		$this->ComputeConstraints();
	}

	/**
	 * Returns the regular expression of the validator.
	 *
	 * @param boolean $bWithSlashes If true, surrounds $sRegExp with '/'. Used with preg_match & co
	 * @return string
	 */
	public function GetRegExp($bWithSlashes = false)
	{
		if ($bWithSlashes)
		{
			$this->sRegExp = str_replace('/', '\\/', $this->sRegExp);
		}
		return ($bWithSlashes) ? '/' . $this->sRegExp . '/' : $this->sRegExp;
	}

	public function GetErrorMessage()
	{
		return $this->sErrorMessage;
	}
{'fraction_non_alphanumeric': 0.13159833046894182, 'fraction_numerical': 0.005155904738521974, 'mean_word_length': 3.531701890989989, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 27, 'https://': 0, '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': '3217613', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1254, 'n_words': 419}