Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-03 Thread Melchior FRANZ
* Stuart Buchanan -- Monday 02 June 2008:
> ... and here's the patch, based on Fred's original patch.
> 
> Assuming it passes muster, could someone review and commit please?

I fixed the bug[1] and committed it, thanks Fred & Stuart!

Though Fred's way to display the entries in upper case hides the
ugly case inconsistency, I kept your approach, since upper case
text takes more space and is a bit harder to read. I'll contact
Robin and ask if he sees a way to fix apt.dat.

I also added a leading space to all entries, so you can use a space
in the search string to mark word boundaries. Searching for "wat"
will return Waterloo and Clearwater, while " wat" will not return 
Clearwater.

m.



[1] should be filter.size() in
ct.toupper((char *) filter.data(), (char *)filter.data() + _filter.size());

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Curtis Olson -- Tuesday 03 June 2008: 
> Well assuming that we have agreed to switch over to a case insensitive
> search, 

I think we have. Takes another hour until I have compiled OSG 2.5.1
and the newest sg/fg changes, but then I'll commit Stuart's patch
(after having fixed indendation and random spaces, of course :-).


For those not fully understanding the issue yet, here's a little
illustration: If I use the following quite useful shell function ...

  apt() { LANG=en_US zgrep "^1 " $FG_ROOT/Airports/apt.dat.gz|sed -r 
's,^..{13},,'|egrep -i "$*" ; }

like so:

  $ apt "" # normally I'd write e.g.apt ^LO   or   apt Dallas
  
then I get a list of all airports, and a part of it looks like this:

 YWTL Waterloo
 CYKF WATERLOO
 KALO WATERLOO RGNL
 37NE Watermeier
 MA97 Waters
 KART WATERTOWN INTL
 KRYV Watertown Muni
 KATY WATERTOWN RGNL
 2S5  Waterville
 CCW3 Waterville Kings Co Muni
 KWVL WATERVILLE ROBERT LAFLEUR
 40C  Watervliet Municipal
 S25  WATFORD CITY MUNI

So a case-sensitive search for "Wat" would give me an unpredictable
"random" result. There's no rule for when names are capitalized or
versal. This is not suited to find a particular airport. Of course,
we could modify the names when reading in apt.dat.gz, but that's a
bit tricky, too. Some things don't make sense when auto-capitalized:
AB (Airbase) shouldn't become Ab, for example.

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Curtis Olson
On Mon, Jun 2, 2008 at 4:55 PM, Melchior FRANZ <[EMAIL PROTECTED]> wrote:

> * Melchior FRANZ -- Monday 02 June 2008:
> > And before we do anything like that we should first decide if
> > we *really* want and need the case sensitivity configurable.
>
> ... especially considering that we are having the discussion exactly
> because case-sensitivity turned out to be useless given the bad
> state of apt.dat. So, if it's useless, why make it an option?  :-)


Well assuming that we have agreed to switch over to a case insensitive
search, that it's hard to disagree with you. :-)

Curt.
-- 
Curtis Olson: http://baron.flightgear.org/~curt/
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Melchior FRANZ -- Monday 02 June 2008:
> And before we do anything like that we should first decide if
> we *really* want and need the case sensitivity configurable.

... especially considering that we are having the discussion exactly
because case-sensitivity turned out to be useless given the bad
state of apt.dat. So, if it's useless, why make it an option?  :-)

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Curtis Olson -- Monday 02 June 2008:
> I may be completely misunderstanding this whole thread, but could we add
> another widget to the search dialog window that is tied to a boolean
> property.

We could, but it would IMHO also be a bit unclean, as it would influence
all airport-search widgets. (Sure, we use only one, but that's not the
point.) And before we do anything like that we should first decide if
we *really* want and need the case sensitivity configurable. Just adding
checkboxes for the sake of it doesn't make dialogs better. This rings my
bloat-bell. :-}

m.


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Curtis Olson
Torsten Dreyer -- Tuesday 03 June 2008:

> > Maybe a litte checkbox named "Case sensitive search" might give the user
> the
> > freedom of choice? This adds one option without dropping the other.
>

 On Mon, Jun 2, 2008 at 4:07 PM, Melchior FRANZ wrote:

> Widgets are associated with one single property, and they read
> from it after getting a "dialog-update" and write to it after
> getting a "dialog-apply". The former is used for sending the
> search expression to the widget, the latter for returning the
> selected entry.
>
> So to add a widget config option, one would have to encode that
> in the search expression, for example by (optionally) setting a
> non-ASCII character at the first position via some embedded Nasal.
> But that's a bit ugly, and I'm not sure if it's worth it.
> Case-insensitive ought to be enough for anybody.  :-)


I may be completely misunderstanding this whole thread, but could we add
another widget to the search dialog window that is tied to a boolean
property.  Then the search function could check the state of this value when
it searches to control the case sensitivity behavior.

Regards,

Curt.
-- 
Curtis Olson: http://baron.flightgear.org/~curt/
-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Stuart Buchanan -- Monday 02 June 2008:
> Assuming it passes muster, [...]

It doesn't. You are adding 2-space spaghetti code indentation to a
file that uses 4 spaces.

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Stuart Buchanan
--- On Mon, 2/6/08, Stuart Buchanan wrote:
> I will continue looking at this, though if anyone else
> would like to jump in with suggestions, that would be very
> welcome.

... and here's the patch, based on Fred's original patch.

Assuming it passes muster, could someone review and commit please?

-Stuart


Index: AirportList.cxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/GUI/AirportList.cxx,v
retrieving revision 1.18
diff -u -p -r1.18 AirportList.cxx
--- AirportList.cxx 11 Mar 2008 15:58:57 -  1.18
+++ AirportList.cxx 2 Jun 2008 21:05:01 -
@@ -1,4 +1,4 @@
-
+#include 
 #include 
 #include 
 
@@ -22,6 +22,7 @@ AirportList::~AirportList ()
 void
 AirportList::create_list ()
 {
+const std::ctype &ct = std::use_facet 
>(std::locale() );
 int num_apt = _airports->size();
 char **content = new char *[num_apt + 1];
 
@@ -30,8 +31,13 @@ AirportList::create_list ()
 const FGAirport *apt = _airports->getAirport(i);
 STD::string entry(apt->getName() + "   (" + apt->getId() + ')');
 
-if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
+if (!_filter.empty()) {
+  // Perform filter check case-insensitively
+  std::string cientry(apt->getName() + "   (" + apt->getId() + ')');
+  ct.toupper( (char *) cientry.data(), (char *) cientry.data() + 
cientry.size() );
+  if (cientry.find(_filter) == std::string::npos)
 continue;
+}
 
 content[n] = new char[entry.size() + 1];
 strcpy(content[n], entry.c_str());
@@ -60,7 +66,12 @@ AirportList::destroy_list ()
 void
 AirportList::setValue (const char *s)
 {
-STD::string filter(s);
+std::string filter(s);
+const std::ctype &ct = std::use_facet 
>(std::locale() );
+
+// convert filter to upper-case for case-insensitive matching
+ct.toupper( (char *) filter.data(),  (char *) filter.data() + 
_filter.size() );
+
 if (filter != _filter) {
 _filter = filter;
 create_list();
Index: AirportList.hxx
===
RCS file: /var/cvs/FlightGear-0.9/source/src/GUI/AirportList.hxx,v
retrieving revision 1.7
diff -u -p -r1.7 AirportList.hxx
--- AirportList.hxx 11 Mar 2008 15:58:57 -  1.7
+++ AirportList.hxx 2 Jun 2008 21:05:01 -
@@ -9,10 +9,6 @@
 #include 
 #include "dialog.hxx"
 
-
-
-SG_USING_STD(string);
-
 class FGAirportList;
 
 class AirportList : public puaList, public GUI_ID
@@ -28,7 +24,7 @@ class AirportList : public puaList, publ
  private:
 FGAirportList * _airports;
 char ** _content;
-STD::string _filter;
+std::string _filter;
 };
 
 #endif // __AIRPORTLIST_HXX



  __
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Torsten Dreyer -- Tuesday 03 June 2008:
> Maybe a litte checkbox named "Case sensitive search" might give the user the 
> freedom of choice? This adds one option without dropping the other.

Widgets are associated with one single property, and they read
from it after getting a "dialog-update" and write to it after
getting a "dialog-apply". The former is used for sending the
search expression to the widget, the latter for returning the
selected entry.

So to add a widget config option, one would have to encode that
in the search expression, for example by (optionally) setting a
non-ASCII character at the first position via some embedded Nasal.
But that's a bit ugly, and I'm not sure if it's worth it.
Case-insensitive ought to be enough for anybody.  :-)

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Torsten Dreyer
Am Montag, 2. Juni 2008 schrieb Melchior FRANZ:
> * Stuart Buchanan -- Monday 02 June 2008:
> > Nevertheless, I think these are acceptable numbers for a 3 character
> > string. The user can easily perform a more specific search on receiving
> > a large number of results.
>
> As I told on IRC already, the current case-sensitive behavior wasn't
> an accident or laziness. It allowed a more precise search string with
> less hits. This seemed useful at times where airport names were
> consistently and correctly capitalized. Unfortunately, current apt.dat
> is a complete mess in this regard, so case-sensitivity turned into
> a disadvantage, and I agree that case-insensitivity is now desirable.
> (Well, fixing apt.dat would be even better, but not in our responsibility.)

Maybe a litte checkbox named "Case sensitive search" might give the user the 
freedom of choice? This adds one option without dropping the other.

Torsten

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Stuart Buchanan
--- On Mon, 2/6/08, Melchior FRANZ wrote:
> * Stuart Buchanan -- Monday 02 June 2008:
> > Nevertheless, I think these are acceptable numbers for
> a 3 character
> > string. The user can easily perform a more specific
> search on receiving
> > a large number of results.  
> 
> As I told on IRC already, the current case-sensitive
> behavior wasn't an accident or laziness. 

I must have missed that. I have not been paying enough attention to the IRC 
channel when logged on recently. My apologies.

> BTW: that ICAO codes are output in parentheses is also not
> just a
> cosmetic issue: this was done to allow searching for all
> French airports
> with "(LF", for (almost) all Austrian military
> airports with "(LOX" etc.

Thanks for pointing that out. I will ensure that this behaviour is unaffected 
by any changes.

-Stuart


  __
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Melchior FRANZ
* Stuart Buchanan -- Monday 02 June 2008:
> Nevertheless, I think these are acceptable numbers for a 3 character
> string. The user can easily perform a more specific search on receiving
> a large number of results.  

As I told on IRC already, the current case-sensitive behavior wasn't
an accident or laziness. It allowed a more precise search string with
less hits. This seemed useful at times where airport names were
consistently and correctly capitalized. Unfortunately, current apt.dat
is a complete mess in this regard, so case-sensitivity turned into
a disadvantage, and I agree that case-insensitivity is now desirable.
(Well, fixing apt.dat would be even better, but not in our responsibility.)

BTW: that ICAO codes are output in parentheses is also not just a
cosmetic issue: this was done to allow searching for all French airports
with "(LF", for (almost) all Austrian military airports with "(LOX" etc.

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-02 Thread Stuart Buchanan
--- On Sun, 1/6/08, Frederic Bouvier wrote:
> I confirm there in no strcasestr or equivalent in MS
> runtime.
> The patch below should be portable, although more
> convoluted.

>From reading the patch, I don't think this does quite what we want either. My 
>reading is that this ensures that the identifier of the airport is in upper 
>case. However, thanks for pointing out another approach to the problem.

What we really want is to ensure that any search is completely case-insensitive.

For example, apt.dat contains the following lines:

1 400 1 1 KLVK LIVERMORE MUNI
1 425 0 1 4AK2 Livengood Camp
13982 0 0 LIVD Dobbiaco

Currently, searching for "LIV" returns the first and last lines, while 
searching for "Livermore" returns nothing, despite being what most people would 
search for.

I think a use searching for "liv" would expect to see all the results above, 
and more.

One issue that is worth discussion is that if we make the search completely 
case-insensitive, we obviously increase the number of results returned. 

In the example above, searching for "liv" would return a total of 54 results. A 
much less unique string, such as "san" would return over 400. 

Note that this assumes that the user has the entire world scenery installed, 
which is pretty unlikely.

Nevertheless, I think these are acceptable numbers for a 3 character string. 
The user can easily perform a more specific search on receiving a large number 
of results.

I will continue looking at this, though if anyone else would like to jump in 
with suggestions, that would be very welcome.

-Stuart


  __
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-06-01 Thread Frederic Bouvier
Melchior FRANZ a écrit :
> * Stuart Buchanan -- Saturday 31 May 2008:
>   
>> +if (!_filter.empty() && (strcasestr(entry.c_str(), _filter.c_str()) 
>> == NULL))
>> 
>
> quote from 'man strcasestr':
>
>   The strcasestr() function is a non-standard extension.
>
> I doubt that it's available on all supported platforms.
>   

I confirm there in no strcasestr or equivalent in MS runtime.
The patch below should be portable, although more convoluted.

-Fred

cvs -z4 -w -q diff -u -wb -- src\GUI\AirportList.cxx 
src\GUI\AirportList.hxx (in directory I:\Devel\FlightGear\)
Index: src/GUI/AirportList.cxx
===
RCS file: /var/cvs/FlightGear-0.9/FlightGear/src/GUI/AirportList.cxx,v
retrieving revision 1.18
diff -u -w -b -r1.18 AirportList.cxx
--- src/GUI/AirportList.cxx11 Mar 2008 15:58:57 -1.18
+++ src/GUI/AirportList.cxx1 Jun 2008 10:21:57 -
@@ -2,6 +2,8 @@
 #include 
 #include 
 
+#include 
+
 #include "AirportList.hxx"
 
 
@@ -25,12 +27,15 @@
 int num_apt = _airports->size();
 char **content = new char *[num_apt + 1];
 
+const std::ctype &ct = std::use_facet >( 
std::locale() );
 int n = 0;
 for (int i = 0; i < num_apt; i++) {
 const FGAirport *apt = _airports->getAirport(i);
-STD::string entry(apt->getName() + "   (" + apt->getId() + ')');
+std::string aid = apt->getId();
+ct.toupper( (char *)aid.data(), (char *)aid.data()+aid.size() );
+std::string entry(apt->getName() + "   (" + aid + ')');
 
-if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
+if (!_filter.empty() && entry.find(_filter) == std::string::npos)
 continue;
 
 content[n] = new char[entry.size() + 1];
@@ -60,7 +65,8 @@
 void
 AirportList::setValue (const char *s)
 {
-STD::string filter(s);
+std::string filter(s);
+std::use_facet >( std::locale() ).toupper( (char 
*)filter.data(), (char *)filter.data()+filter.size() );
 if (filter != _filter) {
 _filter = filter;
 create_list();
Index: src/GUI/AirportList.hxx
===
RCS file: /var/cvs/FlightGear-0.9/FlightGear/src/GUI/AirportList.hxx,v
retrieving revision 1.7
diff -u -w -b -r1.7 AirportList.hxx
--- src/GUI/AirportList.hxx11 Mar 2008 15:58:57 -1.7
+++ src/GUI/AirportList.hxx1 Jun 2008 10:08:17 -
@@ -9,10 +9,6 @@
 #include 
 #include "dialog.hxx"
 
-
-
-SG_USING_STD(string);
-
 class FGAirportList;
 
 class AirportList : public puaList, public GUI_ID
@@ -28,7 +24,7 @@
  private:
 FGAirportList * _airports;
 char ** _content;
-STD::string _filter;
+std::string _filter;
 };
 
 #endif // __AIRPORTLIST_HXX

-- 
Frédéric Bouvier
http://my.fotolia.com/frfoto/   Photo gallery
http://fgsd.sourceforge.net/FlightGear Scenery Designer


-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel


Re: [Flightgear-devel] Patch to perform airport searches case-insensitively

2008-05-31 Thread Melchior FRANZ
* Stuart Buchanan -- Saturday 31 May 2008:
> +if (!_filter.empty() && (strcasestr(entry.c_str(), _filter.c_str()) 
> == NULL))

quote from 'man strcasestr':

  The strcasestr() function is a non-standard extension.

I doubt that it's available on all supported platforms.

m.

-
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse012070mrt/direct/01/
___
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel