summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-12-27 16:58:43 -0500
committerMichael Larabel <michael@phx-laptop.(none)>2008-12-27 16:58:43 -0500
commitdb10a1eb1fb1da87d1403b7c9b6658b880ca5d1b (patch)
tree3e5dafb5cdfe24a775ddd9a12e04f7ef5de20a7b
parent502ac8e9fb41cfc4fb24222e3ec0d1c2f3833ed8 (diff)
downloadphoronix-test-suite-upstream-db10a1eb1fb1da87d1403b7c9b6658b880ca5d1b.tar.gz
phoronix-test-suite-upstream-db10a1eb1fb1da87d1403b7c9b6658b880ca5d1b.tar.xz
phoronix-test-suite-upstream-db10a1eb1fb1da87d1403b7c9b6658b880ca5d1b.zip
pts-core: Eliminate use of most preg_ functions
-rw-r--r--CHANGE-LOG3
-rw-r--r--pts-core/functions/pts-functions-run.php4
-rw-r--r--pts-core/functions/pts-functions.php42
-rw-r--r--pts-core/functions/pts-functions_system_hardware.php2
-rw-r--r--pts-core/functions/pts-functions_system_parsing.php15
-rw-r--r--pts-core/functions/pts-functions_tests.php9
6 files changed, 41 insertions, 34 deletions
diff --git a/CHANGE-LOG b/CHANGE-LOG
index c8f5291..87119b7 100644
--- a/CHANGE-LOG
+++ b/CHANGE-LOG
@@ -9,12 +9,13 @@ Phoronix Test Suite (Git)
- pts-core: Add pts_test_installed() boolean function
- pts-core: Add pts_installed_test_tandem_XmlReader object
- pts-core: Clean up Display / X.Org server reported string
+- pts-core: Eliminate use of most preg_ functions
- pts: Add UXA acceleration check to GtkPerf test note reporting
- pts: Add 2d-test base profile that reports 2D acceleration mode using Cascading Test Profiles
- pts_Graph: Tweak formatting of basic graph attributes
- bilde_renderer: Add and implement draw_polygon and draw_ellipse to drawing API
- bilde_renderer: Add support for dynamically resizing the image drawing buffer
-- bilde_renderer: Add experimental Adobe Flash / SWF renderer with partial support
+- bilde_renderer: Add experimental Adobe Flash / SWF renderer
Phoronix Test Suite 1.6.0 Beta 1
December 18, 2008
diff --git a/pts-core/functions/pts-functions-run.php b/pts-core/functions/pts-functions-run.php
index efb3079..4c74cd2 100644
--- a/pts-core/functions/pts-functions-run.php
+++ b/pts-core/functions/pts-functions-run.php
@@ -449,6 +449,10 @@ function pts_promt_user_tags($default_tags = "")
{
$tags_input = preg_replace("/[^a-zA-Z0-9s, -]/", "", $tags_input);
}
+ else
+ {
+ $tags_input = pts_remove_chars($tags_input, true, true, true);
+ }
$tags_input = trim($tags_input);
}
diff --git a/pts-core/functions/pts-functions.php b/pts-core/functions/pts-functions.php
index 3e3855b..d9deaca 100644
--- a/pts-core/functions/pts-functions.php
+++ b/pts-core/functions/pts-functions.php
@@ -170,12 +170,7 @@ function pts_clean_information_string($str)
$str = str_ireplace($original_phrase, $new_phrase, $str);
}
- if(function_exists("preg_replace"))
- {
- $str = trim(preg_replace("/\s+/", " ", $str));
- }
-
- return $str;
+ return pts_trim_spaces($str);
}
function pts_exit($string = "")
{
@@ -188,14 +183,8 @@ function pts_version_comparable($old, $new)
{
// Checks if there's a major version difference between two strings, if so returns false. If the same or only a minor difference, returns true.
- if(function_exists("preg_replace"))
- {
- $old = preg_replace("/[^.0-9]/", "", $old);
- $new = preg_replace("/[^.0-9]/", "", $new);
- }
-
- $old = explode(".", $old);
- $new = explode(".", $new);
+ $old = explode(".", pts_remove_chars($old, true, true, false));
+ $new = explode(".", pts_remove_chars($new, true, true, false));
$compare = true;
if(count($old) >= 2 && count($new) >= 2)
@@ -243,6 +232,31 @@ function pts_string_bool($string)
$string = strtolower($string);
return $string == "true" || $string == "1" || $string == "on";
}
+function pts_remove_chars($string, $keep_numeric = true, $keep_decimal = true, $keep_alpha = true)
+{
+ $string_r = str_split($string);
+ $new_string = "";
+
+ foreach($string_r as $char)
+ {
+ $i = ord($char);
+ if(($keep_numeric && $i > 47 && $i < 58) || ($keep_alpha && $i > 64 && $i < 91) ||
+ ($keep_alpha && $i > 96 && $i < 123) || ($keep_decimal && $i == 46))
+ {
+ $new_string .= $char;
+ }
+ }
+ return $new_string;
+}
+function pts_trim_spaces($string)
+{
+ while(strpos($string, " ") !== false)
+ {
+ $string = str_replace(" ", "", $string);
+ }
+
+ return trim($string);
+}
function pts_is_valid_download_url($string, $basename = null)
{
// Checks for valid download URL
diff --git a/pts-core/functions/pts-functions_system_hardware.php b/pts-core/functions/pts-functions_system_hardware.php
index 05ab514..933dc26 100644
--- a/pts-core/functions/pts-functions_system_hardware.php
+++ b/pts-core/functions/pts-functions_system_hardware.php
@@ -378,7 +378,7 @@ function hw_sys_memory_string()
$mem_type = substr($mem_type, 0, $cut);
}
- if(preg_replace("/[^a-zA-Z0-9s]/", "", $mem_type) == $mem_type)
+ if(pts_remove_chars($mem_type, true, false, true) == $mem_type)
{
$mem_prefix = $mem_type;
}
diff --git a/pts-core/functions/pts-functions_system_parsing.php b/pts-core/functions/pts-functions_system_parsing.php
index ebbcbe7..bd10b64 100644
--- a/pts-core/functions/pts-functions_system_parsing.php
+++ b/pts-core/functions/pts-functions_system_parsing.php
@@ -537,15 +537,8 @@ function read_ati_overdrive($attribute, $adapter = 0)
if($od_option == $attribute)
{
- $od_value = trim($line_r[1]);
-
- if(function_exists("preg_replace"))
- {
- $od_value = preg_replace("/\s+/", " ", $od_value);
- }
-
+ $od_value = pts_trim_spaces($line_r[1]);
$od_value = str_replace(array("%"), "", $od_value);
-
$od_value_r = explode(" ", $od_value);
if(count($od_value_r) == 1)
@@ -596,11 +589,7 @@ function read_system_memory_usage($TYPE = "TOTAL", $READ = "USED")
if(!empty($grab_line))
{
- if(function_exists("preg_replace"))
- {
- $grab_line = trim(preg_replace("/\s+/", " ", $grab_line));
- }
-
+ $grab_line = pts_trim_spaces($grab_line);
$mem_parts = explode(" ", $grab_line);
if($READ == "USED")
diff --git a/pts-core/functions/pts-functions_tests.php b/pts-core/functions/pts-functions_tests.php
index 0530cde..61ec7bc 100644
--- a/pts-core/functions/pts-functions_tests.php
+++ b/pts-core/functions/pts-functions_tests.php
@@ -613,12 +613,12 @@ function pts_test_version_compatible($version_compare = "")
{
$compatible = true;
- if(!empty($version_compare) && function_exists("preg_replace"))
+ if(!empty($version_compare))
{
- $current = preg_replace("/[^0-9]/", "", PTS_VERSION);
+ $current = pts_remove_chars(PTS_VERSION, true, false, false);
$version_compare = explode("-", $version_compare);
- $support_begins = preg_replace("/[^0-9]/", "", trim($version_compare[0]));
+ $support_begins = pts_remove_chars(trim($version_compare[0]), true, false, false);
if(count($version_compare) == 2)
{
@@ -628,8 +628,7 @@ function pts_test_version_compatible($version_compare = "")
{
$support_ends = PTS_VERSION;
}
-
- $support_ends = preg_replace("/[^0-9]/", "", $support_ends);
+ $support_ends = pts_remove_chars(trim($support_ends), true, false, false);
$compatible = $current >= $support_begins && $current <= $support_ends;
}