UString integration done

- now UString works for both Qt (uses QString) and non-Qt (uses modified
CBString) builds
This commit is contained in:
Nikolaj Schlej 2016-07-05 16:18:55 +02:00
parent 9bd71281b9
commit 804a55ba64
8 changed files with 20 additions and 19 deletions

View File

@ -79,7 +79,7 @@ USTATUS FfsDumper::recursiveDump(const UModelIndex & index, const UString & path
if (!file.open(QFile::Text | QFile::WriteOnly)) if (!file.open(QFile::Text | QFile::WriteOnly))
return U_FILE_OPEN; return U_FILE_OPEN;
file.write(info); file.write(info.toLocal8Bit());
file.close(); file.close();
dumped = true; dumped = true;
} }

View File

@ -62,7 +62,7 @@ int main(int argc, char *argv[])
// Show ffsParser's messages // Show ffsParser's messages
std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages(); std::vector<std::pair<UString, UModelIndex> > messages = ffsParser.getMessages();
for (size_t i = 0; i < messages.size(); i++) { for (size_t i = 0; i < messages.size(); i++) {
std::cout << messages[i].first << std::endl; std::cout << (const char*)messages[i].first.toLocal8Bit() << std::endl;
} }
// Get last VTF // Get last VTF
@ -76,7 +76,7 @@ int main(int argc, char *argv[])
// Show fitParser's messages // Show fitParser's messages
std::vector<std::pair<UString, UModelIndex> > fitMessages = fitParser.getMessages(); std::vector<std::pair<UString, UModelIndex> > fitMessages = fitParser.getMessages();
for (size_t i = 0; i < fitMessages.size(); i++) { for (size_t i = 0; i < fitMessages.size(); i++) {
std::cout << fitMessages[i].first << std::endl; std::cout << (const char*)fitMessages[i].first.toLocal8Bit() << std::endl;
} }
// Show FIT table // Show FIT table
@ -86,11 +86,11 @@ int main(int argc, char *argv[])
std::cout << " Address | Size | Ver | Type | CS " << std::endl; std::cout << " Address | Size | Ver | Type | CS " << std::endl;
std::cout << "-------------------------------------------------------------------" << std::endl; std::cout << "-------------------------------------------------------------------" << std::endl;
for (size_t i = 0; i < fitTable.size(); i++) { for (size_t i = 0; i < fitTable.size(); i++) {
std::cout << fitTable[i][0] << " | " std::cout << (const char*)fitTable[i][0].toLocal8Bit() << " | "
<< fitTable[i][1] << " | " << (const char*)fitTable[i][1].toLocal8Bit() << " | "
<< fitTable[i][2] << " | " << (const char*)fitTable[i][2].toLocal8Bit() << " | "
<< fitTable[i][3] << " | " << (const char*)fitTable[i][3].toLocal8Bit() << " | "
<< fitTable[i][4] << std::endl; << (const char*)fitTable[i][4].toLocal8Bit() << std::endl;
} }
} }
} }
@ -103,7 +103,7 @@ int main(int argc, char *argv[])
std::ofstream ofs; std::ofstream ofs;
ofs.open("report.txt", std::ofstream::out); ofs.open("report.txt", std::ofstream::out);
for (size_t i = 0; i < report.size(); i++) { for (size_t i = 0; i < report.size(); i++) {
ofs << report[i] << std::endl; ofs << (const char*)report[i].toLocal8Bit() << std::endl;
} }
ofs.close(); ofs.close();
} }

View File

@ -903,7 +903,7 @@ struct tagbstring t;
return bninchrr ((bstring) this, pos, &t); return bninchrr ((bstring) this, pos, &t);
} }
const CBString CBString::midstr (int left, int len) const { CBString CBString::midstr (int left, int len) const {
struct tagbstring t; struct tagbstring t;
if (left < 0) { if (left < 0) {
len += left; len += left;

View File

@ -317,7 +317,7 @@ struct CBString : public tagbstring {
void findreplacecaseless (const char * find, const char * repl, int pos = 0); void findreplacecaseless (const char * find, const char * repl, int pos = 0);
// Extraction method. // Extraction method.
const CBString midstr (int left, int len) const; CBString midstr (int left, int len) const;
// Standard manipulation methods. // Standard manipulation methods.
void setsubstr (int pos, const CBString& b, unsigned char fill = ' '); void setsubstr (int pos, const CBString& b, unsigned char fill = ' ');
@ -362,8 +362,11 @@ struct CBString : public tagbstring {
int read (bNread readPtr, void * parm); int read (bNread readPtr, void * parm);
// QString compatibility methods // QString compatibility methods
CBString toLocal8Bit() { return *this; }
bool isEmpty() const { return slen == 0; } bool isEmpty() const { return slen == 0; }
void clear() { *this = ""; } void clear() { *this = ""; }
CBString left(int len) { return midstr(0, len); }
CBString mid(int pos, int len) { return midstr(pos, len); }
static CBString fromUtf16(const ushort* str) { // Naive implementation assuming that only ASCII part of UCS2 is used static CBString fromUtf16(const ushort* str) { // Naive implementation assuming that only ASCII part of UCS2 is used
CBString msg; while (*str) { msg += *(char*)str; str++; } return msg; CBString msg; while (*str) { msg += *(char*)str; str++; } return msg;
} }

View File

@ -4137,8 +4137,8 @@ USTATUS FfsParser::parseSlicMarkerHeader(const UByteArray & store, const UINT32
markerHeader->Size, markerHeader->Size, markerHeader->Size, markerHeader->Size,
header.size(), header.size(), header.size(), header.size(),
markerHeader->Version, markerHeader->Version,
(const char*)UString((const char*)&(markerHeader->OemId), 6), (const char*)UString((const char*)&(markerHeader->OemId)).left(6).toLocal8Bit(),
(const char*)UString((const char*)&(markerHeader->OemTableId), 8), (const char*)UString((const char*)&(markerHeader->OemTableId)).left(8).toLocal8Bit(),
markerHeader->SlicVersion); markerHeader->SlicVersion);
// Add correct offset // Add correct offset

View File

@ -44,9 +44,9 @@ QVariant TreeModel::data(const UModelIndex &index, int role) const
TreeItem *item = static_cast<TreeItem*>(index.internalPointer()); TreeItem *item = static_cast<TreeItem*>(index.internalPointer());
if (role == Qt::DisplayRole) if (role == Qt::DisplayRole)
return (const char*)item->data(index.column()); return (const char*)item->data(index.column()).toLocal8Bit();
else else
return (const char*)item->info(); return (const char*)item->info().toLocal8Bit();
} }
Qt::ItemFlags TreeModel::flags(const UModelIndex &index) const Qt::ItemFlags TreeModel::flags(const UModelIndex &index) const

View File

@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
//TODO: modify properly //TODO: modify properly
#ifndef QT_CORE_LIB #if defined(QT_CORE_LIB) && defined (U_USE_QSTRING)
UString usprintf(const char* fmt, ...) UString usprintf(const char* fmt, ...)
{ {
UString msg; UString msg;

View File

@ -13,9 +13,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#ifndef USTRING_H #ifndef USTRING_H
#define USTRING_H #define USTRING_H
//TODO: modify properly #if defined (QT_CORE_LIB) && defined(U_USE_QSTRING)
#ifndef QT_CORE_LIB
// Use Qt class, if Qt is available // Use Qt class, if Qt is available
#include <QString> #include <QString>
#define UString QString #define UString QString