From ad5f5d5c5feaac3c1351609c79aaa7d2802d5a55 Mon Sep 17 00:00:00 2001 From: osnola Date: Mon, 4 Nov 2013 18:35:36 +0100 Subject: [PATCH 3/8] Correct some cppcheck errors + change code to avoid calling isfinite... --- configure.ac | 10 ------- src/conv/csv/mwaw2csv.cpp | 2 +- src/conv/raw/mwaw2raw.cpp | 2 +- src/conv/text/mwaw2text.cpp | 2 +- src/lib/CWDbaseContent.cxx | 19 +++++++------ src/lib/CWDbaseContent.hxx | 6 ++-- src/lib/CWGraph.cxx | 30 ++++++++++---------- src/lib/CWGraph.hxx | 2 +- src/lib/HMWKGraph.cxx | 12 ++++---- src/lib/MSKGraph.cxx | 2 +- src/lib/MSKGraph.hxx | 2 +- src/lib/MSKParser.cxx | 18 ++---------- src/lib/MSKParser.hxx | 2 -- src/lib/MSWTextStyles.cxx | 2 +- src/lib/MWAWDocument.cxx | 6 ++-- src/lib/MWAWInputStream.cxx | 4 ++- src/lib/MWAWInputStream.hxx | 2 +- src/lib/MWAWOLEParser.cxx | 2 +- src/lib/MWAWOLEStream.cxx | 2 +- src/lib/MWAWPropertyHandler.cxx | 63 +++++++++++++++++++++-------------------- 20 files changed, 84 insertions(+), 106 deletions(-) diff --git a/src/conv/csv/mwaw2csv.cpp b/src/conv/csv/mwaw2csv.cpp index 0937a46..ed3799d 100644 --- a/src/conv/csv/mwaw2csv.cpp +++ b/src/conv/csv/mwaw2csv.cpp @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) CSVGenerator documentGenerator(output); error = MWAWDocument::parse(&input, &documentGenerator); } - catch(MWAWDocument::Result err) + catch(MWAWDocument::Result const &err) { error=err; } diff --git a/src/conv/raw/mwaw2raw.cpp b/src/conv/raw/mwaw2raw.cpp index 5e365f1..8e6a92c 100644 --- a/src/conv/raw/mwaw2raw.cpp +++ b/src/conv/raw/mwaw2raw.cpp @@ -90,7 +90,7 @@ int main(int argc, char *argv[]) { error=MWAWDocument::parse(&input, &documentGenerator); } - catch (MWAWDocument::Result err) + catch (MWAWDocument::Result const &err) { error=err; } diff --git a/src/conv/text/mwaw2text.cpp b/src/conv/text/mwaw2text.cpp index edb980d..2b561bf 100644 --- a/src/conv/text/mwaw2text.cpp +++ b/src/conv/text/mwaw2text.cpp @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) { MWAWDocument::parse(&input, &documentGenerator); } - catch (MWAWDocument::Result err) + catch (MWAWDocument::Result const &err) { error=err; } diff --git a/src/lib/CWDbaseContent.cxx b/src/lib/CWDbaseContent.cxx index 7198103..2c2d971 100644 --- a/src/lib/CWDbaseContent.cxx +++ b/src/lib/CWDbaseContent.cxx @@ -518,7 +518,7 @@ bool CWDbaseContent::readRecordSSV1(Vec2i const &id, long pos, CWDbaseContent::R break; } record.m_resType=Record::R_Double; - if (input->readDouble(record.m_resDouble)) + if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) f << record.m_resDouble << ","; else { MWAW_DEBUG_MSG(("CWDbaseContent::readRecordSSV1: can not read a float\n")); @@ -572,7 +572,7 @@ bool CWDbaseContent::readRecordSSV1(Vec2i const &id, long pos, CWDbaseContent::R f << "###int" << rType << "[res],"; break; case 2: - if (input->checkPosition(resPos+10) && input->readDouble(record.m_resDouble)) { + if (input->checkPosition(resPos+10) && input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) { record.m_resType=Record::R_Double; f << "=" << record.m_resDouble << ","; break; @@ -674,7 +674,7 @@ bool CWDbaseContent::readRecordSS(Vec2i const &id, long pos, CWDbaseContent::Rec break; } record.m_resType=Record::R_Double; - if (input->readDouble(record.m_resDouble)) + if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) f << record.m_resDouble << ","; else { MWAW_DEBUG_MSG(("CWDbaseContent::readRecordSS: can not read a float\n")); @@ -736,7 +736,7 @@ bool CWDbaseContent::readRecordSS(Vec2i const &id, long pos, CWDbaseContent::Rec f << "###int" << rType << "[res],"; break; case 2: - if (remainSz>=10 && input->readDouble(record.m_resDouble)) { + if (remainSz>=10 && input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) { record.m_resType=Record::R_Double; f << "=" << record.m_resDouble << ","; break; @@ -858,7 +858,7 @@ bool CWDbaseContent::readRecordDB(Vec2i const &id, long pos, CWDbaseContent::Rec f << "###"; break; } - if (input->readDouble(record.m_resDouble)) { + if (input->readDouble(record.m_resDouble, record.m_resDoubleNaN)) { record.m_resType=Record::R_Double; f << record.m_resDouble << ","; } else { @@ -929,7 +929,7 @@ bool CWDbaseContent::send(Vec2i const &pos) switch(record.m_resType) { case Record::R_Long: if (format.m_format) - send(double(record.m_resLong), format); + send(double(record.m_resLong), false, format); else { std::stringstream s; s << record.m_resLong; @@ -937,7 +937,7 @@ bool CWDbaseContent::send(Vec2i const &pos) } break; case Record::R_Double: - send(record.m_resDouble, format); + send(record.m_resDouble, record.m_resDoubleNaN, format); break; case Record::R_String: if (record.m_resString.valid()) { @@ -959,7 +959,7 @@ bool CWDbaseContent::send(Vec2i const &pos) return true; } -void CWDbaseContent::send(double val, CWStyleManager::CellFormat const &format) +void CWDbaseContent::send(double val, bool isNotANumber, CWStyleManager::CellFormat const &format) { MWAWContentListenerPtr listener=m_parserState->m_listener; if (!listener) @@ -970,7 +970,8 @@ void CWDbaseContent::send(double val, CWStyleManager::CellFormat const &format) if (type>=10&&type<=11) type += 4; else if (type>=14) type=16; } - if (type <= 0 || type >=16 || type==10 || type==11 || !boost::math::isfinite(val)) { + // note: if val*0!=0, val is a NaN so better so simply print NaN + if (type <= 0 || type >=16 || type==10 || type==11 || isNotANumber) { s << val; listener->insertUnicodeString(s.str().c_str()); return; diff --git a/src/lib/CWDbaseContent.hxx b/src/lib/CWDbaseContent.hxx index 36596e9..04177fe 100644 --- a/src/lib/CWDbaseContent.hxx +++ b/src/lib/CWDbaseContent.hxx @@ -78,7 +78,7 @@ protected: //! different result type enum Type { R_Unknown, R_Long, R_Double, R_String }; //! contructor - Record() : m_style(-1), m_resType(R_Unknown), m_resLong(0), m_resDouble(0), m_resString(), m_format(0), m_font(3,9), m_justify(0), m_borders(0) { + Record() : m_style(-1), m_resType(R_Unknown), m_resLong(0), m_resDouble(0), m_resDoubleNaN(false), m_resString(), m_format(0), m_font(3,9), m_justify(0), m_borders(0) { } //! the style if known @@ -89,6 +89,8 @@ protected: long m_resLong; //! the result id double double m_resDouble; + //! a flag to know if a double result is nan or not + bool m_resDoubleNaN; //! the result entry if string MWAWEntry m_resString; //! the format ( in a v1-3 spreadsheet) @@ -123,7 +125,7 @@ protected: bool readRecordDB(Vec2i const &where, long pos, Record &record); //! send a double with a corresponding cell format - void send(double val, CWStyleManager::CellFormat const &format); + void send(double val, bool isNotaNumber, CWStyleManager::CellFormat const &format); //! the file version int m_version; diff --git a/src/lib/CWGraph.cxx b/src/lib/CWGraph.cxx index 6f34628..01109f6 100644 --- a/src/lib/CWGraph.cxx +++ b/src/lib/CWGraph.cxx @@ -311,7 +311,7 @@ struct ZonePict : public Zone { struct Bitmap : public CWStruct::DSET { //! constructor Bitmap(CWStruct::DSET const &dset = CWStruct::DSET()) : - DSET(dset), m_bitmapType(-1), m_size(0,0), m_entry(), m_colorMap() { + DSET(dset), m_bitmapType(-1), m_bitmapSize(0,0), m_entry(), m_colorMap() { } //! operator<< @@ -324,7 +324,7 @@ struct Bitmap : public CWStruct::DSET { //! the bitmap type int m_bitmapType; //! the bitmap size - Vec2i m_size; + Vec2i m_bitmapSize; //! the bitmap entry MWAWEntry m_entry; //! the color map @@ -666,7 +666,7 @@ void CWGraph::askToSend(int number, bool asGraphic, MWAWPosition const& pos) //////////////////////////////////////////////////////////// // Intermediate level //////////////////////////////////////////////////////////// -bool CWGraph::getSurfaceColor(CWGraphInternal::Style const style, MWAWColor &col) const +bool CWGraph::getSurfaceColor(CWGraphInternal::Style const &style, MWAWColor &col) const { if (!style.hasSurfaceColor()) return false; @@ -814,7 +814,7 @@ shared_ptr CWGraph::readBitmapZone dim[j] = (int) input->readLong(2); f << "sz=" << dim[1] << "x" << dim[0] << ","; if (dim[0] > 0 && dim[1] > 0) { - bitmap->m_size = Vec2i(dim[1]+2, dim[0]+2); + bitmap->m_bitmapSize = Vec2i(dim[1]+2, dim[0]+2); sizeSet = true; } ascFile.addDelimiter(input->tell(),']'); @@ -852,7 +852,7 @@ shared_ptr CWGraph::readBitmapZone for (int j = 0; j < 2; j++) dim[j] = (int) input->readLong(2); if (i == N-1 && !sizeSet) - bitmap->m_size = Vec2i(dim[0]+2, dim[1]+2); + bitmap->m_bitmapSize = Vec2i(dim[0]+2, dim[1]+2); f << "dim?=" << dim[0] << "x" << dim[1] << ","; for (int j = 3; j < 6; j++) { @@ -1993,18 +1993,18 @@ bool CWGraph::readBitmapData(CWGraphInternal::Bitmap &zone) return false; } /* Fixme: this code can not works for the packed bitmap*/ - long numColors = zone.m_size[0]*zone.m_size[1]; + long numColors = zone.m_bitmapSize[0]*zone.m_bitmapSize[1]; int numBytes = numColors ? int(sz/numColors) : 0; if (sz != numBytes*numColors) { // check for different row alignement: 2 and 4 for (int align=2; align <= 4; align*=2) { - int diffToAlign=align-(zone.m_size[0]%align); + int diffToAlign=align-(zone.m_bitmapSize[0]%align); if (diffToAlign==align) continue; - numColors = (zone.m_size[0]+diffToAlign)*zone.m_size[1]; + numColors = (zone.m_bitmapSize[0]+diffToAlign)*zone.m_bitmapSize[1]; numBytes = numColors ? int(sz/numColors) : 0; if (sz == numBytes*numColors) { - zone.m_size[0]+=diffToAlign; - MWAW_DEBUG_MSG(("CWGraph::readBitmapData: increase width to %d\n",zone.m_size[0])); + zone.m_bitmapSize[0]+=diffToAlign; + MWAW_DEBUG_MSG(("CWGraph::readBitmapData: increase width to %d\n",zone.m_bitmapSize[0])); break; } } @@ -2048,7 +2048,7 @@ void CWGraph::checkNumberAccrossPages(CWGraphInternal::Group &group) const void CWGraph::updateInformation(CWGraphInternal::Group &group) const { - if (group.m_blockToSendList.size() || group.m_idLinkedZonesMap.size()) + if (!group.m_blockToSendList.empty() || !group.m_idLinkedZonesMap.empty()) return; std::set forbiddenZone; @@ -2633,19 +2633,19 @@ bool CWGraph::sendBitmap(CWGraphInternal::Bitmap &bitmap, bool asGraphic, MWAWPo MWAWPictBitmapColor *bmapColor = 0; bool indexed = false; if (numColors > 2) { - bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_size); + bmapIndexed = new MWAWPictBitmapIndexed(bitmap.m_bitmapSize); bmapIndexed->setColors(bitmap.m_colorMap); bmap.reset(bmapIndexed); indexed = true; } else - bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_size))); + bmap.reset((bmapColor=new MWAWPictBitmapColor(bitmap.m_bitmapSize))); //! let go int fSz = bitmap.m_bitmapType; MWAWInputStreamPtr &input= m_parserState->m_input; input->seek(bitmap.m_entry.begin(), WPX_SEEK_SET); - for (int r = 0; r < bitmap.m_size[1]; r++) { - for (int c = 0; c < bitmap.m_size[0]; c++) { + for (int r = 0; r < bitmap.m_bitmapSize[1]; r++) { + for (int c = 0; c < bitmap.m_bitmapSize[0]; c++) { long val = (long) input->readULong(fSz); if (indexed) { bmapIndexed->set(c,r,(int)val); diff --git a/src/lib/CWGraph.hxx b/src/lib/CWGraph.hxx index 0655464..bdb2bd5 100644 --- a/src/lib/CWGraph.hxx +++ b/src/lib/CWGraph.hxx @@ -98,7 +98,7 @@ public: (CWStruct::DSET const &zone, MWAWEntry const &entry, bool &complete); //! return the surface color which corresponds to some ids (if possible) - bool getSurfaceColor(CWGraphInternal::Style const style, MWAWColor &col) const; + bool getSurfaceColor(CWGraphInternal::Style const &style, MWAWColor &col) const; protected: //! set the slide list ( for presentation ) void setSlideList(std::vector const &slideList); diff --git a/src/lib/HMWKGraph.cxx b/src/lib/HMWKGraph.cxx index 2ad56d2..ab8b904 100644 --- a/src/lib/HMWKGraph.cxx +++ b/src/lib/HMWKGraph.cxx @@ -292,7 +292,7 @@ std::string Group::print() const //! Internal: the picture of a HMWKGraph struct PictureFrame : public Frame { //! constructor - PictureFrame(Frame const &orig) : Frame(orig), m_type(0), m_dim(0,0), m_borderDim(0,0) { + PictureFrame(Frame const &orig) : Frame(orig), m_pictureType(0), m_dim(0,0), m_borderDim(0,0) { for (int i = 0; i < 7; ++i) m_values[i] = 0; } //! destructor @@ -307,7 +307,7 @@ struct PictureFrame : public Frame { //! print local data std::string print() const { std::stringstream s; - if (m_type) s << "type?=" << m_type << ","; + if (m_pictureType) s << "type?=" << m_pictureType << ","; if (m_dim[0] || m_dim[1]) s << "dim?=" << m_dim << ","; if (m_borderDim[0] > 0 || m_borderDim[1] > 0) @@ -319,7 +319,7 @@ struct PictureFrame : public Frame { } //! a type - int m_type; + int m_pictureType; //! a dim? Vec2i m_dim; //! the border dim? @@ -422,7 +422,7 @@ private: //! Internal: the textbox of a HMWKGraph struct TextBox : public Frame { //! constructor - TextBox(Frame const &orig, bool isComment) : Frame(orig), m_commentBox(isComment), m_textFileId(-1), m_linkedIdList(), m_isLinked(false), m_extra("") { + TextBox(Frame const &orig, bool isComment) : Frame(orig), m_commentBox(isComment), m_textFileId(-1), m_linkedIdList(), m_isLinked(false) { for (int i = 0; i < 2; ++i) m_dim[i] = 0; } //! destructor @@ -517,8 +517,6 @@ struct TextBox : public Frame { std::vector m_linkedIdList; //! a flag to know if this textbox is linked to a previous box bool m_isLinked; - //! extra data - std::string m_extra; }; bool TableCell::sendContent(MWAWContentListenerPtr, MWAWTable &table) @@ -1603,7 +1601,7 @@ shared_ptr HMWKGraph::readPictureFrame(shared_p picture.reset(new HMWKGraphInternal::PictureFrame(header)); libmwaw::DebugFile &asciiFile = zone->ascii(); libmwaw::DebugStream f; - picture->m_type = (int) input->readLong(2); // 0 or 4 : or maybe wrapping + picture->m_pictureType = (int) input->readLong(2); // 0 or 4 : or maybe wrapping for (int i = 0; i < 5; ++i) // always 0 picture->m_values[i] = (int) input->readLong(2); float bDim[2]; diff --git a/src/lib/MSKGraph.cxx b/src/lib/MSKGraph.cxx index fa876a1..dd873c1 100644 --- a/src/lib/MSKGraph.cxx +++ b/src/lib/MSKGraph.cxx @@ -2729,7 +2729,7 @@ void MSKGraph::sendAll(int zoneId, bool mainZone) } } -void MSKGraph::sendObjects(MSKGraph::SendData what) +void MSKGraph::sendObjects(MSKGraph::SendData const &what) { MWAWContentListenerPtr listener=m_parserState->m_listener; if (!listener) { diff --git a/src/lib/MSKGraph.hxx b/src/lib/MSKGraph.hxx index 29ee53a..f9518e4 100644 --- a/src/lib/MSKGraph.hxx +++ b/src/lib/MSKGraph.hxx @@ -110,7 +110,7 @@ public: Vec2i m_size; }; /** sends all the object of a page, frame, ... */ - void sendObjects(SendData const what); + void sendObjects(SendData const &what); /** try to update positions knowing pages and lines height */ void computePositions(int zoneId, std::vector &linesHeight, std::vector &pagesHeight); diff --git a/src/lib/MSKParser.cxx b/src/lib/MSKParser.cxx index 16b7d84..c527e90 100644 --- a/src/lib/MSKParser.cxx +++ b/src/lib/MSKParser.cxx @@ -36,27 +36,13 @@ #include "MSKParser.hxx" -/** Internal: the structures of a MSKParser */ -namespace MSKParserInternal -{ -//////////////////////////////////////// -//! Internal: the state of a MSK3Parser -struct State { - //! constructor - State() { - } -}; -} - MSKParser::MSKParser(MWAWInputStreamPtr input, MWAWRSRCParserPtr rsrcParser, MWAWHeader *header) : - MWAWParser(input, rsrcParser, header), m_state(new MSKParserInternal::State), - m_input(input), m_asciiFile(input) + MWAWParser(input, rsrcParser, header), m_input(input), m_asciiFile(input) { } MSKParser::MSKParser(MWAWInputStreamPtr input, MWAWParserStatePtr parserState) : - MWAWParser(parserState), m_state(new MSKParserInternal::State), - m_input(input), m_asciiFile(input) + MWAWParser(parserState), m_input(input), m_asciiFile(input) { } diff --git a/src/lib/MSKParser.hxx b/src/lib/MSKParser.hxx index eb29d1b..88244b9 100644 --- a/src/lib/MSKParser.hxx +++ b/src/lib/MSKParser.hxx @@ -94,8 +94,6 @@ public: return m_asciiFile; } protected: - //! the state - shared_ptr m_state; //! the input which can be an OLE in MSWorks 4 file MWAWInputStreamPtr m_input; //! the debug file of the actual input diff --git a/src/lib/MSWTextStyles.cxx b/src/lib/MSWTextStyles.cxx index 93a6e62..2bba921 100644 --- a/src/lib/MSWTextStyles.cxx +++ b/src/lib/MSWTextStyles.cxx @@ -386,6 +386,7 @@ bool MSWTextStyles::readParagraph(MSWStruct::Paragraph ¶, int dataSz) int const vers = version(); libmwaw::DebugFile &ascFile = m_parserState->m_asciiFile; libmwaw::DebugStream f; + int numFont=0; while (long(input->tell()) < endPos) { long actPos = input->tell(); /* 5-16: basic paragraph properties @@ -403,7 +404,6 @@ bool MSWTextStyles::readParagraph(MSWStruct::Paragraph ¶, int dataSz) } bool done = false; long dSz = endPos-actPos; - int numFont=0; switch(wh) { case 0: done = (actPos+1==endPos||(dataSz==2 && actPos+2==endPos)); diff --git a/src/lib/MWAWDocument.cxx b/src/lib/MWAWDocument.cxx index ef9d280..182de89 100644 --- a/src/lib/MWAWDocument.cxx +++ b/src/lib/MWAWDocument.cxx @@ -522,9 +522,9 @@ void GraphicExporter::endElement(const char *psName) m_output->endTextObject(); #ifdef DEBUG else if (strcmp(psName, "SetStyle") && strcmp(psName, "Rectangle") && - strcmp(psName, "Rectangle") && strcmp(psName, "Ellipse") && - strcmp(psName, "Polygon") && strcmp(psName, "Polyline") && - strcmp(psName, "Path") && strcmp(psName, "GraphicObject")) { + strcmp(psName, "Ellipse") && strcmp(psName, "Polygon") && + strcmp(psName, "Polyline") && strcmp(psName, "Path") && + strcmp(psName, "GraphicObject")) { MWAW_DEBUG_MSG(("GraphicExporter::endElement: called with unexpected name %s\n", psName)); } #endif diff --git a/src/lib/MWAWInputStream.cxx b/src/lib/MWAWInputStream.cxx index c4dc2b6..9b2e28c 100644 --- a/src/lib/MWAWInputStream.cxx +++ b/src/lib/MWAWInputStream.cxx @@ -229,7 +229,7 @@ uint8_t MWAWInputStream::readU8(WPXInputStream *stream) return *(uint8_t const *)(p); } -bool MWAWInputStream::readDouble(double &res) +bool MWAWInputStream::readDouble(double &res, bool &isNotANumber) { if (!m_stream) return false; long pos=tell(); @@ -244,6 +244,7 @@ bool MWAWInputStream::readDouble(double &res) } exp -= 0x3fff; + isNotANumber=false; unsigned long mantisse = (unsigned long) readULong(4); if ((mantisse & 0x80000000) == 0) { if (readULong(4) != 0) return false; @@ -251,6 +252,7 @@ bool MWAWInputStream::readDouble(double &res) if (exp == -0x3fff && mantisse == 0) return true; // ok zero if (exp == 0x4000 && (mantisse & 0xFFFFFFL)==0) { // ok Nan res=std::numeric_limits::quiet_NaN(); + isNotANumber = true; return true; } return false; diff --git a/src/lib/MWAWInputStream.hxx b/src/lib/MWAWInputStream.hxx index 818451a..bc29165 100644 --- a/src/lib/MWAWInputStream.hxx +++ b/src/lib/MWAWInputStream.hxx @@ -139,7 +139,7 @@ public: //! return a int8, int16, int32 readed from actualPos long readLong(int num); //! try to read a double (ppc) - bool readDouble(double &res); + bool readDouble(double &res, bool &isNotANumber); /**! reads numbytes data, WITHOUT using any endian or section consideration * \return a pointer to the read elements diff --git a/src/lib/MWAWOLEParser.cxx b/src/lib/MWAWOLEParser.cxx index a14aee1..70d6dd6 100644 --- a/src/lib/MWAWOLEParser.cxx +++ b/src/lib/MWAWOLEParser.cxx @@ -622,7 +622,7 @@ bool MWAWOLEParser::readCompObj(MWAWInputStreamPtr ip, std::string const &oleNam if (clsName) f << "'" << clsName << "'"; else { - MWAW_DEBUG_MSG(("MWAWOLEParser::readCompObj: unknown clsid=%ld\n", clsData[0])); + MWAW_DEBUG_MSG(("MWAWOLEParser::readCompObj: unknown clsid=%ld\n", (long) clsData[0])); f << "unknCLSID='" << std::hex << clsData[0] << "'"; } } else { diff --git a/src/lib/MWAWOLEStream.cxx b/src/lib/MWAWOLEStream.cxx index 6ffebea..9abdd90 100644 --- a/src/lib/MWAWOLEStream.cxx +++ b/src/lib/MWAWOLEStream.cxx @@ -454,7 +454,7 @@ void DirEntry::load( unsigned char *buffer, unsigned len ) m_name="R"; m_macRootEntry=true; } else { - for( unsigned j=0; ( buffer[j]) && (j='0' && val[0]<='9'))) { - std::istringstream iss(val); - double res = 0.0; - iss >> res; - if (!iss.fail()) { - if (iss.eof() || iss.peek() == std::char_traits::eof()) { - list.insert(key.c_str(), res); - return true; - } - std::string remain; - iss >> remain; - if (iss.peek() == std::char_traits::eof()) { - if (remain=="pt") { - list.insert(key.c_str(), res/72., WPX_INCH); - return true; - } - if (remain=="in") { - list.insert(key.c_str(), res, WPX_INCH); - return true; - } - if (remain=="%") { - list.insert(key.c_str(), res/100., WPX_PERCENT); - return true; - } - if (remain=="*") { - list.insert(key.c_str(), res/1440., WPX_INCH); - return true; - } - } + std::string number(""), remain(""); + // check if the val can be a double, first isolate the potential numbering part ... + for (size_t s=0; s='0' && c<='9')) { + number+=c; + continue; } + remain=val.substr(s); + break; + } + if (number.empty()) { + list.insert(key.c_str(), val.c_str()); + return true; + } + std::istringstream iss(number); + double res = 0.0; + iss >> res; + if (iss.fail() || iss.peek()!=std::char_traits::eof()) { + list.insert(key.c_str(), val.c_str()); + return true; } - list.insert(key.c_str(), val.c_str()); + if (remain.empty()) + list.insert(key.c_str(), res); + else if (remain=="pt") + list.insert(key.c_str(), res/72., WPX_INCH); + else if (remain=="in") + list.insert(key.c_str(), res, WPX_INCH); + else if (remain=="%") + list.insert(key.c_str(), res/100., WPX_PERCENT); + else if (remain=="*") + list.insert(key.c_str(), res/1440., WPX_INCH); + else + list.insert(key.c_str(), val.c_str()); return true; } -- 1.9.0