From e004cdef0b1bbc9bb164eafa02ccd8de4f845097 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Thu, 16 Oct 2008 14:14:28 -0400 Subject: [PATCH] more cleanup --- src/CodeVersionInformation.hx | 33 ++++++++++++------------ src/FunctionTokenProcessor.hx | 13 +++++++--- src/JavaScriptTarget.hx | 43 ++++++++++++++++++++++--------- src/TestCodeVersionInformation.hx | 1 + 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/src/CodeVersionInformation.hx b/src/CodeVersionInformation.hx index 62fa48d..fe7b2f6 100644 --- a/src/CodeVersionInformation.hx +++ b/src/CodeVersionInformation.hx @@ -1,13 +1,12 @@ +/** + Process version information for a set of Results. +**/ class CodeVersionInformation { public var final_versions : Hash>; public var minimum_versions : Hash; public var maximum_versions : Hash; public var all_modules : Array; - public static function breakdown_version_number(version : String) { - return version.split("."); - } - public static function get_version_lower_than(s : String) : String { var greater_than = ~/\<= (.*)$/; @@ -20,19 +19,17 @@ class CodeVersionInformation { public static function breakdown_php_version_string(s : String) { var parts = new Array(); - for (regexp in [ ~/^([^\ ]*) (.*)$/ ]) { - if (regexp.match(s)) { - var version = regexp.matched(2).split("-").shift(); + var regexp = ~/\W*(\w*) (.*)$/; + if (regexp.match(s)) { + var version = regexp.matched(2).split("-").shift(); - var greater_than = ~/\>= (.*)$/; - if (greater_than.match(version)) { - version = greater_than.matched(1); - } - - parts.push(regexp.matched(1)); - parts.push(version); - break; + var greater_than = ~/\>= (.*)$/; + if (greater_than.match(version)) { + version = greater_than.matched(1); } + + parts.push(regexp.matched(1)); + parts.push(version); } return parts; @@ -123,6 +120,10 @@ class CodeVersionInformation { return final_versions; } + /** + Create a new CodeVersionInformation object based on the provided + Result set and, optionally, while ignoring the provided modules. + **/ public function new(results : Array, ?ignored_modules : Hash) { var start_minimum_versions = new Hash>(); var start_maximum_versions = new Hash>(); @@ -132,7 +133,7 @@ class CodeVersionInformation { var internal_minimum_version = new Hash>(); var internal_maximum_version = new Hash>(); - for (part in result.version.split(", ")) { + for (part in result.version.split(",")) { var version_string_info = breakdown_php_version_string(part); if (version_string_info.length > 0) { var source = version_string_info[0]; diff --git a/src/FunctionTokenProcessor.hx b/src/FunctionTokenProcessor.hx index 9a81498..069c262 100644 --- a/src/FunctionTokenProcessor.hx +++ b/src/FunctionTokenProcessor.hx @@ -12,8 +12,8 @@ class FunctionTokenProcessor extends TokenProcessor { var tokens_parsed = 0; // - // haXe XML parsing is slow, as it uses a custom XML parser. - // so I'll use a custom XML parser for this data. + // haXe XML parsing is slow, as it uses a custom XML parser... + // ..so I'll my own custom XML parser for this particular data. // /*var start = Date.now(); var first_element = Xml.parse(s).firstElement(); @@ -38,6 +38,12 @@ class FunctionTokenProcessor extends TokenProcessor { var version_regexp = ~/from=\'([^\']*)\'/i; var token_regexp = ~/name=\'([^\']*)\'/i; + var version_clean_regexps = [ + function(s) { return ~/PECL /.replace(s, ""); }, + function(s) { return ~/\:/.replace(s, " "); }, + function(s) { return ~/\, /.replace(s, ","); } + ]; + while (i < s_length) { var new_i = s.indexOf("(); - ignored_modules = new Hash(); + show_only_modules = new Hash(); + ignored_modules = new Hash(); manually_ignored_modules = new Hash(); #if js @@ -78,16 +78,9 @@ class JavaScriptTarget { } #if js - static public function change_result_and_redraw(result_checkbox : Dynamic) { - var index_id_search = ~/^result-enabled-([0-9]+)$/; - if (index_id_search.match(result_checkbox.id)) { - var index_id = Std.parseInt(index_id_search.matched(1)); - if (change_result(index_id, !result_checkbox.checked)) { - display_version_information(); - } - } - } - + /** + Display code version information. + **/ static public function display_version_information() { var version_info = new CodeVersionInformation(current_results, ignored_modules); @@ -97,6 +90,7 @@ class JavaScriptTarget { output += "
"; + // module list var all_modules_hash = new Hash(); for (module in minimum.keys()) { all_modules_hash.set(module, true); } @@ -163,6 +157,7 @@ class JavaScriptTarget { output += ""; + // maximum version info var maximum = version_info.final_versions.get("maximum"); var printed_message = false; @@ -180,6 +175,7 @@ class JavaScriptTarget { output += "

This code may not run!

"; } + // tokens list output += ""; output += ""; @@ -258,6 +254,7 @@ class JavaScriptTarget { output += ""; + // update the how-to-ignore information var permanent_ignore_div = js.Lib.document.getElementById("permanent-ignore"); if ((ignored_modules_array.length > 0) || (ignored_tokens.length > 0)) { @@ -286,6 +283,9 @@ class JavaScriptTarget { js.Lib.document.getElementById('output').innerHTML = output; } + /** + Analyze the provided code and display the results. + **/ static public function do_analysis(textarea) { show_only_modules = new Hash(); @@ -305,11 +305,30 @@ class JavaScriptTarget { }, 100); } + /** + Toggle a token's visibility and redraw the page. + **/ + static public function change_result_and_redraw(result_checkbox : Dynamic) { + var index_id_search = ~/^result-enabled-([0-9]+)$/; + if (index_id_search.match(result_checkbox.id)) { + var index_id = Std.parseInt(index_id_search.matched(1)); + if (change_result(index_id, !result_checkbox.checked)) { + display_version_information(); + } + } + } + + /** + Toggle a module's visibiity and redraw the page. + **/ static public function toggle_module_and_redraw(module : String) { JavaScriptTarget.toggle_module(module); JavaScriptTarget.display_version_information(); } + /** + Toggle a module's enabled/disabed status and redraw the page. + **/ static public function toggle_ignore_module_and_redraw(module : String) { JavaScriptTarget.toggle_ignore_module(module); JavaScriptTarget.display_version_information(); diff --git a/src/TestCodeVersionInformation.hx b/src/TestCodeVersionInformation.hx index 19f1abb..68d37f9 100644 --- a/src/TestCodeVersionInformation.hx +++ b/src/TestCodeVersionInformation.hx @@ -28,6 +28,7 @@ class TestCodeVersionInformation extends haxe.unit.TestCase { **/ function test_breakdown_version_string() { assertEquals("[PHP, 4]", CodeVersionInformation.breakdown_php_version_string("PHP 4").toString()); + assertEquals("[PHP, 4]", CodeVersionInformation.breakdown_php_version_string(" PHP 4").toString()); assertEquals("[PHP, 5.2.0]", CodeVersionInformation.breakdown_php_version_string("PHP 5 >= 5.2.0").toString()); assertEquals("[xmlwriter, 2.0.4]", CodeVersionInformation.breakdown_php_version_string("xmlwriter 2.0.4").toString());
TokenIgnore?