On Mittwoch, 2. Januar 2008, Thomas Bleher wrote: > * Markus Krötzsch <[EMAIL PROTECTED]> [2008-01-02 08:37]: > > On Sonntag, 30. Dezember 2007, Thomas Bleher wrote: > > > * Markus Krötzsch <[EMAIL PROTECTED]> [2007-12-30 22:10]: > > > > OK, my conclusion now was to support the following syntax: > > > > > > > > [[property% *subs?r*]] > > > > > > > > where ? and * represent _ and % in SQL. > > > > > > I think this is fine generally, but now you cannot query for a literal > > > * or ? anymore, AFAIK. > > > > I would not consider this to be a major issue, given that those > > characters are not too common in typical application strings, and given > > the fact that using "?" still queries for "some symbol" in that place -- > > it seems to be very unlikely that too strings differ only in one position > > where the query string has a "?". So in most cases it will have the same > > hits anyway (yes, there are some cases that could be problematic [1] ;). > > Agreed. > > > Anyway, I will leave this issue at rest until any user actually complains > > about this limitation. > > Here I have to respectfully disagree. > It seems unwise to wait until someone complains, when there is already a > patch resolving the issue.
OK, I give in. I will see to it as soon as I find the time. -- Markus > Why spend more time later on when the issue > can just be fixed right now? > > OK, the regexes where not very readable, but it doesn't really make the > code more complicated. > > FWIW, the regexes where so ugly only because backslashes have to be escaped > twice for PHPs preg_replace (so a single \ becomes \\\\). > > If we used ! as an escape sequence instead of \, the regexes would look > like this (untested): > > $value = str_replace(array('%', '_'), array('!%', '!_'), $value); > $value = preg_replace('/(?<!!)((?:!!)*)\*/', '$1%', $value); // if there's > an even number of \, change * to % $value = > preg_replace('/(?<!!)((?:!!)*)\?/', '$1_', $value); // ditto for ? and _ > $value = preg_replace('/(?<!!)((?:!!)*)!\*/', '$1*', $value); // if there's > an odd number, * was escaped and should stay as is; but the last \ is > removed $value = preg_replace('/(?<!!)((?:!!)*)!\?/', '$1?', $value); // > ditto for ? > > (?: ) is a subexpression for grouping, not capturing, > (?<! ) is zero-width negative look-behind (i.e. we make sure that the > character before our match is not !). > > Regards, > Thomas > > > [1] http://de.wikipedia.org/wiki/Die_drei_%3F%3F%3F > > > > > Not a huge deal, but before, "a_b" searched for "a, followed by any > > > char, followed by b", while "a\_b" searched for "exactly a_b". > > > > > > Properly escaping everything gets messy rather quickly, as \ can also > > > be escaped to query for a literal \, so you need translations like: > > > > > > ? => _ > > > \? => ? > > > \\? => \\_ > > > \\\? => \\? > > > > > > The following regular expressions work fine for me, but unfortunately > > > they are quite ugly: > > > > > > $value = str_replace(array('%', '_'), array('\%', '\_'), $value); // > > > escape % and _ $value = preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)\*/', > > > '$1%', $value); // if there's an even number of \, change * to % $value > > > = preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)\?/', '$1_', $value); // ditto > > > for ? and _ $value = preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)\\\\\*/', > > > '$1*', $value); // if there's an odd number, * was escaped and should > > > stay as is; but the last \ is removed $value = > > > preg_replace('/(?<!\\\\)((?:\\\\\\\\)*)\\\\\?/', '$1?', $value); // > > > ditto for ? > > > > > > I think these should be added to SMW, so all characters can be queried. > > > > > > Regards, > > > Thomas > > > > -- > > Markus Krötzsch > > Institut AIFB, Universät Karlsruhe (TH), 76128 Karlsruhe > > phone +49 (0)721 608 7362 fax +49 (0)721 608 5998 > > [EMAIL PROTECTED] www http://korrekt.org -- Markus Krötzsch Institut AIFB, Universät Karlsruhe (TH), 76128 Karlsruhe phone +49 (0)721 608 7362 fax +49 (0)721 608 5998 [EMAIL PROTECTED] www http://korrekt.org
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________ Semediawiki-devel mailing list Semediawiki-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/semediawiki-devel