From 5b8a8a5f3d24826fbb9f241eed2e578136cb5412 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 6 Feb 2005 07:12:08 +0000 Subject: [PATCH] r47: Have a new-style PCV input parser... with lots of not working code and one working bit :-). --- includes/functions.php | 66 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/includes/functions.php b/includes/functions.php index 30f48c6..1445d9c 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -375,6 +375,72 @@ function construct_pcv_select_global_version($product = 0, $component = 0, $vers return $global_versions_html; } +// ###################### Start parse_pcv_select ##################### +function parse_pcv_select($input) +{ + $input = trim($input); + + ///////// PREG_MATCH IS A PIECE OF SHIT!1!!!!11! + // (yes I just swore in the code because the bastard of a RegEx didn't match + // my string for any good reason) + //var_dump( preg_match('#^p(\d+?)c(\d+?)v(\d+?)$#', $input) ); + /*if (ereg('p[:digit:].+?c[:digit:].+?v[:digit:].+?', $input) === false) + { + return false; + }*/ + + + /////////// CANT'T EXPLODE EMPTY + //$moo = explode('', $input); + //print_r($moo); + + + /////////// TOKENIZING TAKES WAAAAAAAAAAY TOO MUCH WORK + /*$tokens = array('p', 'c', 'v'); + $token = current($tokens);*/ + /*for ($i = 0; $i <= strlen($input); $i++) + { + $char = $input[$i]; + echo $token . "-$i>$char "; + if (is_numeric($char)) + { + $trio["$token"] .= $char; + } + else + { + array_shift($tokens); + $token = current($tokens); + if ($char != $token AND $char != current($tokens)) + { + // return false; + } + } + }*/ + + ///////// TOKENIZING 2 -- NO WORKEY + /*foreach ($tokens AS $token) + { + for ($i = 0; $i <= strlen($input); $i++) + { + $char = $input["$i"]; + if ($char != current($tokens)) + { + + } + } + }*/ + + //////// SO WE DO IT THE MORONIC WAY AND IT WORKS!!!! + $trio = preg_split('#(p|c|v)#i', $input, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); + print_r($trio); + if (count($trio) != 6 OR $trio[0] != 'p' OR $trio[2] != 'c' OR $trio[4] != 'v') + { + return false; + } + + return array('product' => intval($trio[1]), 'component' => intval($trio[3]), 'version' => intval($trio[5])); +} + /*=====================================================================*\ || ################################################################### || # $HeadURL$ -- 2.22.5