Commit 15d26211 authored by VanillaSalt's avatar VanillaSalt

use wstring

parent 895e6e7a
......@@ -39,9 +39,9 @@ struct CardDataC {
unsigned int category;
};
struct CardString {
wchar_t* name;
wchar_t* text;
wchar_t* desc[16];
std::wstring name;
std::wstring text;
std::wstring desc[16];
};
typedef std::unordered_map<unsigned int, CardDataC>::const_iterator code_pointer;
......
......@@ -1370,7 +1370,7 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, declarable_type)) {
mainGame->lstANCard->clear();
ancard.clear();
mainGame->lstANCard->addItem(cstr.name);
mainGame->lstANCard->addItem(cstr.name.c_str());
ancard.push_back(trycode);
return;
}
......@@ -1379,15 +1379,15 @@ void ClientField::UpdateDeclarableCodeType(bool enter) {
mainGame->lstANCard->clear();
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(wcsstr(cit->second.name, pname) != 0) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declarable_type)) {
if(wcscmp(pname, cit->second.name) == 0) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name, -1);
if(pname == cit->second.name) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first);
} else {
mainGame->lstANCard->addItem(cit->second.name);
mainGame->lstANCard->addItem(cit->second.name.c_str());
ancard.push_back(cit->first);
}
}
......@@ -1402,7 +1402,7 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, opcode)) {
mainGame->lstANCard->clear();
ancard.clear();
mainGame->lstANCard->addItem(cstr.name);
mainGame->lstANCard->addItem(cstr.name.c_str());
ancard.push_back(trycode);
return;
}
......@@ -1411,15 +1411,15 @@ void ClientField::UpdateDeclarableCodeOpcode(bool enter) {
mainGame->lstANCard->clear();
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
if(wcsstr(cit->second.name, pname) != 0) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias
if(is_declarable(cp->second, opcode)) {
if(wcscmp(pname, cit->second.name) == 0) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name, -1);
if(pname == cit->second.name) { //exact match
mainGame->lstANCard->insertItem(0, cit->second.name.c_str(), -1);
ancard.insert(ancard.begin(), cit->first);
} else {
mainGame->lstANCard->addItem(cit->second.name);
mainGame->lstANCard->addItem(cit->second.name.c_str());
ancard.push_back(cit->first);
}
}
......
......@@ -17,8 +17,7 @@ bool DataManager::LoadDB(const char* file) {
return Error(pDB);
CardDataC cd;
CardString cs;
for(int i = 0; i < 16; ++i) cs.desc[i] = 0;
int step = 0, len = 0;
int step = 0;
do {
step = sqlite3_step(pStmt);
if(step == SQLITE_BUSY || step == SQLITE_ERROR || step == SQLITE_MISUSE)
......@@ -44,27 +43,21 @@ bool DataManager::LoadDB(const char* file) {
cd.attribute = sqlite3_column_int(pStmt, 9);
cd.category = sqlite3_column_int(pStmt, 10);
_datas.insert(std::make_pair(cd.code, cd));
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 12), strBuffer);
if(len) {
cs.name = new wchar_t[len + 1];
memcpy(cs.name, strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.name = 0;
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, 13), strBuffer);
if(len) {
cs.text = new wchar_t[len + 1];
memcpy(cs.text, strBuffer, (len + 1)*sizeof(wchar_t));
} else {
cs.text = new wchar_t[1];
cs.text[0] = 0;
if(const char* text = (const char*)sqlite3_column_text(pStmt, 12)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.name = strBuffer;
}
for(int i = 14; i < 30; ++i) {
len = BufferIO::DecodeUTF8((const char*)sqlite3_column_text(pStmt, i), strBuffer);
if(len) {
cs.desc[i - 14] = new wchar_t[len + 1];
memcpy(cs.desc[i - 14], strBuffer, (len + 1)*sizeof(wchar_t));
} else cs.desc[i - 14] = 0;
if(const char* text = (const char*)sqlite3_column_text(pStmt, 13)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.text = strBuffer;
}
_strings.insert(std::make_pair(cd.code, cs));
for(int i = 0; i < 16; ++i) {
if(const char* text = (const char*)sqlite3_column_text(pStmt, i + 14)) {
BufferIO::DecodeUTF8(text, strBuffer);
cs.desc[i] = strBuffer;
}
}
_strings.emplace(cd.code, cs);
}
} while(step != SQLITE_DONE);
sqlite3_finalize(pStmt);
......@@ -126,8 +119,8 @@ code_pointer DataManager::GetCodePointer(int code) {
bool DataManager::GetString(int code, CardString* pStr) {
auto csit = _strings.find(code);
if(csit == _strings.end()) {
pStr->name = (wchar_t*)unknown_string;
pStr->text = (wchar_t*)unknown_string;
pStr->name = unknown_string;
pStr->text = unknown_string;
return false;
}
*pStr = csit->second;
......@@ -137,16 +130,16 @@ const wchar_t* DataManager::GetName(int code) {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.name)
return csit->second.name;
if(!csit->second.name.empty())
return csit->second.name.c_str();
return unknown_string;
}
const wchar_t* DataManager::GetText(int code) {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.text)
return csit->second.text;
if(!csit->second.text.empty())
return csit->second.text.c_str();
return unknown_string;
}
const wchar_t* DataManager::GetDesc(int strCode) {
......@@ -157,8 +150,8 @@ const wchar_t* DataManager::GetDesc(int strCode) {
auto csit = _strings.find(code);
if(csit == _strings.end())
return unknown_string;
if(csit->second.desc[offset])
return csit->second.desc[offset];
if(!csit->second.desc[offset].empty())
return csit->second.desc[offset].c_str();
return unknown_string;
}
const wchar_t* DataManager::GetSysString(int code) {
......
......@@ -848,12 +848,12 @@ void DeckBuilder::FilterCards() {
}
if(pstr) {
if(pstr[0] == L'$') {
if(!CardNameContains(text.name, &pstr[1]))
if(!CardNameContains(text.name.c_str(), &pstr[1]))
continue;
} else if(pstr[0] == L'@' && set_code) {
if(!check_set_code(data, set_code)) continue;
} else {
if(!CardNameContains(text.name, pstr) && wcsstr(text.text, pstr) == 0
if(!CardNameContains(text.name.c_str(), pstr) && text.text.find(pstr) == std::wstring::npos
&& (!set_code || !check_set_code(data, set_code)))
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment