diff options
author | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-08-12 19:11:52 +0200 |
---|---|---|
committer | Markus Mohrhard <markus.mohrhard@googlemail.com> | 2017-08-13 00:13:08 +0200 |
commit | 3e0b1754a7878d34604dbdd589855f546ca158bd (patch) | |
tree | 17a5b322d9625d2887db8903eb6790f611a6f7c1 /sc/source/ui/dataprovider/csvdataprovider.cxx | |
parent | b37ce3664ad8f97bc1f97f7ef64669168268c60f (diff) |
external data: pass the whole string to the csv parser
Change-Id: I221027f8613eaacd4fcb46d31e33185abeadae48
Reviewed-on: https://gerrit.libreoffice.org/41093
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source/ui/dataprovider/csvdataprovider.cxx')
-rw-r--r-- | sc/source/ui/dataprovider/csvdataprovider.cxx | 112 |
1 files changed, 24 insertions, 88 deletions
diff --git a/sc/source/ui/dataprovider/csvdataprovider.cxx b/sc/source/ui/dataprovider/csvdataprovider.cxx index 24450e0d4349..fb77b4096986 100644 --- a/sc/source/ui/dataprovider/csvdataprovider.cxx +++ b/sc/source/ui/dataprovider/csvdataprovider.cxx @@ -19,80 +19,44 @@ namespace { -struct Cell -{ - struct Str - { - size_t Pos; - size_t Size; - }; - - union - { - Str maStr; - double mfValue; - }; - - bool mbValue; - - Cell(); - Cell( const Cell& r ); -}; - -struct Line -{ - OString maLine; - std::vector<Cell> maCells; -}; - -Cell::Cell() : mfValue(0.0), mbValue(true) {} - -Cell::Cell(const Cell& r) : mbValue(r.mbValue) -{ - if (r.mbValue) - mfValue = r.mfValue; - else - { - maStr.Pos = r.maStr.Pos; - maStr.Size = r.maStr.Size; - } -} - class CSVHandler { - Line& mrLine; - size_t mnColCount; - size_t mnCols; - const char* mpLineHead; + ScDocument* mpDoc; + SCCOL mnCol; + SCROW mnRow; public: - CSVHandler( Line& rLine, size_t nColCount ) : - mrLine(rLine), mnColCount(nColCount), mnCols(0), mpLineHead(rLine.maLine.getStr()) {} + CSVHandler(ScDocument* pDoc) : + mpDoc(pDoc), mnCol(0), mnRow(0) + { + } static void begin_parse() {} static void end_parse() {} static void begin_row() {} - static void end_row() {} + void end_row() + { + ++mnRow; + mnCol = 0; + } void cell(const char* p, size_t n) { - if (mnCols >= mnColCount) + if (mnCol > MAXCOL) return; - Cell aCell; - if (ScStringUtil::parseSimpleNumber(p, n, '.', ',', aCell.mfValue)) + double mfValue = 0.0; + if (ScStringUtil::parseSimpleNumber(p, n, '.', ',', mfValue)) { - aCell.mbValue = true; + mpDoc->SetValue(mnCol, mnRow, 0, mfValue); } else { - aCell.mbValue = false; - aCell.maStr.Pos = std::distance(mpLineHead, p); - aCell.maStr.Size = n; + OString aStr(p, n); + mpDoc->SetString(mnCol, mnRow, 0, OStringToOUString(aStr, RTL_TEXTENCODING_UTF8)); } - mrLine.maCells.push_back(aCell); - ++mnCols; + ++mnCol; } }; @@ -136,41 +100,13 @@ void CSVFetchThread::execute() { OStringBuffer aBuffer(64000); std::unique_ptr<SvStream> pStream = DataProvider::FetchStreamFromURL(maURL, aBuffer); - SCROW nCurRow = 0; - SCCOL nCol = 0; - while (pStream->good()) - { - if (mbTerminate) - break; - - Line aLine; - aLine.maCells.clear(); - pStream->ReadLine(aLine.maLine); - CSVHandler aHdl(aLine, MAXCOL); - orcus::csv_parser<CSVHandler> parser(aLine.maLine.getStr(), aLine.maLine.getLength(), aHdl, maConfig); - parser.parse(); + if (mbTerminate) + return; - if (aLine.maCells.empty()) - { - break; - } + CSVHandler aHdl(&mrDocument); + orcus::csv_parser<CSVHandler> parser(aBuffer.getStr(), aBuffer.getLength(), aHdl, maConfig); + parser.parse(); - nCol = 0; - const char* pLineHead = aLine.maLine.getStr(); - for (auto& rCell : aLine.maCells) - { - if (rCell.mbValue) - { - mrDocument.SetValue(ScAddress(nCol, nCurRow, 0 /* Tab */), rCell.mfValue); - } - else - { - mrDocument.SetString(nCol, nCurRow, 0 /* Tab */, OUString(pLineHead+rCell.maStr.Pos, rCell.maStr.Size, RTL_TEXTENCODING_UTF8)); - } - ++nCol; - } - nCurRow++; - } SolarMutexGuard aGuard; mpIdle->Start(); } |