← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1734: [filters] Added PregFilter

 

------------------------------------------------------------
revno: 1734
author: Sander van Schouwenburg <sander@xxxxxxxxxxxxx>
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Sun 2009-08-02 22:33:30 +0200
message:
  [filters] Added PregFilter
  
  This filter uses preg_replace().
added:
  filters/pregfilter.lib.php
modified:
  filters/main.lib.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'filters/main.lib.php'
--- filters/main.lib.php	2006-05-16 07:08:18 +0000
+++ filters/main.lib.php	2009-08-02 20:33:30 +0000
@@ -29,5 +29,6 @@
 anewt_include('filters/stripwhitespacefilter');
 anewt_include('filters/uppercasefilter');
 anewt_include('filters/firstuppercasefilter');
+anewt_include('filters/pregfilter');
 
 ?>

=== added file 'filters/pregfilter.lib.php'
--- filters/pregfilter.lib.php	1970-01-01 00:00:00 +0000
+++ filters/pregfilter.lib.php	2009-08-02 20:33:30 +0000
@@ -0,0 +1,62 @@
+<?php
+
+/*
+ * Anewt, Almost No Effort Web Toolkit, filters module
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA+
+ */
+
+
+anewt_include('filters/filter');
+
+
+/**
+ * Filter to transform a string to all Preg.
+ */
+class PregFilter extends Filter {
+
+	protected $regexp;
+	protected $replace;
+
+	/**
+	 * Constructor.
+	 *
+	 * \param $regexp
+	 *   The regular expression. This is the first argument to preg_replace.
+	 * \param $replace
+	 *   The replacement value. This is the second argument to preg_replace.
+	 */
+	function __construct($regexp, $replace)
+	{
+		assert('is_string($regexp)');
+		assert('is_string($replace)');
+
+		$this->regexp = $regexp;
+		$this->replace = $replace;
+	}
+	/**
+	 * Applies the PregFilter to the passed value.
+	 *
+	 * \param $value The value to filter.
+	 *
+	 * \return The string filtered through preg_replace.
+	 */
+	function filter($value) {
+		assert('is_string($value)');
+		return preg_replace($this->regexp, $this->replace, $value);
+	}
+}
+
+?>