From 70fd2c3ce096a2a7a9642b7a83723d7f36088c41 Mon Sep 17 00:00:00 2001 From: leozide Date: Tue, 7 Feb 2017 18:55:54 -0800 Subject: [PATCH] Removed old string class. --- common/lc_application.cpp | 4 +- common/lc_application.h | 3 +- common/lc_category.cpp | 139 ++++++++++- common/lc_category.h | 7 +- common/lc_library.cpp | 54 +---- common/lc_library.h | 6 +- common/lc_partselectionwidget.cpp | 2 +- common/str.cpp | 384 ------------------------------ common/str.h | 158 ------------ leocad.pro | 2 - qt/lc_qcategorydialog.cpp | 4 +- qt/lc_qpreferencesdialog.cpp | 8 +- 12 files changed, 164 insertions(+), 607 deletions(-) delete mode 100644 common/str.cpp delete mode 100644 common/str.h diff --git a/common/lc_application.cpp b/common/lc_application.cpp index 33852a25..34ea8f4d 100644 --- a/common/lc_application.cpp +++ b/common/lc_application.cpp @@ -81,7 +81,7 @@ void lcApplication::ExportClipboard(const QByteArray& Clipboard) SetClipboard(Clipboard); } -void lcApplication::GetFileList(const char* Path, lcArray& FileList) +void lcApplication::GetFileList(const char* Path, lcArray& FileList) { QDir Dir(Path); Dir.setFilter(QDir::Files | QDir::Hidden | QDir::Readable); @@ -93,7 +93,7 @@ void lcApplication::GetFileList(const char* Path, lcArray& FileList) { QString AbsolutePath = Dir.absoluteFilePath(Files[FileIdx]); - FileList.Add(AbsolutePath.toLocal8Bit().data()); + FileList.Add(AbsolutePath.toStdString()); } } diff --git a/common/lc_application.h b/common/lc_application.h index f6490809..085fb1c6 100644 --- a/common/lc_application.h +++ b/common/lc_application.h @@ -5,7 +5,6 @@ class Project; class lcPiecesLibrary; -class String; enum lcLightingMode { @@ -48,7 +47,7 @@ public: bool LoadPiecesLibrary(const char* LibPath, const char* LibraryInstallPath, const char* LDrawPath); - void GetFileList(const char* Path, lcArray& FileList); + void GetFileList(const char* Path, lcArray& FileList); void SetClipboard(const QByteArray& Clipboard); void ExportClipboard(const QByteArray& Clipboard); diff --git a/common/lc_category.cpp b/common/lc_category.cpp index 798dbb0f..7bd8e60a 100644 --- a/common/lc_category.cpp +++ b/common/lc_category.cpp @@ -143,10 +143,147 @@ bool lcSaveCategories(QTextStream& Stream, const lcArray& Cat for (int CategoryIdx = 0; CategoryIdx < Categories.GetSize(); CategoryIdx++) { const lcLibraryCategory& Category = Categories[CategoryIdx]; - Stream << Format.arg((const char*)Category.Name, (const char*)Category.Keywords); + Stream << Format.arg(Category.Name.c_str(), Category.Keywords.c_str()); } Stream.flush(); return true; } + +bool lcMatchCategory(const char* PieceName, const char* Expression) +{ + // Check if we need to split the test expression. + const char* p = Expression; + + while (*p) + { + if (*p == '!') + { + return !lcMatchCategory(PieceName, p + 1); + } + else if (*p == '(') + { +// const char* Start = p; + int c = 0; + + // Skip what's inside the parenthesis. + do + { + if (*p == '(') + c++; + else if (*p == ')') + c--; + else if (*p == 0) + return false; // Mismatched parenthesis. + + p++; + } + while (c); + + if (*p == 0) + break; + } + else if ((*p == '|') || (*p == '&')) + { + std::string LeftStr(Expression, (p - Expression) - 1); + std::string RightStr(p + 1); + + if (*p == '|') + return lcMatchCategory(PieceName, LeftStr.c_str()) || lcMatchCategory(PieceName, RightStr.c_str()); + else + return lcMatchCategory(PieceName, LeftStr.c_str()) && lcMatchCategory(PieceName, RightStr.c_str()); + } + + p++; + } + + if (strchr(Expression, '(')) + { + p = Expression; + while (*p) + { + if (*p == '(') + { + const char* Start = p; + int c = 0; + + // Extract what's inside the parenthesis. + do + { + if (*p == '(') + c++; + else if (*p == ')') + c--; + else if (*p == 0) + return false; // Mismatched parenthesis. + + p++; + } + while (c); + + std::string SubExpression(Start + 1, p - Start - 2); + return lcMatchCategory(PieceName, SubExpression.c_str()); + } + + p++; + } + } + + const char* SearchStart = Expression; + while (isspace(*SearchStart)) + SearchStart++; + + const char* SearchEnd = SearchStart + strlen(SearchStart) - 1; + while (SearchEnd >= SearchStart && isspace(*SearchEnd)) + SearchEnd--; + + // Testing a simple case. + std::string Search; + if (SearchStart != SearchEnd) + Search = std::string(SearchStart, SearchEnd - SearchStart + 1); + const char* Word = Search.c_str(); + + // Check for modifiers. + bool WholeWord = 0; + bool Begin = 0; + + for (;;) + { + if (Word[0] == '^') + WholeWord = true; + else if (Word[0] == '%') + Begin = true; + else + break; + + Word++; + } + + const char* Result = strcasestr(PieceName, Word); + + if (!Result) + return false; + + if (Begin && (Result != PieceName)) + { + if ((Result != PieceName + 1) || ((Result[-1] != '_') && (Result[-1] != '~'))) + return false; + } + + if (WholeWord) + { + char End = Result[strlen(Word)]; + + if ((End != 0) && (End != ' ')) + return false; + + if ((Result != PieceName) && ((Result[-1] == '_') || (Result[-1] == '~'))) + Result--; + + if ((Result != PieceName) && (Result[-1] != ' ')) + return false; + } + + return true; +} diff --git a/common/lc_category.h b/common/lc_category.h index a86217d8..502b1aa7 100644 --- a/common/lc_category.h +++ b/common/lc_category.h @@ -1,13 +1,12 @@ #ifndef _LC_CATEGORY_H_ #define _LC_CATEGORY_H_ -#include "str.h" #include "lc_array.h" struct lcLibraryCategory { - String Name; - String Keywords; + std::string Name; + std::string Keywords; }; extern lcArray gCategories; @@ -22,4 +21,6 @@ bool lcLoadCategories(const QByteArray& Buffer, lcArray& Cate bool lcSaveCategories(const QString& FileName, const lcArray& Categories); bool lcSaveCategories(QTextStream& Stream, const lcArray& Categories); +bool lcMatchCategory(const char* PieceName, const char* Expression); + #endif // _LC_CATEGORY_H_ diff --git a/common/lc_library.cpp b/common/lc_library.cpp index 71fe9c0d..9c2c7f8e 100644 --- a/common/lc_library.cpp +++ b/common/lc_library.cpp @@ -424,7 +424,7 @@ void lcPiecesLibrary::ReadArchiveDescriptions(const QString& OfficialFileName, c bool lcPiecesLibrary::OpenDirectory(const char* Path) { char FileName[LC_MAXPATH]; - lcArray FileList; + lcArray FileList; strcpy(FileName, Path); strcat(FileName, "parts.lst"); @@ -501,7 +501,7 @@ bool lcPiecesLibrary::OpenDirectory(const char* Path) for (int FileIdx = 0; FileIdx < FileList.GetSize(); FileIdx++) { char Name[LC_PIECE_NAME_LEN]; - const char* Src = (const char*)FileList[FileIdx] + PathLength; + const char* Src = (const char*)FileList[FileIdx].c_str() + PathLength; char* Dst = Name; while (*Src && Dst - Name < (int)sizeof(Name)) @@ -526,7 +526,7 @@ bool lcPiecesLibrary::OpenDirectory(const char* Path) *Dst = 0; lcDiskFile PieceFile; - if (!PieceFile.Open(FileList[FileIdx], "rt")) + if (!PieceFile.Open(FileList[FileIdx].c_str(), "rt")) continue; char Line[1024]; @@ -575,7 +575,7 @@ bool lcPiecesLibrary::OpenDirectory(const char* Path) for (int FileIdx = 0; FileIdx < FileList.GetSize(); FileIdx++) { char Name[LC_PIECE_NAME_LEN]; - const char* Src = (const char*)FileList[FileIdx] + PathLength; + const char* Src = (const char*)FileList[FileIdx].c_str() + PathLength; char* Dst = Name; while (*Src && Dst - Name < (int)sizeof(Name)) @@ -616,7 +616,7 @@ bool lcPiecesLibrary::OpenDirectory(const char* Path) for (int FileIdx = 0; FileIdx < FileList.GetSize(); FileIdx++) { char Name[LC_MAXPATH]; - const char* Src = (const char*)FileList[FileIdx] + PathLength; + const char* Src = (const char*)FileList[FileIdx].c_str() + PathLength; char* Dst = Name; while (*Src && Dst - Name < (int)sizeof(Name)) @@ -2450,31 +2450,27 @@ void lcLibraryMeshData::AddMeshDataNoDuplicateCheck(const lcLibraryMeshData& Dat } } -bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const +bool lcPiecesLibrary::PieceInCategory(PieceInfo* Info, const char* CategoryKeywords) const { if (Info->IsTemporary()) return false; - String PieceName; + const char* PieceName; if (Info->m_strDescription[0] == '~' || Info->m_strDescription[0] == '_') PieceName = Info->m_strDescription + 1; else PieceName = Info->m_strDescription; - PieceName.MakeLower(); - String Keywords = CategoryKeywords; - Keywords.MakeLower(); - - return PieceName.Match(Keywords); + return lcMatchCategory(PieceName, CategoryKeywords); } void lcPiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) { if (CategoryIndex >= 0 && CategoryIndex < gCategories.GetSize()) - GetCategoryEntries(gCategories[CategoryIndex].Keywords, GroupPieces, SinglePieces, GroupedPieces); + GetCategoryEntries(gCategories[CategoryIndex].Keywords.c_str(), GroupPieces, SinglePieces, GroupedPieces); } -void lcPiecesLibrary::GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) +void lcPiecesLibrary::GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces) { SinglePieces.RemoveAll(); GroupedPieces.RemoveAll(); @@ -2534,36 +2530,6 @@ void lcPiecesLibrary::GetCategoryEntries(const String& CategoryKeywords, bool Gr } } -void lcPiecesLibrary::SearchPieces(const char* Keyword, lcArray& Pieces) const -{ - Pieces.RemoveAll(); - - String LowerKeyword = Keyword; - LowerKeyword.MakeLower(); - - for (int PieceIdx = 0; PieceIdx < mPieces.GetSize(); PieceIdx++) - { - PieceInfo* Info = mPieces[PieceIdx]; - - char LowerName[sizeof(Info->m_strName)]; - strcpy(LowerName, Info->m_strName); - strlwr(LowerName); - - if (strstr(LowerName, LowerKeyword)) - { - Pieces.Add(Info); - continue; - } - - char LowerDescription[sizeof(Info->m_strDescription)]; - strcpy(LowerDescription, Info->m_strDescription); - strlwr(LowerDescription); - - if (strstr(LowerDescription, LowerKeyword)) - Pieces.Add(Info); - } -} - void lcPiecesLibrary::GetPatternedPieces(PieceInfo* Parent, lcArray& Pieces) const { char Name[LC_PIECE_NAME_LEN]; diff --git a/common/lc_library.h b/common/lc_library.h index b5e79d3d..5b8d05c0 100644 --- a/common/lc_library.h +++ b/common/lc_library.h @@ -5,7 +5,6 @@ #include "lc_mesh.h" #include "lc_math.h" #include "lc_array.h" -#include "str.h" class PieceInfo; class lcZipFile; @@ -147,10 +146,9 @@ public: lcTexture* FindTexture(const char* TextureName); bool LoadTexture(lcTexture* Texture); - bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const; - void SearchPieces(const char* Keyword, lcArray& Pieces) const; + bool PieceInCategory(PieceInfo* Info, const char* CategoryKeywords) const; void GetCategoryEntries(int CategoryIndex, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); - void GetCategoryEntries(const String& CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); + void GetCategoryEntries(const char* CategoryKeywords, bool GroupPieces, lcArray& SinglePieces, lcArray& GroupedPieces); void GetPatternedPieces(PieceInfo* Parent, lcArray& Pieces) const; void GetParts(lcArray& Parts); diff --git a/common/lc_partselectionwidget.cpp b/common/lc_partselectionwidget.cpp index e2894798..b5a9f6b1 100644 --- a/common/lc_partselectionwidget.cpp +++ b/common/lc_partselectionwidget.cpp @@ -721,7 +721,7 @@ void lcPartSelectionWidget::UpdateCategories() mCurrentModelCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Parts In Use"))); for (int CategoryIdx = 0; CategoryIdx < gCategories.GetSize(); CategoryIdx++) - new QTreeWidgetItem(mCategoriesWidget, QStringList((const char*)gCategories[CategoryIdx].Name)); + new QTreeWidgetItem(mCategoriesWidget, QStringList(QString::fromStdString(gCategories[CategoryIdx].Name))); mModelsCategoryItem = new QTreeWidgetItem(mCategoriesWidget, QStringList(tr("Models"))); diff --git a/common/str.cpp b/common/str.cpp deleted file mode 100644 index a17246f6..00000000 --- a/common/str.cpp +++ /dev/null @@ -1,384 +0,0 @@ -// -// General purpose string class -// - -#include "lc_global.h" -#include -#include "str.h" - -static String aux; - -// ============================================================================= -// Construction / Destruction - -String::String () -{ - m_pData = new char[1]; - m_pData[0] = '\0'; -} - -String::~String () -{ - delete []m_pData; -} - -// ============================================================================= -// Operators - -const String& String::operator= (const String& src) -{ - delete []m_pData; - m_pData = new char[src.GetLength () + 1]; - strcpy (m_pData, src.m_pData); - return *this; -} - -const String& String::operator= (char ch) -{ - delete []m_pData; - m_pData = new char[2]; - m_pData[0] = ch; - m_pData[1] = '\0'; - return *this; -} - -const String& String::operator= (const char *src) -{ - delete []m_pData; - m_pData = new char[strlen (src) + 1]; - strcpy (m_pData, src); - return *this; -} - -const String& String::operator+= (const String& src) -{ - char *tmp = new char[GetLength () + src.GetLength () + 1]; - strcpy (tmp, m_pData); - strcat (tmp, src.m_pData); - delete []m_pData; - m_pData = tmp; - return *this; -} - -const String& String::operator+= (char ch) -{ - size_t len = GetLength (); - char *tmp = new char[len + 1 + 1]; - strcpy (tmp, m_pData); - tmp[len] = ch; - tmp[len+1] = '\0'; - delete []m_pData; - m_pData = tmp; - return *this; -} - -const String& String::operator+= (const char *src) -{ - char *tmp = new char[GetLength () + strlen (src) + 1]; - strcpy (tmp, m_pData); - strcat (tmp, src); - delete []m_pData; - m_pData = tmp; - return *this; -} - -// ============================================================================= -// Non-member operators - -String& operator+ (const String& string1, const String& string2) -{ - String s; - s = string1; - s += string2; - aux = s; - return aux; -} - -String& operator+ (const String& string, char ch) -{ - String s; - s = string; - s += ch; - aux = s; - return aux; -} - -String& operator+ (char ch, const String& string) -{ - String s; - s = ch; - s += string; - aux = s; - return aux; -} - -String& operator+ (const String& string1, const char *string2) -{ - String s; - s = string1; - s += string2; - aux = s; - return aux; -} - -String& operator+ (const char *string1, const String& string2) -{ - String s; - s = string1; - s += string2; - aux = s; - return aux; -} - -// ============================================================================= -// Sub-string extraction - -String& String::Mid (int first, int count) const -{ - if (count < 0) - count = 0; - else if (count > (int)GetLength ()) - count = (int)GetLength (); - - String s; - strncpy (s.GetBuffer (count+1), m_pData + first, count); - s.m_pData[count] = '\0'; - aux = s; - - return aux; -} - -String& String::Left (int count) const -{ - if (count < 0) - count = 0; - else if (count > (int)GetLength ()) - count = (int)GetLength (); - - String s; - strncpy (s.GetBuffer (count+1), m_pData, count); - s.m_pData[count] = '\0'; - aux = s; - - return aux; -} - -String& String::Right (int count) const -{ - if (count < 0) - count = 0; - else if (count > (int)GetLength ()) - count = (int)GetLength (); - - String s; - strncpy (s.GetBuffer (count+1), m_pData + GetLength () - count, count); - s.m_pData[count] = '\0'; - aux = s; - - return aux; -} - -// ============================================================================= -// Other functions - -// Evaluates the contents of the string against a boolean expression. -// For example: (^Car | %Animal) & !Parrot -// Will return true for any strings that have the Car word or -// begin with Animal and do not have the word Parrot. -bool String::Match(const String& Expression) const -{ - // Check if we need to split the test expression. - const char* p = Expression; - - while (*p) - { - if (*p == '!') - { - return !Match(String(p + 1)); - } - else if (*p == '(') - { -// const char* Start = p; - int c = 0; - - // Skip what's inside the parenthesis. - do - { - if (*p == '(') - c++; - else if (*p == ')') - c--; - else if (*p == 0) - return false; // Mismatched parenthesis. - - p++; - } - while (c); - - if (*p == 0) - break; - } - else if ((*p == '|') || (*p == '&')) - { - String LeftStr, RightStr; - - LeftStr = Expression.Left((p - Expression) - 1); - RightStr = Expression.Right((int)Expression.GetLength() - (p - Expression) - 1); - - if (*p == '|') - return Match(LeftStr) || Match(RightStr); - else - return Match(LeftStr) && Match(RightStr); - } - - p++; - } - - if (Expression.Find('(') != -1) - { - p = Expression; - while (*p) - { - if (*p == '(') - { - const char* Start = p; - int c = 0; - - // Extract what's inside the parenthesis. - do - { - if (*p == '(') - c++; - else if (*p == ')') - c--; - else if (*p == 0) - return false; // Mismatched parenthesis. - - p++; - } - while (c); - - String Expr = Expression.Mid(Start - Expression + 1, p - Start - 2); - return Match(Expr); - } - - p++; - } - } - - // Testing a simple case. - String Search = Expression; - Search.TrimRight(); - Search.TrimLeft(); - - const char* Word = Search; - - // Check for modifiers. - bool WholeWord = 0; - bool Begin = 0; - - for (;;) - { - if (Word[0] == '^') - WholeWord = true; - else if (Word[0] == '%') - Begin = true; - else - break; - - Word++; - } - - int Result = Find(Word); - - if (Result == -1) - return false; - - if (Begin && (Result != 0)) - { - if ((Result != 1) || ((GetAt(Result-1) != '_') && (GetAt(Result-1) != '~'))) - return false; - } - - if (WholeWord) - { - char End = GetAt(Result + (int)strlen(Word)); - - if ((End != 0) && (End != ' ')) - return false; - - if ((Result != 0) && ((GetAt(Result-1) == '_') || (GetAt(Result-1) == '~'))) - Result--; - - if ((Result != 0) && (GetAt(Result-1) != ' ')) - return false; - } - - return true; -} - -int String::CompareNoCase (const char *string) const -{ - char c1, c2, *ch = m_pData; - while (*ch && *string) - { - c1 = tolower (*ch); - c2 = tolower (*string); - if (c1 != c2) - return (c1 - c2); - ch++; string++; - } - return (((int)*ch) - ((int)*string)); -} - -int String::CompareNoCase(const char *string, int count) const -{ - char c1, c2, *ch = m_pData; - - while (*ch && *string) - { - c1 = tolower (*ch); - c2 = tolower (*string); - - if (c1 != c2) - return (c1 - c2); - - ch++; - string++; - count--; - - if (!count) - return 0; - } - - return (((int)*ch) - ((int)*string)); -} - -void String::MakeUpper () -{ - for (char *cp = m_pData; *cp; ++cp) - if ('a' <= *cp && *cp <= 'z') - *cp += 'A' - 'a'; -} - -void String::MakeLower () -{ - for (char *cp = m_pData; *cp; ++cp) - if ('A' <= *cp && *cp <= 'Z') - *cp += 'a' - 'A'; -} - -void String::TrimRight () -{ - for (char *s = m_pData + strlen (m_pData) - 1; s >= m_pData && isspace (*s); s--) - *s = '\0'; -} - -void String::TrimLeft () -{ - char *ch; - ch = m_pData; - while (isspace (*ch)) - ch++; - memmove (m_pData, ch, strlen (ch)+1); -} diff --git a/common/str.h b/common/str.h deleted file mode 100644 index c6d57933..00000000 --- a/common/str.h +++ /dev/null @@ -1,158 +0,0 @@ -#ifndef _STR_H_ -#define _STR_H_ - -#include - -class String -{ -public: - String(); - String(const String& src) - { m_pData = NULL; *this = src; } - String(const char* str) - { m_pData = NULL; *this = str; } - ~String(); - - size_t GetLength() const - { return strlen(m_pData); } - bool IsEmpty() const - { return m_pData[0] == '\0'; } - void Empty() - { m_pData[0] = '\0'; } - - char GetAt(int index) const - { return m_pData[index]; } - char& operator[](int index) const - { return m_pData[index]; } - void SetAt(int index, char ch) - { m_pData[index] = ch; } - operator char*() const - { return m_pData; } - operator const char*() const - { return m_pData; } - - // Operators - const String& operator=(const String& src); - const String& operator=(char ch); - const String& operator=(const char *src); - const String& operator+=(const String& string); - const String& operator+=(char ch); - const String& operator+=(const char *src); - - // Comparison - int Compare(const char *string) const - { return strcmp(m_pData, string); } - int CompareNoCase(const char *string) const; - int CompareNoCase(const char *string, int count) const; - bool Match(const String& Expression) const; - - // simple sub-string extraction - String& Mid(int first, int count) const; - String& Left(int count) const; - String& Right(int count) const; - - // upper/lower/reverse conversion - void MakeUpper(); - void MakeLower(); - - // trimming whitespace (either side) - void TrimRight(); - void TrimLeft(); - - // searching (return starting index, or -1 if not found) - // look for a single character match - int Find(char ch) const - { - char *pf = strchr(m_pData, ch); - return (pf) ? (pf - m_pData) : -1; - } - int ReverseFind(char ch) const - { - char *pf = strrchr(m_pData, ch); - return (pf) ? (pf - m_pData) : -1; - } - int FindOneOf(const char *set) const - { - char *pf = strpbrk(m_pData, set); - return (pf) ? (pf - m_pData) : -1; - } - - // look for a specific sub-string - int Find(const char *str) const - { - char *pf = strstr(m_pData, str); - return (pf) ? (pf - m_pData) : -1; - } - - char* Buffer() - { - return m_pData; - } - - const char* Buffer() const - { - return m_pData; - } - - char* GetBuffer(int len) - { - if (len > (int)strlen(m_pData)) - { - char *tmp = new char[len+1]; - strcpy(tmp, m_pData); - delete []m_pData; - m_pData = tmp; - } - return m_pData; - } - -protected: - char* m_pData; -}; - -// Concatenation operators -String& operator+(const String& string1, const String& string2); -String& operator+(const String& string, char ch); -String& operator+(char ch, const String& string); -String& operator+(const String& string1, const char *string2); -String& operator+(const char *string1, const String& string2); - -// Comparison operators -inline bool operator==(const String& s1, const String& s2) -{ return s1.Compare(s2) == 0; } -inline bool operator==(const String& s1, const char *s2) -{ return s1.Compare(s2) == 0; } -inline bool operator==(const char *s1, const String& s2) -{ return s2.Compare(s1) == 0; } -inline bool operator!=(const String& s1, const String& s2) -{ return s1.Compare(s2) != 0; } -inline bool operator!=(const String& s1, const char *s2) -{ return s1.Compare(s2) != 0; } -inline bool operator!=(const char *s1, const String& s2) -{ return s2.Compare(s1) != 0; } -inline bool operator<(const String& s1, const String& s2) -{ return s1.Compare(s2) < 0; } -inline bool operator<(const String& s1, const char *s2) -{ return s1.Compare(s2) < 0; } -inline bool operator<(const char *s1, const String& s2) -{ return s2.Compare(s1) > 0; } -inline bool operator>(const String& s1, const String& s2) -{ return s1.Compare(s2) > 0; } -inline bool operator>(const String& s1, const char *s2) -{ return s1.Compare(s2) > 0; } -inline bool operator>(const char *s1, const String& s2) -{ return s2.Compare(s1) < 0; } -inline bool operator<=(const String& s1, const String& s2) -{ return s1.Compare(s2) <= 0; } -inline bool operator<=(const String& s1, const char *s2) -{ return s1.Compare(s2) <= 0; } -inline bool operator<=(const char *s1, const String& s2) -{ return s2.Compare(s1) >= 0; } -inline bool operator>=(const String& s1, const String& s2) -{ return s1.Compare(s2) >= 0; } -inline bool operator>=(const String& s1, const char *s2) -{ return s1.Compare(s2) >= 0; } -inline bool operator>=(const char *s1, const String& s2) -{ return s2.Compare(s1) <= 0; } - -#endif // _STR_H_ diff --git a/leocad.pro b/leocad.pro index 901143cf..d0138af6 100644 --- a/leocad.pro +++ b/leocad.pro @@ -126,7 +126,6 @@ macx { SOURCES += common/view.cpp \ common/tr.cpp \ common/texfont.cpp \ - common/str.cpp \ common/project.cpp \ common/pieceinf.cpp \ common/piece.cpp \ @@ -182,7 +181,6 @@ HEADERS += \ common/tr.h \ common/texfont.h \ common/system.h \ - common/str.h \ common/project.h \ common/pieceinf.h \ common/piece.h \ diff --git a/qt/lc_qcategorydialog.cpp b/qt/lc_qcategorydialog.cpp index 35a3eb9b..daf8bcc9 100644 --- a/qt/lc_qcategorydialog.cpp +++ b/qt/lc_qcategorydialog.cpp @@ -16,8 +16,8 @@ lcQCategoryDialog::lcQCategoryDialog(QWidget *parent, void *data) : else setWindowTitle(tr("New Category")); - ui->name->setText((const char*)options->Name); - ui->keywords->setText((const char*)options->Keywords); + ui->name->setText(QString::fromStdString(options->Name)); + ui->keywords->setText(QString::fromStdString(options->Keywords)); } lcQCategoryDialog::~lcQCategoryDialog() diff --git a/qt/lc_qpreferencesdialog.cpp b/qt/lc_qpreferencesdialog.cpp index 78fdf778..1257d272 100644 --- a/qt/lc_qpreferencesdialog.cpp +++ b/qt/lc_qpreferencesdialog.cpp @@ -210,7 +210,7 @@ void lcQPreferencesDialog::updateCategories() for (int categoryIndex = 0; categoryIndex < options->Categories.GetSize(); categoryIndex++) { - categoryItem = new QTreeWidgetItem(tree, QStringList((const char*)options->Categories[categoryIndex].Name)); + categoryItem = new QTreeWidgetItem(tree, QStringList(QString::fromStdString(options->Categories[categoryIndex].Name))); categoryItem->setData(0, CategoryRole, QVariant(categoryIndex)); } @@ -237,7 +237,7 @@ void lcQPreferencesDialog::updateParts() { lcArray singleParts, groupedParts; - library->GetCategoryEntries(options->Categories[categoryIndex].Keywords, false, singleParts, groupedParts); + library->GetCategoryEntries(options->Categories[categoryIndex].Keywords.c_str(), false, singleParts, groupedParts); for (int partIndex = 0; partIndex < singleParts.GetSize(); partIndex++) { @@ -257,7 +257,7 @@ void lcQPreferencesDialog::updateParts() for (categoryIndex = 0; categoryIndex < options->Categories.GetSize(); categoryIndex++) { - if (library->PieceInCategory(info, options->Categories[categoryIndex].Keywords)) + if (library->PieceInCategory(info, options->Categories[categoryIndex].Keywords.c_str())) break; } @@ -328,7 +328,7 @@ void lcQPreferencesDialog::on_deleteCategory_clicked() if (categoryIndex == -1) return; - QString question = tr("Are you sure you want to delete the category '%1'?").arg((const char*)options->Categories[categoryIndex].Name); + QString question = tr("Are you sure you want to delete the category '%1'?").arg(QString::fromStdString(options->Categories[categoryIndex].Name)); if (QMessageBox::question(this, "LeoCAD", question, QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes) return;