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:
parent
5d5b1f3ca4
commit
9fc99b10e2
2 changed files with 36 additions and 31 deletions
|
@ -1,12 +1,12 @@
|
|||
|
||||
#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),
|
||||
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)
|
||||
|
@ -14,24 +14,32 @@ AirportList::AirportList (int x, int y, int width, int height)
|
|||
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() && 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;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue