1
0
Fork 0

Fred BOUVIER & Stuart BUCHANAN: make search function case-insensitive

mf: add leading space to allow search for word boundaries (" wat")
This commit is contained in:
mfranz 2008-06-03 10:25:58 +00:00
parent 5d5b1f3ca4
commit 9fc99b10e2
2 changed files with 36 additions and 31 deletions

View file

@ -1,12 +1,12 @@
#include <locale>
#include <Main/globals.hxx> #include <Main/globals.hxx>
#include <Airports/simple.hxx> #include <Airports/simple.hxx>
#include "AirportList.hxx" #include "AirportList.hxx"
AirportList::AirportList (int x, int y, int width, int height) AirportList::AirportList(int x, int y, int width, int height) :
: puaList(x, y, width, height), puaList(x, y, width, height),
GUI_ID(FGCLASS_AIRPORTLIST), GUI_ID(FGCLASS_AIRPORTLIST),
_airports(globals->get_airports()), _airports(globals->get_airports()),
_content(0) _content(0)
@ -14,24 +14,32 @@ AirportList::AirportList (int x, int y, int width, int height)
create_list(); create_list();
} }
AirportList::~AirportList() AirportList::~AirportList()
{ {
destroy_list(); destroy_list();
} }
void 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(); int num_apt = _airports->size();
char **content = new char *[num_apt + 1]; char **content = new char *[num_apt + 1];
int n = 0; int n = 0;
for (int i = 0; i < num_apt; i++) { for (int i = 0; i < num_apt; i++) {
const FGAirport *apt = _airports->getAirport(i); const FGAirport *apt = _airports->getAirport(i);
STD::string entry(apt->getName() + " (" + apt->getId() + ')'); std::string entry(' ' + apt->getName() + " (" + apt->getId() + ')');
if (!_filter.empty() && entry.find(_filter) == STD::string::npos) if (!_filter.empty()) {
std::string upper(entry.data());
ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size());
if (upper.find(_filter) == std::string::npos)
continue; continue;
}
content[n] = new char[entry.size() + 1]; content[n] = new char[entry.size() + 1];
strcpy(content[n], entry.c_str()); strcpy(content[n], entry.c_str());
@ -47,6 +55,7 @@ AirportList::create_list ()
_content = content; _content = content;
} }
void void
AirportList::destroy_list() AirportList::destroy_list()
{ {
@ -57,15 +66,18 @@ AirportList::destroy_list ()
delete [] _content; delete [] _content;
} }
void 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) { if (filter != _filter) {
_filter = filter; _filter = filter;
create_list(); create_list();
} }
} }
// end of AirportList.cxx

View file

@ -4,19 +4,12 @@
#define __AIRPORTLIST_HXX #define __AIRPORTLIST_HXX
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include STL_STRING
#include <plib/puAux.h> #include <plib/puAux.h>
#include "dialog.hxx" #include "dialog.hxx"
SG_USING_STD(string);
class FGAirportList; class FGAirportList;
class AirportList : public puaList, public GUI_ID class AirportList : public puaList, public GUI_ID {
{
public: public:
AirportList(int x, int y, int width, int height); AirportList(int x, int y, int width, int height);
virtual ~AirportList(); virtual ~AirportList();
@ -28,7 +21,7 @@ class AirportList : public puaList, public GUI_ID
private: private:
FGAirportList *_airports; FGAirportList *_airports;
char **_content; char **_content;
STD::string _filter; std::string _filter;
}; };
#endif // __AIRPORTLIST_HXX #endif // __AIRPORTLIST_HXX