public function searchAndReplace( $text ) {
		$state = 0;
		$length = strlen( $text );
		$matches = [];
		for ( $i = 0; $i < $length; $i++ ) {
			$ch = $text[$i];
			$state = $this->nextState( $state, $ch );
			foreach ( $this->outputs[$state] as $match ) {
				$offset = $i - $this->searchKeywords[$match] + 1;
				$matches[$offset] = $match;
			}
		}
		ksort( $matches );

		$buf = '';
		$lastInsert = 0;
		foreach ( $matches as $offset => $match ) {
			if ( $offset >= $lastInsert ) {
				$buf .= substr( $text, $lastInsert, $offset - $lastInsert );
				$buf .= $this->replacePairs[$match];
				$lastInsert = $offset + $this->searchKeywords[$match];
			}
		}
		$buf .= substr( $text, $lastInsert );

		return $buf;
	}