diff options
author | Michele Calgaro <[email protected]> | 2023-07-03 18:04:26 +0900 |
---|---|---|
committer | Michele Calgaro <[email protected]> | 2023-07-03 18:04:26 +0900 |
commit | b2480185f5b5f75f3398e5d718e53ec5a3767b2b (patch) | |
tree | b50b55506088dbfd209afe7f5bab65250de526f5 /conduits | |
parent | f060f38e3d74c72345c416ec422a3d4b4a766a4e (diff) | |
download | kpilot-b2480185f5b5f75f3398e5d718e53ec5a3767b2b.tar.gz kpilot-b2480185f5b5f75f3398e5d718e53ec5a3767b2b.zip |
Fix functionality broken by commit a956e3e
Signed-off-by: Michele Calgaro <[email protected]>
Diffstat (limited to 'conduits')
-rw-r--r-- | conduits/docconduit/DOC-converter.cpp | 70 | ||||
-rw-r--r-- | conduits/docconduit/DOC-converter.h | 25 |
2 files changed, 57 insertions, 38 deletions
diff --git a/conduits/docconduit/DOC-converter.cpp b/conduits/docconduit/DOC-converter.cpp index 8adaf50..e5fa8a4 100644 --- a/conduits/docconduit/DOC-converter.cpp +++ b/conduits/docconduit/DOC-converter.cpp @@ -71,7 +71,6 @@ bool operator== ( const docBookmark &s1, const docBookmark &s2) int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) { FUNCTIONSETUP; -// bmkList res; int pos = 0, nr=0, found=0; #ifdef DEBUG DEBUGKPILOT<<"Finding matches of "<<pattern<<endl; @@ -86,7 +85,7 @@ int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) { { ++found; if (found>=from && found<=to) { - fBookmarks.append(new docBookmark(pattern, pos)); + fBookmarks.push_back(new docBookmark(pattern, pos)); ++nr; } @@ -101,7 +100,6 @@ int docMatchBookmark::findMatches(TQString doctext, bmkList &fBookmarks) { int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks) { FUNCTIONSETUP; -// bmkList res; TQRegExp rx(pattern); int pos = 0, nr=0, found=0; @@ -114,7 +112,7 @@ int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks) ++found; if (found>=from && found<to) { if (capSubexpression>=0) { - fBookmarks.append(new docBookmark(/*bmkName.left(16)*/rx.cap(capSubexpression), pos)); + fBookmarks.push_back(new docBookmark(/*bmkName.left(16)*/rx.cap(capSubexpression), pos)); } else { // TODO: use the subexpressions from the regexp for the bmk name ($1..$9) (given as separate regexp) TQString bmkText(bmkName); @@ -122,7 +120,7 @@ int docRegExpBookmark::findMatches(TQString doctext, bmkList &fBookmarks) bmkText.replace(CSL1("$%1").arg(i), rx.cap(i)); bmkText.replace(CSL1("\\%1").arg(i), rx.cap(i)); } - fBookmarks.append(new docBookmark(bmkText.left(16), pos)); + fBookmarks.push_back(new docBookmark(bmkText.left(16), pos)); } ++nr; } @@ -148,13 +146,16 @@ DOCConverter::DOCConverter(TQObject *parent, const char *name):TQObject(parent,n FUNCTIONSETUP; docdb=0L; eSortBookmarks=eSortNone; - fBookmarks.setAutoDelete( TRUE ); } DOCConverter::~DOCConverter() { FUNCTIONSETUP; + for (docBookmark *bmk : fBookmarks) + { + delete bmk; + } } @@ -241,7 +242,7 @@ int DOCConverter::findBmkEndtags(TQString &text, bmkList&fBmks) { break; } if (text[pos] == '<') { - fBmks.append(new docMatchBookmark(text.mid(pos + 1, endpos - pos - 1))); + fBmks.push_back(new docMatchBookmark(text.mid(pos + 1, endpos - pos - 1))); ++nr; DEBUGKPILOT<<"Found opening < at position "<<pos<<", bookmarktext ="<<text.mid(pos+1, endpos-pos-1)<<endl; text.remove(pos, text.length()); @@ -257,7 +258,6 @@ int DOCConverter::findBmkEndtags(TQString &text, bmkList&fBmks) { int DOCConverter::findBmkInline(TQString &text, bmkList &fBmks) { FUNCTIONSETUP; -// bmkList res; int nr=0; TQRegExp rx(CSL1("<\\*(.*)\\*>")); @@ -266,7 +266,7 @@ int DOCConverter::findBmkInline(TQString &text, bmkList &fBmks) { while (pos >= 0) { pos = rx.search(text, pos); if (pos >= 0) { - fBmks.append(new docBookmark(rx.cap(1), pos+1)); + fBmks.push_back(new docBookmark(rx.cap(1), pos+1)); ++nr; text = text.remove(pos, rx.matchedLength()); } @@ -315,7 +315,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) { if (fieldnr>1) { TQString name(bmkinfo[1]); DEBUGKPILOT<<"Bookmark \""<<name<<"\" set at position "<<pos<<endl; - fBmks.append(new docBookmark(name, pos)); + fBmks.push_back(new docBookmark(name, pos)); } } else if (bookmark==CSL1("-") || bookmark==CSL1("+")) { if (fieldnr>1) { @@ -349,7 +349,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) { } } } - fBmks.append(bmk); + fBmks.push_back(bmk); bmk=0L; } else { DEBUGKPILOT<<"Could not allocate bookmark "<<name<<endl; @@ -366,7 +366,7 @@ int DOCConverter::findBmkFile(TQString &, bmkList &fBmks) { if (bmk) { bmk->from=1; bmk->to=1; - fBmks.append(bmk); + fBmks.push_back(bmk); } } } // fieldnr>0 @@ -403,10 +403,8 @@ bool DOCConverter::convertTXTtoPDB() { } // Process the bookmarks: find the occurrences of the regexps, and sort them if requested: - bmkSortedList pdbBookmarks; - pdbBookmarks.setAutoDelete(TRUE); - docBookmark*bmk; - for (bmk = fBookmarks.first(); bmk; bmk = fBookmarks.next()) + bmkList pdbBookmarks; + for (docBookmark *bmk : fBookmarks) { bmk->findMatches(text, pdbBookmarks); } @@ -415,12 +413,11 @@ bool DOCConverter::convertTXTtoPDB() { { case eSortName: docBookmark::compare_pos=false; -// qHeapSort(pdbBookmarks); - pdbBookmarks.sort(); + pdbBookmarks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; }); break; case eSortPos: docBookmark::compare_pos=true; - pdbBookmarks.sort(); + pdbBookmarks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; }); break; case eSortNone: default: @@ -429,7 +426,7 @@ bool DOCConverter::convertTXTtoPDB() { #ifdef DEBUG DEBUGKPILOT << "Bookmarks: "<<endl; - for (bmk = pdbBookmarks.first(); bmk; bmk = pdbBookmarks.next()) + for (bmk : pdbBookmarks) { DEBUGKPILOT<<bmk->bmkName.left(20)<<" at position "<<bmk->position<<endl; } @@ -437,6 +434,10 @@ bool DOCConverter::convertTXTtoPDB() { if (!docdb->isOpen()) { emit logError(i18n("Unable to open palm doc database %1").arg(docdb->dbPathName()) ); + for (docBookmark *bmk : pdbBookmarks) + { + delete bmk; + } return false; } @@ -480,8 +481,7 @@ bool DOCConverter::convertTXTtoPDB() { recnum=0; // Finally, write out the bookmarks - for (bmk = pdbBookmarks.first(); bmk; bmk = pdbBookmarks.next()) -// for (bmkList::const_iterator it=pdbBookmarks.begin(); it!=pdbBookmarks.end(); ++it) + for (docBookmark *bmk : pdbBookmarks) { ++recnum; DEBUGKPILOT << "Bookmark #"<<recnum<<", Name="<<bmk->bmkName.left(20)<<", Position="<<bmk->position<<endl; @@ -494,7 +494,15 @@ bool DOCConverter::convertTXTtoPDB() { KPILOT_DELETE(bmkRecord); } + for (docBookmark *bmk : pdbBookmarks) + { + delete bmk; + } pdbBookmarks.clear(); + for (docBookmark *bmk : fBookmarks) + { + delete bmk; + } fBookmarks.clear(); return true; @@ -561,8 +569,7 @@ bool DOCConverter::convertPDBtoTXT() // After the document records possibly come a few bookmark records, so read them in and put them in a separate bookmark file. // for the ztxt conduit there might be annotations after the bookmarks, so the upper bound needs to be adapted. int upperBmkRec=docdb->recordCount(); - bmkSortedList bmks; - bmks.setAutoDelete(TRUE); + bmkList bmks; for (int i=header.numRecords+1; i<upperBmkRec; ++i) { PilotRecord*rec=docdb->readRecordByIndex(i); @@ -570,7 +577,7 @@ bool DOCConverter::convertPDBtoTXT() { PilotDOCBookmark bookie(rec); docBookmark*bmk=new docBookmark(TQString::fromLatin1(bookie.bookmarkName), bookie.pos); - bmks.append(bmk); + bmks.push_back(bmk); KPILOT_DELETE(rec); } else { emit logMessage(i18n("Could not read bookmark record #%1 from Database %2").arg(i).arg(docdb->dbPathName())); @@ -578,9 +585,9 @@ bool DOCConverter::convertPDBtoTXT() } // TODO: Sort the list of bookmarks according to their position docBookmark::compare_pos=true; - bmks.sort(); + bmks.sort([](docBookmark *a, docBookmark *b) { return *a < *b; }); - if ((fBmkTypes & eBmkFile) && (bmks.count()>0)) + if ((fBmkTypes & eBmkFile) && (bmks.size()>0)) { TQString bmkfilename = docfile.name(); if (bmkfilename.endsWith(CSL1(".txt"))){ @@ -598,7 +605,7 @@ bool DOCConverter::convertPDBtoTXT() DEBUGKPILOT<<"Writing "<<upperBmkRec-header.numRecords<< "("<<upperBmkRec<<") bookmarks to file "<<bmkfilename<<endl; TQTextStream bmkstream(&bmkfile); - for (docBookmark*bmk=bmks.first(); bmk; bmk=bmks.next()) + for (docBookmark *bmk : bmks) { bmkstream<<bmk->position<<", "<<bmk->bmkName<<endl; } @@ -608,8 +615,9 @@ bool DOCConverter::convertPDBtoTXT() } if (fBmkTypes & eBmkInline) { - for (docBookmark*bmk=bmks.last(); bmk; bmk=bmks.prev()) + for (bmkList::reverse_iterator rit = bmks.rbegin(); rit!= bmks.rend(); ++rit) { + docBookmark *bmk = *rit; doctext.insert(bmk->position, TQString(CSL1("<*") + bmk->bmkName + CSL1("*>"))); @@ -624,6 +632,10 @@ bool DOCConverter::convertPDBtoTXT() docdb->cleanup(); // reset all records to unchanged. I don't know if this is really such a wise idea? docdb->resetSyncFlags(); + for (docBookmark *bmk : bmks) + { + delete bmk; + } return true; } diff --git a/conduits/docconduit/DOC-converter.h b/conduits/docconduit/DOC-converter.h index 25eab65..4eed37e 100644 --- a/conduits/docconduit/DOC-converter.h +++ b/conduits/docconduit/DOC-converter.h @@ -36,7 +36,7 @@ #define BMK_SUFFIX ".bmk" #define PDBBMK_SUFFIX ".bm" -#include <tqptrlist.h> +#include <list> #include <tqobject.h> class PilotDatabase; @@ -49,8 +49,7 @@ class PilotDatabase; ****************************************************************************************************/ class docBookmark; -#define bmkList TQPtrList<docBookmark> -#define bmkSortedList TQPtrList<docBookmark> +#define bmkList std::list<docBookmark*> class docBookmark { public: @@ -61,7 +60,7 @@ public: virtual ~ docBookmark() { }; virtual int findMatches(TQString, bmkList &fBookmarks) { FUNCTIONSETUP; - fBookmarks.append(new docBookmark(*this)); + fBookmarks.push_back(new docBookmark(*this)); return 1; }; @@ -140,16 +139,24 @@ public: bool convertPDBtoTXT(); int setBookmarks(bmkList bookmarks) { + for (docBookmark *bmk : fBookmarks) + { + delete bmk; + } fBookmarks = bookmarks; - return fBookmarks.count(); + return fBookmarks.size(); }; int clearBookmarks() { + for (docBookmark *bmk : fBookmarks) + { + delete bmk; + } fBookmarks.clear(); - return fBookmarks.count(); + return fBookmarks.size(); }; - int addBookmark(docBookmark*bookmark) { - fBookmarks.append(bookmark); - return fBookmarks.count(); + int addBookmark(docBookmark *bookmark) { + fBookmarks.push_back(bookmark); + return fBookmarks.size(); }; int findBmkEndtags(TQString &, bmkList&); |