[josm-dev] [PATCH] Regex support for search

Ævar Arnfjörð Bjarmason avarab at gmail.com
Thu Jan 8 14:26:48 GMT 2009


On Thu, Jan 8, 2009 at 2:19 PM, Dirk Stöcker <openstreetmap at dstoecker.de> wrote:
> On Thu, 8 Jan 2009, Ævar Arnfjörð Bjarmason wrote:
>
>> The attached patch adds regex support to search, this solves trac
>> ticket #1864 [1][2], it adds a new "regex search" checkbox to the
>> search dialog below "case sensitive". If it's checked the pattern
>> given will be compiled as a regex with java.util.regex, e.g.:
>
> Thanks for your work.
>
>> ^hig.*?[way]+$ # Matches in both keys and values
>> ^foo$:[bar]       # Seperate regexes for the key and value
>>
>> Patterns are case-insensitive by default, if the "case sensitive"
>> checkbox is checked they will be compiled with
>> Pattern.CASE_INSENSITIVE set (instead of lower casing the regex or
>> pattern which would screw things up).
>>
>> If the user enters an invalid regex a dialog like this (by throwing
>> ParseError) shows up:
>>
>> http://flickr.com/photos/avarab/3178963199/sizes/o/
>>
>> It is of course translatable but the "full error" part comes directly
>> from Java's e.getMessage() exception method and may thus not be in the
>> same language as the rest of the JOSM interface. Although Java
>> implementations might have it localized. I think this is acceptable
>> given the limitations, the alternative is to provide a "regex
>> compilation failed" error without any further detail.
>
> Some notes: You cannot add any text without tr(). It will not get
> translated. Either you make a marktr() around or you add it directly at the
> place where it is used and add a tr().

I didn't know about that tr() restriction. Attached is a patch where I
duplicate the error message for all the places where there can be
regex errors, more duplication but it eliminates the class variable I
was using to store the message.

> About Java messages: When they aren't dynamic, we can translate them as
> well. Add a tr around the message text and have a
>
> tr("could not get audio input stream from input URL"); // Java message
> loading audio data
>
> in the i18n/specialmessages.java.
>
> If they are dynamic (e.g. contain variables), then we cannot translate them.
> Your example looks like they are dynamic.

Yes, that error message is dynamic.

>> 2. I couldn't submit it to trac, it gave me: "500 Internal Server
>> Error (Submission rejected as potential spam (Content contained
>> blacklisted patterns))"
>
> Making a zip sometimes helps :-)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: josm-rx-search2.patch
Type: text/x-diff
Size: 15169 bytes
Desc: not available
URL: <http://lists.openstreetmap.org/pipermail/josm-dev/attachments/20090108/84bf7f98/attachment.patch>


More information about the josm-dev mailing list