From ac7f58722db2f912f17a94c6ce109457a74e6469 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 22 Jul 2011 08:30:08 +0200 Subject: [PATCH] added URI_TEMPLATE_MATCH_RESULT --- .../protocol/uri_template/src/uri_template.e | 6 +-- .../src/uri_template_match_result.e | 37 +++++++++++++++++++ .../uri_template/tests/test_uri_template.e | 23 ++++++------ 3 files changed, 51 insertions(+), 15 deletions(-) create mode 100644 library/protocol/uri_template/src/uri_template_match_result.e diff --git a/library/protocol/uri_template/src/uri_template.e b/library/protocol/uri_template/src/uri_template.e index dbc53430..c479985f 100644 --- a/library/protocol/uri_template/src/uri_template.e +++ b/library/protocol/uri_template/src/uri_template.e @@ -3,7 +3,7 @@ note Summary description for {URI_TEMPLATE}. See http://tools.ietf.org/html/draft-gregorio-uritemplate-05 - + ]" legal: "See notice at end of class." status: "See notice at end of class." @@ -116,7 +116,7 @@ feature -- Builder feature -- Analyze - match (a_uri: STRING): detachable TUPLE [path_variables: HASH_TABLE [STRING, STRING]; query_variables: HASH_TABLE [STRING, STRING]] + match (a_uri: STRING): detachable URI_TEMPLATE_MATCH_RESULT local b: BOOLEAN tpl: like template @@ -174,7 +174,7 @@ feature -- Analyze l_x_parts.forth end if b then - Result := [l_path_vars, l_query_vars] + create Result.make (l_path_vars, l_query_vars) end end end diff --git a/library/protocol/uri_template/src/uri_template_match_result.e b/library/protocol/uri_template/src/uri_template_match_result.e new file mode 100644 index 00000000..8c9cb3d2 --- /dev/null +++ b/library/protocol/uri_template/src/uri_template_match_result.e @@ -0,0 +1,37 @@ +note + description: "Summary description for {URI_TEMPLATE_MATCH_RESULT}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + URI_TEMPLATE_MATCH_RESULT + +create + make + +feature {NONE} -- Initialization + + make (p: like path_variables; q: like query_variables) + do + path_variables := p + query_variables := q + end + +feature -- Access + + path_variables: HASH_TABLE [STRING, STRING] + query_variables: HASH_TABLE [STRING, STRING] + +;note + copyright: "2011-2011, Eiffel Software and others" + license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" + source: "[ + Eiffel Software + 5949 Hollister Ave., Goleta, CA 93117 USA + Telephone 805-685-1006, Fax 805-685-6869 + Website http://www.eiffel.com + Customer support http://support.eiffel.com + ]" +end + diff --git a/library/protocol/uri_template/tests/test_uri_template.e b/library/protocol/uri_template/tests/test_uri_template.e index 6248f31b..76219cb8 100644 --- a/library/protocol/uri_template/tests/test_uri_template.e +++ b/library/protocol/uri_template/tests/test_uri_template.e @@ -21,7 +21,6 @@ feature -- Test routines do uri_template_parse ("api/foo/{foo_id}/{?id,extra}", <<"foo_id">>, <<"id", "extra">>) uri_template_parse ("weather/{state}/{city}?forecast={day}", <<"state", "city">>, <<"day">>) - end test_uri_template_matcher @@ -300,8 +299,8 @@ feature -- Test routines uri_template_string (ht, "x{/empty_keys*}", "x") uri_template_string (ht, "x{/empty_keys*|none}", "x/none") --- uri_template_string (ht, "x{;name|none}", "x;name=Fred,Wilma,Pebbles") --- uri_template_string (ht, "x{;favs|none}", "x;favs=color,red,volume,high") + uri_template_string (ht, "x{;name|none}", "x;name=Fred,Wilma,Pebbles") + uri_template_string (ht, "x{;favs|none}", "x;favs=color,red,volume,high") uri_template_string (ht, "x{;favs*|none}", "x;color=red;volume=high") uri_template_string (ht, "x{;empty}", "x;empty") uri_template_string (ht, "x{;empty|none}", "x;empty") @@ -316,10 +315,10 @@ feature -- Test routines uri_template_string (ht, "x{?empty}", "x?empty=") uri_template_string (ht, "x{?empty|foo=none}", "x?empty=") uri_template_string (ht, "x{?undef}", "x") --- uri_template_string (ht, "x{?undef|foo=none}", "x?foo=none") + uri_template_string (ht, "x{?undef|foo=none}", "x?foo=none") uri_template_string (ht, "x{?empty_keys}", "x") --- uri_template_string (ht, "x{?empty_keys|none}", "x?none") --- uri_template_string (ht, "x{?empty_keys|y=z}", "x?y=z") + uri_template_string (ht, "x{?empty_keys|none}", "x?none") + uri_template_string (ht, "x{?empty_keys|y=z}", "x?y=z") uri_template_string (ht, "x{?empty_keys*|y=z}", "x?y=z") @@ -363,13 +362,12 @@ feature -- Test routines uri_template_string (ht, "x{?empty_keys+}", "x") uri_template_string (ht, "x{?empty_keys+|none}", "x?empty_keys.none") --- uri_template_string (ht, "x{;name|none}", "x;name=Fred,Wilma,Pebbles") --- uri_template_string (ht, "x{;favs|none}", "x;favs=color,red,volume,high") - uri_template_string (ht, "x{;favs|none}", "x;color,red,volume,high") -- DIFF + uri_template_string (ht, "x{;name|none}", "x;name=Fred,Wilma,Pebbles") + uri_template_string (ht, "x{;favs|none}", "x;favs=color,red,volume,high") uri_template_string (ht, "x{;favs*|none}", "x;color=red;volume=high") uri_template_string (ht, "x{;favs+|none}", "x;favs.color=red;favs.volume=high") uri_template_string (ht, "x{;undef}", "x") --- uri_template_string (ht, "x{;undef|none}", "x;undef=none") + uri_template_string (ht, "x{;undef|none}", "x;undef=none") uri_template_string (ht, "x{;undef|none}", "x;none") uri_template_string (ht, "x{;empty}", "x;empty") uri_template_string (ht, "x{;empty|none}", "x;empty") @@ -447,7 +445,6 @@ feature -- Test routines uri_template_string (ht, "{;x,y}", ";x=1024;y=768") uri_template_string (ht, "{;x,y,empty}", ";x=1024;y=768;empty") uri_template_string (ht, "{;x,y,undef}", ";x=1024;y=768") --- uri_template_string (ht, "{;list}", ";val1,val2,val3") -- DIFF uri_template_string (ht, "{;list}", ";list=val1,val2,val3") -- DIFF uri_template_string (ht, "{;list*}", ";val1;val2;val3") uri_template_string (ht, "{;list+}", ";list=val1;list=val2;list=val3") @@ -570,8 +567,10 @@ feature -- Test routines local b: BOOLEAN i: INTEGER + l_match: detachable URI_TEMPLATE_MATCH_RESULT do - if attached a_uri_template.match (a_uri) as l_match then + l_match := a_uri_template.match (a_uri) + if l_match /= Void then if attached l_match.path_variables as path_ht then b := path_ht.count = path_res.count from