]> git.mxchange.org Git - flightgear.git/commitdiff
Fred BOUVIER & Stuart BUCHANAN: make search function case-insensitive
authormfranz <mfranz>
Tue, 3 Jun 2008 10:25:58 +0000 (10:25 +0000)
committermfranz <mfranz>
Tue, 3 Jun 2008 10:25:58 +0000 (10:25 +0000)
mf: add leading space to allow search for word boundaries (" wat")

src/GUI/AirportList.cxx
src/GUI/AirportList.hxx

index 9fff823104d8a30e6398f531035f089647eae581..1b62f0aff3ef823f4e9a21ef699189f153d3eeaf 100644 (file)
@@ -1,37 +1,45 @@
-
+#include <locale>
 #include <Main/globals.hxx>
 #include <Airports/simple.hxx>
 
 #include "AirportList.hxx"
 
 
-AirportList::AirportList (int x, int y, int width, int height)
-    puaList(x, y, width, height),
-      GUI_ID(FGCLASS_AIRPORTLIST),
-      _airports(globals->get_airports()),
-      _content(0)
+AirportList::AirportList(int x, int y, int width, int height) :
+    puaList(x, y, width, height),
+    GUI_ID(FGCLASS_AIRPORTLIST),
+    _airports(globals->get_airports()),
+    _content(0)
 {
     create_list();
 }
 
-AirportList::~AirportList ()
+
+AirportList::~AirportList()
 {
     destroy_list();
 }
 
+
 void
-AirportList::create_list ()
+AirportList::create_list()
 {
+    const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
     int num_apt = _airports->size();
     char **content = new char *[num_apt + 1];
 
     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 entry(' ' + apt->getName() + "   (" + apt->getId() + ')');
+
+        if (!_filter.empty()) {
+            std::string upper(entry.data());
+            ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
 
-        if (!_filter.empty() && entry.find(_filter) == STD::string::npos)
-            continue;
+            if (upper.find(_filter) == std::string::npos)
+                continue;
+        }
 
         content[n] = new char[entry.size() + 1];
         strcpy(content[n], entry.c_str());
@@ -47,8 +55,9 @@ AirportList::create_list ()
     _content = content;
 }
 
+
 void
-AirportList::destroy_list ()
+AirportList::destroy_list()
 {
     for (char **c = _content; *c; c++) {
         delete *c;
@@ -57,15 +66,18 @@ AirportList::destroy_list ()
     delete [] _content;
 }
 
+
 void
-AirportList::setValue (const char *s)
+AirportList::setValue(const char *s)
 {
-    STD::string filter(s);
+    std::string filter(s);
+    const std::ctype<char> &ct = std::use_facet<std::ctype<char> >(std::locale());
+    ct.toupper((char *)filter.data(), (char *)filter.data() + filter.size());
+
     if (filter != _filter) {
         _filter = filter;
         create_list();
     }
 }
 
-// end of AirportList.cxx
 
index 1fe4673afa3ddfe7aaf113e5c95a517a03b78c90..dabd6977829dc81c1419dedd24b0b1450c047dd2 100644 (file)
@@ -4,31 +4,24 @@
 #define __AIRPORTLIST_HXX
 
 #include <simgear/compiler.h>
-#include STL_STRING
-
 #include <plib/puAux.h>
 #include "dialog.hxx"
 
-
-
-SG_USING_STD(string);
-
 class FGAirportList;
 
-class AirportList : public puaList, public GUI_ID
-{
- public:
-    AirportList (int x, int y, int width, int height);
-    virtual ~AirportList ();
+class AirportList : public puaList, public GUI_ID {
+public:
+    AirportList(int x, int y, int width, int height);
+    virtual ~AirportList();
 
     virtual void create_list();
     virtual void destroy_list();
-    virtual void setValue (const char *);
+    virtual void setValue(const char *);
 
- private:
-    FGAirportList * _airports;
-    char ** _content;
-    STD::string _filter;
+private:
+    FGAirportList *_airports;
+    char **_content;
+    std::string _filter;
 };
 
 #endif // __AIRPORTLIST_HXX