<commit_before><?php

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version
 * This program 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 General Public License for more details
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * This class represents a buffer, which contains a temporary text content;
 * This is also the concrete subject of the Obsever Design Pattern
 * 
 * @author <NAME> & <NAME>
 * @category Observer
 * @package observer
 * @version 0.1
 */

class Buffer
{

	/**
	 * The begining of a selection.
	 * @var selectionStart
	 * @access private
	 * @type Integer
	 */
	private $_selectionStart;
	
	/**
	 * The end of a selection
	 * @var selectionEnd
	 * @access private
	 * @type Integer
	 */
	private $selectionEnd;
	
	/**
	 * The constructor of the class
	 * @return void
	 */
	public function __construct()
	{
		
	}
	
	/**
	 * Get the current text
	 * @return the current text
	 * @access public
	 */
	public function getText()
	{
		
	}
	
	/**
	 * Set the content of the current text
	 * @return void
	 * @param String $text the new content
	 * @access public
	 */
	public function setText(String $text)
	{
		
	}
	
	/**
	 * Set the begining of the selection
	 * @return void
	 * @param Integer $val the begining of the selection
	 * @access public
	 */
	public function setSelectionStart($val)
	{
		$this->_selectionStart = $val;
	}
	
	/**
	 * Set the end of the selection
	 * @return void
	 * @param Integer $val the end of the selection
	 * @access public
	 */
	public function setSelectionEnd($val)
	{
		$this->_selectionEnd = $val;
	}
	
	/**
	 * Insert a character into the buffer
	 * @return void
	 * @access public
	 */
	public function insert()
	{
		
	}
	
	/**
	 * Set a text content into the clipboard
	 * @return void
	 * @access private
	 */
	private function _setTextIntoClipBoard()
	{
		
	}
	
	/**
	 * Get a text content from the clipboard
	 * @return String the text content from the clipboard
	 */
	private function _getTextFromClipBoard()
	{
		
	}
	
	/** Command methods **/
	
	/**
	 * Copy the current selection into clipboard
	 * @return void
	 * @access public
	 */
	public function copyText()
	{
		
	}
	
	/**
	 * Cut the current selection into clipboard
	 * @return void
	 * @access public
	 */
	public function cutText()
	{
		
	}
	
	/**
	 * Paste the content of the clipboard into the buffer
	 * @return void
	 * @access public
	 */
	public function pasteText()
	{
		
	}
	
	/**  Observer methods **/
	
	/**
	 * Attach an observer to this concrete subject
	 * @return void
	 * @param Observer $o the observer of this concrete subject
	 */
	public function attach($o)
	{
		
	}
	
	/**
	 * Detach an observer from this concrete subject
	 * @return void
	 * @param Observer $o the observer to be detached
	 */
	public function detach($o)
	{
		
	}
	
	/**
	 * Notify the observers of this concrete subject
	 * @return void
	 * @access public
	 */
	public function notify()
	{
		
	}
}

?><commit_msg>* Implementation of the command methods in Buffer.php<commit_after><?php

/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version
 * This program 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 General Public License for more details
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

/**
 * This class represents a buffer, which contains a temporary text content;
 * This is also the concrete subject of the Obsever Design Pattern
 * 
 * @author <NAME> & <NAME>
 * @category Observer
 * @package observer
 * @version 0.1
 */

class Buffer
{
	
	/**
	 * The content of the current text
	 * @var _text
	 * @access private
	 * @type String
	 */
	private $_text;
	
	/**
	 * The begining of a selection.
	 * @var _selectionStart
	 * @access private
	 * @type Integer
	 */
	private $_selectionStart;
	
	/**
	 * The end of a selection
	 * @var _selectionEnd
	 * @access private
	 * @type Integer
	 */
	private $_selectionEnd;
	
	/**
	 * The clipboard object
	 * @var _clipboard
	 * @access private
	 * @type Clipboard
	 */
	private $_clipboard;
	
	/**
	 * The constructor of the class
	 * @return void
	 */
	public function __construct()
	{
		$this->_text = ""; 
		$this->_selectionStart = 0;
		$this->_selectionEnd = 0;
		$this->_clipboard = new Clipboard();
	}
	
	/**
	 * Get the current text
	 * @return the current text
	 * @access public
	 */
	public function getText()
	{
		return $this->_text;
	}
	
	/**
	 * Set the content of the current text
	 * @return void
	 * @param String $text the new content
	 * @access public
	 */
	public function setText($text)
	{
		$this->_text = $text;	
	}
	
	/**
	 * Set the begining of the selection
	 * @return void
	 * @param Integer $val the begining of the selection
	 * @access public
	 */
	public function setSelectionStart($val)
	{
		$this->_selectionStart = $val;
	}
	
	/**
	 * Set the end of the selection
	 * @return void 
	 * @param Integer $val the end of the selection
	 * @access public
	 */
	public function setSelectionEnd($val)
	{
		$this->_selectionEnd = $val;
	}
	
	/**
	 * Set the begining and the end of the selection
	 * @return void
	 * @param Integer $start the begining of the selection
	 * @param Integer $end the end of the selection
	 */
	public function setSelection($start, $end)
	{
		if($start <= $end){
			$this->_selectionStart = $start;
			$this->_selectionEnd = $end;
		}
		else{
			$this->_selectionStart = $start;
			$this->_selectionEnd = $end;
		}
	}
	
	/**
	 * Insert a character into the buffer
	 * @return void 
	 * @param Character $char the character to be inserted
	 */
	public function insert($char)
	{
		$this->_text = substr($this->_text, 0, $this->_selectionStart);
		$this->_text .= $char;
		$this->_text .= substr($this->_text, $this->_selectionEnd, strlen($this->_text));
		
		$this->_selectionStart++;
		
		if($this->_selectionStart != $this->_selectionEnd)
		{
			$this->_selectionEnd = $this->_selectionStart;
		}
	}
	
	/**
	 * Set a text content into the clipboard
	 * @return void
	 * @access private
	 */
	private function _setTextIntoClipBoard($text)
	{
		return $this->_clipboard->setText($text);
	}
	
	/**
	 * Get a text content from the clipboard
	 * @return String the text content from the clipboard
	 */
	private function _getTextFromClipBoard()
	{
		return $this->_clipboard->getText();
	}
	
	/** Command methods **/
	
	/**
	 * Copy the current selection into clipboard
	 * @return void
	 * @access public
	 */
	public function copyText()
	{
		$text = substr($this->_text, $this->_selectionStart, $this->_selectionEnd);
		
		if ( $text !== "" ) 
			$this->_setTextIntoClipBoard($text);
	}
	
	/**
	 * Cut the current selection into clipboard
	 * @return void
	 * @access public
	 */
	public function cutText()
	{
		if( $this->_selectionStart !== $this->_selectionEnd)
		{
			$text = substr($this->_text, $this->_selectionStart, $this->_selectionEnd);
			$this->_setTextIntoClipBoard($text);
			
			$this->_text = substr($this->_text, 0, $this->_selectionStart);
			$this->_text .= substr($this->_text, $this->_selectionEnd, strlen($this->_text));

			// deselection
			$this->_selectionEnd = $this->_selectionStart;

		}
	}
	
	/**
	 * Paste the content of the clipboard into the buffer
	 * @return void
	 * @access public
	 */
	public function pasteText()
	{
		if( $this->_clipboard->getText() === "")
		{
			if( $this->_selectionStart !== $this->_selectionEnd)
			{
				$this->_text = substr($this->_text, 0, $this->_selectionStart);
				$this->_text .= substr($this->_text, $this->_selectionEnd, strlen($this->_text));
				
				// deselection
				$this->_selectionEnd = $this->_selectionStart;
			}

			$this->_text = substr($this->_text, 0, $this->_selectionStart);
			$this->_text .= $this->_getTextFromClipBoard();
			$this->_text .= substr($this->_text, $this->_selectionStart, strlen($this->_text));
		}	
	}
	
	/**  Observer methods **/
	
	/**
	 * Attach an observer to this concrete subject
	 * @return void
	 * @param Observer $o the observer of this concrete subject
	 */
	public function attach($o)
	{
		
	}
	
	/**
	 * Detach an observer from this concrete subject
	 * @return void
	 * @param Observer $o the observer to be detached
	 */
	public function detach($o)
	{
		
	}
	
	/**
	 * Notify the observers of this concrete subject
	 * @return void
	 * @access public
	 */
	public function notify()
	{
		
	}
}

?>
{'fraction_non_alphanumeric': 0.11489583333333334, 'fraction_numerical': 0.00125, 'mean_word_length': 2.527185892725937, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 83, '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': '1278292', 'n_tokens_mistral': 3223, 'n_tokens_neox': 2668, 'n_words': 952}