Where to put custom URL parser

I've written a routine for encoding and decoding custom urls.

My route looks like:

map.browse 'items/browse/*query', :controller => 'items', :action =>
'browse'

Now the param query is suposed to look something like:

manufactured_by_Sombody/is_tagged_this_and_that/is_tagged_foo_or_bar/
is_not_tagged_baz_and_nitch

Now I've got the routines built to decode this and turn it into a
thinking sphinx search hash, and I have the code to turn the TS hash
into that url. My problem is, I need access to that code in both the
controller and the view, where is the best place to put this code so
it is accessible in those two locations without repeating the code.

Is there a better way to do this, becaue at the moment in order to
form links I am using code like

link_to "foo", browse_url(:query => parse_browse_url(hash))

I'd appreciate any input.

-Brian