cvs: pear /CodeGen/CodeGen Element.php Extension.php Maintainer.php /CodeGen/CodeGen/Tools Getopt.php Indent.php
| From: | Hartmut Holzgraefe | Date: | Fri, 17 Feb 2006 09:47:00 +0000 |
| Subject: | cvs: pear /CodeGen/CodeGen Element.php Extension.php Maintainer.php /CodeGen/CodeGen/Tools Getopt.php Indent.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-38300@lists.php.net to get a copy of this message | ||
hholzgra Fri Feb 17 09:47:00 2006 UTC
Modified files:
/pear/CodeGen/CodeGen Element.php Extension.php Maintainer.php
/pear/CodeGen/CodeGen/Tools Getopt.php Indent.php
Log:
- ereg() calls changed to preg_match()
- set_locale("C") to make sure case insensitive matches are ASCII only
- do not indent C preprocessor directives
http://cvs.php.net/viewcvs.cgi/pear/CodeGen/CodeGen/Element.php?r1=1.4&r2=1.5&diff_format=u
Index: pear/CodeGen/CodeGen/Element.php
diff -u pear/CodeGen/CodeGen/Element.php:1.4 pear/CodeGen/CodeGen/Element.php:1.5
--- pear/CodeGen/CodeGen/Element.php:1.4 Sat Feb 4 19:18:28 2006
+++ pear/CodeGen/CodeGen/Element.php Fri Feb 17 09:47:00 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Element.php,v 1.4 2006/02/04 19:18:28 hholzgra Exp $
+ * @version CVS: $Id: Element.php,v 1.5 2006/02/17 09:47:00 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -129,7 +129,7 @@
*/
function isName($name)
{
- if (ereg("^[[:alpha:]_][[:alnum:]_]*$",$name)) {
+ if (preg_match('|^[a-z_]\w*$|i',$name)) {
// TODO reserved words
return true;
}
http://cvs.php.net/viewcvs.cgi/pear/CodeGen/CodeGen/Extension.php?r1=1.15&r2=1.16&diff_format=u
Index: pear/CodeGen/CodeGen/Extension.php
diff -u pear/CodeGen/CodeGen/Extension.php:1.15 pear/CodeGen/CodeGen/Extension.php:1.16
--- pear/CodeGen/CodeGen/Extension.php:1.15 Wed Feb 15 15:25:47 2006
+++ pear/CodeGen/CodeGen/Extension.php Fri Feb 17 09:47:00 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Extension.php,v 1.15 2006/02/15 15:25:47 hholzgra Exp $
+ * @version CVS: $Id: Extension.php,v 1.16 2006/02/17 09:47:00 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -225,6 +225,8 @@
*/
function __construct()
{
+ set_locale("C"); // ASCII only
+
$this->release = new CodeGen_Release;
$this->platform = new CodeGen_Tools_Platform("all");
@@ -264,7 +266,7 @@
*/
function setName($name)
{
- if (!ereg("^[[:alpha:]_][[:alnum:]_]*$", $name)) {
+ if (!preg_match('|^[a-z_]\w*$|i', $name)) {
return PEAR::raiseError("'$name' is not a valid extension name");
}
http://cvs.php.net/viewcvs.cgi/pear/CodeGen/CodeGen/Maintainer.php?r1=1.3&r2=1.4&diff_format=u
Index: pear/CodeGen/CodeGen/Maintainer.php
diff -u pear/CodeGen/CodeGen/Maintainer.php:1.3 pear/CodeGen/CodeGen/Maintainer.php:1.4
--- pear/CodeGen/CodeGen/Maintainer.php:1.3 Fri Aug 5 20:00:12 2005
+++ pear/CodeGen/CodeGen/Maintainer.php Fri Feb 17 09:47:00 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Maintainer.php,v 1.3 2005/08/05 20:00:12 hholzgra Exp $
+ * @version CVS: $Id: Maintainer.php,v 1.4 2006/02/17 09:47:00 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -109,7 +109,7 @@
*/
function setUser($name)
{
- if (!ereg("^[[:alnum:]_-]+$", $name)) {
+ if (!preg_match('|^[\w-]+$|i', $name)) {
return PEAR::raiseError("'$name' is not a valid CVS user name");
}
http://cvs.php.net/viewcvs.cgi/pear/CodeGen/CodeGen/Tools/Getopt.php?r1=1.2&r2=1.3&diff_format=u
Index: pear/CodeGen/CodeGen/Tools/Getopt.php
diff -u pear/CodeGen/CodeGen/Tools/Getopt.php:1.2 pear/CodeGen/CodeGen/Tools/Getopt.php:1.3
--- pear/CodeGen/CodeGen/Tools/Getopt.php:1.2 Sun Aug 14 16:47:59 2005
+++ pear/CodeGen/CodeGen/Tools/Getopt.php Fri Feb 17 09:47:00 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2003-2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Getopt.php,v 1.2 2005/08/14 16:47:59 hholzgra Exp $
+ * @version CVS: $Id: Getopt.php,v 1.3 2006/02/17 09:47:00 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -191,7 +191,7 @@
{
$names = array();
foreach ($this->options [0] as $opt) {
- $names[] = ereg_replace("^-*", "", $opt[0]);
+ $names[] = preg_replace("|^-*|", "", $opt[0]);
}
return $names;
http://cvs.php.net/viewcvs.cgi/pear/CodeGen/CodeGen/Tools/Indent.php?r1=1.2&r2=1.3&diff_format=u
Index: pear/CodeGen/CodeGen/Tools/Indent.php
diff -u pear/CodeGen/CodeGen/Tools/Indent.php:1.2 pear/CodeGen/CodeGen/Tools/Indent.php:1.3
--- pear/CodeGen/CodeGen/Tools/Indent.php:1.2 Fri Aug 5 09:52:42 2005
+++ pear/CodeGen/CodeGen/Tools/Indent.php Fri Feb 17 09:47:00 2006
@@ -15,7 +15,7 @@
* @author Hartmut Holzgraefe <hartmut@php.net>
* @copyright 2005 Hartmut Holzgraefe
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Indent.php,v 1.2 2005/08/05 09:52:42 hholzgra Exp $
+ * @version CVS: $Id: Indent.php,v 1.3 2006/02/17 09:47:00 hholzgra Exp $
* @link http://pear.php.net/package/CodeGen
*/
@@ -83,24 +83,29 @@
*/
function indent($level, $text)
{
+ // TODO: untabify?
+
$lines = explode("\n", $text);
+ // remove trailing blank lines
while (count($lines) && trim(end($lines)) == "") {
array_pop($lines);
}
- $maxindent = 999;
+ // how far is this block intented right now?
+ $minIndent = 999;
foreach ($lines as $line) {
- if (trim($line)=="") continue;
- ereg("^ *", $line, $matches);
- $maxindent = min($maxindent, strlen($matches[0]));
+ if (trim($line)=="") continue; // ignore blank lines
+ if ($line{0} == '#') continue; // ignore preprocessor instructions
+ preg_match("|^ *|", $line, $matches); // detect leading blanks
+ $minIndent = min($minIndent, strlen($matches[0]));
}
$result = "";
- $find = str_repeat(" ", $maxindent);
+ $find = str_repeat(" ", $minIndent);
$replace = str_repeat(" ", $level);
foreach ($lines as $line) {
- $result.= self::tabify(ereg_replace("^$find", $replace,
$line)."\n", 4);
+ $result.= self::tabify(preg_replace("|^$find|", $replace,
$line)."\n", 4);
}
return self::linetrim($result);