diff --git a/jni/NativeFormats/JavaNativeFormatPlugin.cpp b/jni/NativeFormats/JavaNativeFormatPlugin.cpp index e144cac44..ac69dd61f 100644 --- a/jni/NativeFormats/JavaNativeFormatPlugin.cpp +++ b/jni/NativeFormats/JavaNativeFormatPlugin.cpp @@ -67,7 +67,7 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) { } const AuthorList &authors = book.authors(); - for (size_t i = 0; i < authors.size(); ++i) { + for (std::size_t i = 0; i < authors.size(); ++i) { const Author &author = *authors[i]; javaString = env->NewStringUTF(author.name().c_str()); jstring key = env->NewStringUTF(author.sortKey().c_str()); @@ -77,7 +77,7 @@ static void fillMetaInfo(JNIEnv* env, jobject javaBook, Book &book) { } const TagList &tags = book.tags(); - for (size_t i = 0; i < tags.size(); ++i) { + for (std::size_t i = 0; i < tags.size(); ++i) { const Tag &tag = *tags[i]; AndroidUtil::Method_Book_addTag->call(javaBook, tag.javaTag(env)); } @@ -149,17 +149,17 @@ static bool initInternalHyperlinks(JNIEnv *env, jobject javaModel, BookModel &mo } ZLUnicodeUtil::utf8ToUcs2(ucs2id, id); ZLUnicodeUtil::utf8ToUcs2(ucs2modelId, label.Model->id()); - const size_t idLen = ucs2id.size() * 2; - const size_t modelIdLen = ucs2modelId.size() * 2; + const std::size_t idLen = ucs2id.size() * 2; + const std::size_t modelIdLen = ucs2modelId.size() * 2; char *ptr = allocator.allocate(idLen + modelIdLen + 8); ZLCachedMemoryAllocator::writeUInt16(ptr, ucs2id.size()); ptr += 2; - memcpy(ptr, &ucs2id.front(), idLen); + std::memcpy(ptr, &ucs2id.front(), idLen); ptr += idLen; ZLCachedMemoryAllocator::writeUInt16(ptr, ucs2modelId.size()); ptr += 2; - memcpy(ptr, &ucs2modelId.front(), modelIdLen); + std::memcpy(ptr, &ucs2modelId.front(), modelIdLen); ptr += modelIdLen; ZLCachedMemoryAllocator::writeUInt32(ptr, label.ParagraphNumber); } @@ -181,7 +181,7 @@ static jobject createTextModel(JNIEnv *env, jobject javaModel, ZLTextModel &mode jstring language = AndroidUtil::createJavaString(env, model.language()); jint paragraphsNumber = model.paragraphsNumber(); - const size_t arraysSize = model.startEntryIndices().size(); + const std::size_t arraysSize = model.startEntryIndices().size(); jintArray entryIndices = env->NewIntArray(arraysSize); jintArray entryOffsets = env->NewIntArray(arraysSize); jintArray paragraphLenghts = env->NewIntArray(arraysSize); diff --git a/jni/NativeFormats/JavaPluginCollection.cpp b/jni/NativeFormats/JavaPluginCollection.cpp index 066ae5921..c635385c1 100644 --- a/jni/NativeFormats/JavaPluginCollection.cpp +++ b/jni/NativeFormats/JavaPluginCollection.cpp @@ -27,12 +27,12 @@ extern "C" JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz) { const std::vector > plugins = PluginCollection::Instance().plugins(); - const size_t size = plugins.size(); + const std::size_t size = plugins.size(); jclass cls = AndroidUtil::Class_NativeFormatPlugin.j(); // TODO: memory leak? jobjectArray javaPlugins = env->NewObjectArray(size, cls, 0); - for (size_t i = 0; i < size; ++i) { + for (std::size_t i = 0; i < size; ++i) { jstring fileType = AndroidUtil::createJavaString(env, plugins[i]->supportedFileType()); jobject p = AndroidUtil::StaticMethod_NativeFormatPlugin_create->call(fileType); env->SetObjectArrayElement(javaPlugins, i, p); diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp index 5b90530e9..79ddcb5d5 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.cpp @@ -232,8 +232,8 @@ void BookReader::addImage(const std::string &id, shared_ptr image void BookReader::insertEndParagraph(ZLTextParagraph::Kind kind) { if ((myCurrentTextModel != 0) && mySectionContainsRegularContents) { - size_t size = myCurrentTextModel->paragraphsNumber(); - if ((size > 0) && (((*myCurrentTextModel)[(size_t)-1])->kind() != kind)) { + std::size_t size = myCurrentTextModel->paragraphsNumber(); + if ((size > 0) && (((*myCurrentTextModel)[(std::size_t)-1])->kind() != kind)) { ((ZLTextPlainModel&)*myCurrentTextModel).createParagraph(kind); mySectionContainsRegularContents = false; } @@ -293,7 +293,7 @@ void BookReader::endContentsParagraph() { } /* -void BookReader::setReference(size_t contentsParagraphNumber, int referenceNumber) { +void BookReader::setReference(std::size_t contentsParagraphNumber, int referenceNumber) { ContentsModel &contentsModel = (ContentsModel&)*myModel.myContentsModel; if (contentsParagraphNumber >= contentsModel.paragraphsNumber()) { return; diff --git a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h index 14c70c687..be6bda819 100644 --- a/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h +++ b/jni/NativeFormats/fbreader/src/bookmodel/BookReader.h @@ -71,7 +71,7 @@ public: void beginContentsParagraph(int referenceNumber = -1); void endContentsParagraph(); bool contentsParagraphIsOpen() const; - //void setReference(size_t contentsParagraphNumber, int referenceNumber); + //void setReference(std::size_t contentsParagraphNumber, int referenceNumber); void addData(const std::string &data); void addContentsData(const std::string &data); diff --git a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp index 3c8cba3cd..04fe063dc 100644 --- a/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/FormatPlugin.cpp @@ -44,7 +44,7 @@ bool FormatPlugin::detectEncodingAndLanguage(Book &book, ZLInputStream &stream, if (collection.isLanguageAutoDetectEnabled() && stream.open()) { static const int BUFSIZE = 65536; char *buffer = new char[BUFSIZE]; - const size_t size = stream.read(buffer, BUFSIZE); + const std::size_t size = stream.read(buffer, BUFSIZE); stream.close(); shared_ptr info = ZLLanguageDetector().findInfo(buffer, size); delete[] buffer; @@ -77,7 +77,7 @@ bool FormatPlugin::detectLanguage(Book &book, ZLInputStream &stream, const std:: if (collection.isLanguageAutoDetectEnabled() && stream.open()) { static const int BUFSIZE = 65536; char *buffer = new char[BUFSIZE]; - const size_t size = stream.read(buffer, BUFSIZE); + const std::size_t size = stream.read(buffer, BUFSIZE); stream.close(); shared_ptr info = ZLLanguageDetector().findInfoForEncoding(encoding, buffer, size, -20000); diff --git a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp index f2a761b39..b58de2242 100644 --- a/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp +++ b/jni/NativeFormats/fbreader/src/formats/css/StyleSheetParser.cpp @@ -48,7 +48,7 @@ void StyleSheetTableParser::storeData(const std::string &selector, const StyleSh std::string id = *it; ZLStringUtil::stripWhiteSpaces(id); if (!id.empty()) { - const size_t index = id.find('.'); + const std::size_t index = id.find('.'); if (index == std::string::npos) { myTable.addMap(id, std::string(), map); } else { @@ -231,7 +231,7 @@ void StyleSheetParser::processWordWithoutComments(const std::string &word) { break; case ATTRIBUTE_VALUE: { - const size_t l = word.length(); + const std::size_t l = word.length(); if (l >= 2 && (word[0] == '"' || word[0] == '\'') && word[0] == word[l - 1]) { myMap[myAttributeName].push_back(word.substr(1, l - 2)); } else { diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.cpp index 7234ff9f1..8877c5422 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.cpp @@ -50,7 +50,7 @@ bool DocBookReader::readBook() { myModelReader.pushKind(REGULAR); myModelReader.beginParagraph(); - if (!readDocument(stream)) { + if (!readDocument(stream, true)) { return false; } @@ -89,7 +89,7 @@ void DocBookReader::handleHardLinebreak() { if (!myCurrentStyleEntry.isNull()) { myModelReader.addStyleEntry(*myCurrentStyleEntry); } - for (size_t i = 0; i < myKindStack.size(); ++i) { + for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } @@ -156,7 +156,7 @@ void DocBookReader::handleSeparatorField() { std::vector result = ZLStringUtil::split(utf8String, SPACE_DELIMETER); //TODO split function can returns empty string, maybe fix it std::vector splitted; - for (size_t i = 0; i < result.size(); ++i) { + for (std::size_t i = 0; i < result.size(); ++i) { if (!result.at(i).empty()) { splitted.push_back(result.at(i)); } @@ -239,7 +239,7 @@ void DocBookReader::handleFontStyle(unsigned int fontStyle) { if (fontStyle & OleMainStream::CharInfo::FONT_ITALIC) { myKindStack.push_back(ITALIC); } - for (size_t i = 0; i < myKindStack.size(); ++i) { + for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } @@ -289,7 +289,7 @@ void DocBookReader::handleParagraphStyle(const OleMainStream::Style &styleInfo) // if it has the same StyleIdCurrent if (myCurrentStyleInfo.StyleIdCurrent != OleMainStream::Style::STYLE_INVALID && myCurrentStyleInfo.StyleIdCurrent == styleInfo.StyleIdCurrent) { - for (size_t i = 0; i < myKindStack.size(); ++i) { + for (std::size_t i = 0; i < myKindStack.size(); ++i) { myModelReader.addControl(myKindStack.at(i), true); } } else { @@ -312,7 +312,7 @@ std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode // [0x13] HYPERLINK "http://yandex.ru/yandsearch?text='some text' и "some text2"" [0x14] link text [0x15] static const ZLUnicodeUtil::Ucs2Char QUOTE = 0x22; - size_t i, first = 0; + std::size_t i, first = 0; //TODO maybe functions findFirstOf and findLastOf should be in ZLUnicodeUtil class for (i = 0; i < s.size(); ++i) { if (s.at(i) == QUOTE) { @@ -323,7 +323,7 @@ std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode if (i == s.size()) { return std::string(); } - size_t j, last = 0; + std::size_t j, last = 0; for (j = s.size(); j > 0 ; --j) { if (s.at(j - 1) == QUOTE) { last = j - 1; @@ -335,7 +335,7 @@ std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode } ZLUnicodeUtil::Ucs2String link; - for (size_t k = first + 1; k < last; ++k) { + for (std::size_t k = first + 1; k < last; ++k) { ZLUnicodeUtil::Ucs2Char ch = s.at(k); if (urlencode && ZLUnicodeUtil::isSpace(ch)) { //TODO maybe implement function for encoding all signs in url, not only spaces and quotes @@ -356,11 +356,11 @@ std::string DocBookReader::parseLink(ZLUnicodeUtil::Ucs2String s, bool urlencode return utf8String; } -void DocBookReader::footnoteHandler() { +void DocBookReader::footnotesStartHandler() { handlePageBreak(); } -void DocBookReader::dataHandler(const char *buffer, size_t len) { +void DocBookReader::ansiDataHandler(const char *buffer, std::size_t len) { if (myConverter.isNull()) { // lazy converter initialization const ZLEncodingCollection &collection = ZLEncodingCollection::Instance(); @@ -374,6 +374,6 @@ void DocBookReader::dataHandler(const char *buffer, size_t len) { ZLUnicodeUtil::utf8ToUcs2(myBuffer, utf8String); } -void DocBookReader::ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { +void DocBookReader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { myBuffer.push_back(symbol); } diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.h b/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.h index b020e4fab..d80fb8eae 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocBookReader.h @@ -40,9 +40,9 @@ public: bool readBook(); private: - void dataHandler(const char *buffer, size_t len); - void ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); - void footnoteHandler(); + void ansiDataHandler(const char *buffer, std::size_t len); + void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); + void footnotesStartHandler(); void handleChar(ZLUnicodeUtil::Ucs2Char ucs2char); void handleHardLinebreak(); diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocFloatImageReader.cpp b/jni/NativeFormats/fbreader/src/formats/doc/DocFloatImageReader.cpp index 747ecff0d..8c308e4da 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocFloatImageReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocFloatImageReader.cpp @@ -17,6 +17,8 @@ * 02110-1301, USA. */ +#include + #include "OleUtil.h" #include "OleStream.h" #include "OleMainStream.h" @@ -32,7 +34,10 @@ DocFloatImageReader::DocFloatImageReader(unsigned int off, unsigned int len, sha void DocFloatImageReader::readAll() { //OfficeArtContent structure is described at p.405-406 [MS-DOC] - myTableStream->seek(myOffset, true); + if (!myTableStream->seek(myOffset, true)) { + ZLLogger::Instance().println("DocPlugin", "problems with reading float images"); + return; + } unsigned int count = 0; @@ -56,7 +61,7 @@ void DocFloatImageReader::readAll() { ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeId(unsigned int shapeId) const { FSPContainer container; bool found = false; - for (size_t i = 0; !found && i < myItem.FSPs.size(); ++i) { + for (std::size_t i = 0; !found && i < myItem.FSPs.size(); ++i) { if (myItem.FSPs.at(i).fsp.shapeId == shapeId) { found = true; container = myItem.FSPs.at(i); @@ -67,7 +72,7 @@ ZLFileImage::Blocks DocFloatImageReader::getBlocksForShapeId(unsigned int shapeI return ZLFileImage::Blocks(); } - for (size_t i = 0; i < container.fopte.size(); ++i) { + for (std::size_t i = 0; i < container.fopte.size(); ++i) { const FOPTE &fopte = container.fopte.at(i); if (fopte.pId == 0x0104 && !fopte.isComplex) { //0x0104 specifies the BLIP, see p.420 [MS-ODRAW] if (fopte.value <= myItem.blips.size() && fopte.value > 0) { @@ -144,8 +149,12 @@ unsigned int DocFloatImageReader::skipRecord(const RecordHeader &header, shared_ unsigned int DocFloatImageReader::readBStoreContainerFileBlock(Blip &blip, shared_ptr stream, shared_ptr mainStream) { //OfficeArtBStoreContainerFileBlock structure is described at p.59 [MS-ODRAW] unsigned int count = readFBSE(blip.storeEntry, stream); - if( blip.storeEntry.offsetInDelay != (unsigned int)(-1)) { - mainStream->seek(blip.storeEntry.offsetInDelay, true); //see p.70 [MS-ODRAW] + if (blip.storeEntry.offsetInDelay != (unsigned int)-1) { + if (mainStream->seek(blip.storeEntry.offsetInDelay, true)) { //see p.70 [MS-ODRAW] + //TODO maybe we should stop reading float images here + ZLLogger::Instance().println("DocPlugin", "DocFloatImageReader: problems with seeking for offset"); + return count; + } } RecordHeader header; unsigned int count2 = readRecordHeader(header, mainStream); @@ -330,7 +339,7 @@ unsigned int DocFloatImageReader::readArrayFOPTE(std::vector &fopteArray, count += readFOPTE(fopte, stream); fopteArray.push_back(fopte); } - for (size_t i = 0; i < fopteArray.size(); ++i) { + for (std::size_t i = 0; i < fopteArray.size(); ++i) { if (fopteArray.at(i).isComplex) { stream->seek(fopteArray.at(i).value, false); count += fopteArray.at(i).value; @@ -342,29 +351,34 @@ unsigned int DocFloatImageReader::readArrayFOPTE(std::vector &fopteArray, unsigned int DocFloatImageReader::readFOPTE(FOPTE &fopte, shared_ptr stream) { //OfficeArtFOPTE structure is described at p.32 [MS-ODRAW] unsigned int dtemp; - dtemp = read2Bytes (stream); + dtemp = read2Bytes(stream); fopte.pId = (dtemp & 0x3fff); fopte.isBlipId = ((dtemp & 0x4000) >> 14) == 0x1; fopte.isComplex = ((dtemp & 0x8000) >> 15) == 0x1; - fopte.value = read4Bytes (stream); + fopte.value = read4Bytes(stream); return 6; } unsigned int DocFloatImageReader::read1Byte(shared_ptr stream) { char b[1]; - stream->read(b, 1); + if (stream->read(b, 1) != 1) { + return 0; + } return OleUtil::getU1Byte(b, 0); } unsigned int DocFloatImageReader::read2Bytes(shared_ptr stream) { char b[2]; - stream->read(b, 2); + if (stream->read(b, 2) != 2) { + return 0; + } return OleUtil::getU2Bytes(b, 0); } unsigned int DocFloatImageReader::read4Bytes(shared_ptr stream) { char b[4]; - stream->read(b, 4); + if (stream->read(b, 4) != 4) { + return 0; + } return OleUtil::getU4Bytes(b, 0); } - diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocMetaInfoReader.h b/jni/NativeFormats/fbreader/src/formats/doc/DocMetaInfoReader.h index 30e9ec020..db26d29e8 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocMetaInfoReader.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocMetaInfoReader.h @@ -34,7 +34,7 @@ public: /* void startElementHandler(int tag, const char **attributes); void endElementHandler(int tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); */ private: diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp index 0cfe02ea7..6a20e685f 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocPlugin.cpp @@ -53,9 +53,9 @@ bool DocPlugin::readMetaInfo(Book &book) const { return false; } - shared_ptr stream = new DocCharStream(book.file(), 50000); + shared_ptr stream = new DocAnsiStream(book.file(), 50000); if (!detectEncodingAndLanguage(book, *stream)) { - stream = new DocAnsiStream(book.file(), 50000); + stream = new DocUcs2Stream(book.file(), 50000); detectLanguage(book, *stream, ZLEncodingConverter::UTF8, true); } diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.cpp b/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.cpp index b4ae346c2..b21e15a25 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.cpp @@ -27,49 +27,54 @@ class DocReader : public OleStreamReader { public: - DocReader(char *buffer, size_t maxSize); + DocReader(char *buffer, std::size_t maxSize); ~DocReader(); - size_t readSize() const; + std::size_t readSize() const; private: bool readStream(OleMainStream &stream); - void dataHandler(const char *buffer, size_t len); - void ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); - void footnoteHandler(); + void ansiDataHandler(const char *buffer, std::size_t len); + void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); + void footnotesStartHandler(); protected: char *myBuffer; - const size_t myMaxSize; - size_t myActualSize; -}; - -class DocCharReader : public DocReader { - -public: - DocCharReader(char *buffer, size_t maxSize); - ~DocCharReader(); - -private: - void dataHandler(const char *buffer, size_t len); + const std::size_t myMaxSize; + std::size_t myActualSize; }; class DocAnsiReader : public DocReader { public: - DocAnsiReader(char *buffer, size_t maxSize); + DocAnsiReader(char *buffer, std::size_t maxSize); ~DocAnsiReader(); private: - void ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); + void ansiDataHandler(const char *buffer, std::size_t len); }; -DocReader::DocReader(char *buffer, size_t maxSize) : myBuffer(buffer), myMaxSize(maxSize), myActualSize(0) { +class DocUcs2Reader : public DocReader { + +public: + DocUcs2Reader(char *buffer, std::size_t maxSize); + ~DocUcs2Reader(); + +private: + void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol); +}; + +DocReader::DocReader(char *buffer, std::size_t maxSize) : myBuffer(buffer), myMaxSize(maxSize), myActualSize(0) { } DocReader::~DocReader() { } bool DocReader::readStream(OleMainStream &stream) { + // TODO make 2 optmizations: + // 1) If another piece is too big, reading of next piece can be stopped if some size parameter will be specified + // (it can be transfered as a parameter (with default 0 value, that means no need to use it) to readNextPiece method) + // 2) We can specify as a parameter for readNextPiece, what kind of piece should be read next (ANSI or not ANSI). + // As type of piece is known already, there's no necessary to read other pieces. while (myActualSize < myMaxSize) { if (!readNextPiece(stream)) { break; @@ -78,50 +83,50 @@ bool DocReader::readStream(OleMainStream &stream) { return true; } -void DocReader::dataHandler(const char*, size_t) { +void DocReader::ansiDataHandler(const char*, std::size_t) { } -void DocReader::ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char) { +void DocReader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char) { } -void DocReader::footnoteHandler() { +void DocReader::footnotesStartHandler() { } -size_t DocReader::readSize() const { +std::size_t DocReader::readSize() const { return myActualSize; } -DocCharReader::DocCharReader(char *buffer, size_t maxSize) : DocReader(buffer, maxSize) { -} - -DocCharReader::~DocCharReader() { -} - -void DocCharReader::dataHandler(const char *buffer, size_t dataLength) { - if (myActualSize < myMaxSize) { - const size_t len = std::min(dataLength, myMaxSize - myActualSize); - strncpy(myBuffer + myActualSize, buffer, len); - myActualSize += len; - } -} - -DocAnsiReader::DocAnsiReader(char *buffer, size_t maxSize) : DocReader(buffer, maxSize) { +DocAnsiReader::DocAnsiReader(char *buffer, std::size_t maxSize) : DocReader(buffer, maxSize) { } DocAnsiReader::~DocAnsiReader() { } -void DocAnsiReader::ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { +void DocAnsiReader::ansiDataHandler(const char *buffer, std::size_t dataLength) { if (myActualSize < myMaxSize) { - char buffer[4]; - const size_t dataLength = ZLUnicodeUtil::ucs2ToUtf8(buffer, symbol); - const size_t len = std::min(dataLength, myMaxSize - myActualSize); - strncpy(myBuffer + myActualSize, buffer, len); + const std::size_t len = std::min(dataLength, myMaxSize - myActualSize); + std::strncpy(myBuffer + myActualSize, buffer, len); myActualSize += len; } } -DocStream::DocStream(const ZLFile& file, size_t maxSize) : myFile(file), myBuffer(0), mySize(maxSize) { +DocUcs2Reader::DocUcs2Reader(char *buffer, std::size_t maxSize) : DocReader(buffer, maxSize) { +} + +DocUcs2Reader::~DocUcs2Reader() { +} + +void DocUcs2Reader::ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) { + if (myActualSize < myMaxSize) { + char buffer[4]; + const std::size_t dataLength = ZLUnicodeUtil::ucs2ToUtf8(buffer, symbol); + const std::size_t len = std::min(dataLength, myMaxSize - myActualSize); + std::strncpy(myBuffer + myActualSize, buffer, len); + myActualSize += len; + } +} + +DocStream::DocStream(const ZLFile& file, std::size_t maxSize) : myFile(file), myBuffer(0), mySize(maxSize) { } DocStream::~DocStream() { @@ -137,7 +142,7 @@ bool DocStream::open() { if (stream.isNull() || !stream->open()) { return false; } - if (!reader->readDocument(stream)) { + if (!reader->readDocument(stream, false)) { return false; } mySize = reader->readSize(); @@ -145,10 +150,10 @@ bool DocStream::open() { return true; } -size_t DocStream::read(char *buffer, size_t maxSize) { +std::size_t DocStream::read(char *buffer, std::size_t maxSize) { maxSize = std::min(maxSize, mySize - myOffset); - if ((buffer != 0) && (myBuffer !=0)) { - memcpy(buffer, myBuffer + myOffset, maxSize); + if (buffer != 0 && myBuffer != 0) { + std::memcpy(buffer, myBuffer + myOffset, maxSize); } myOffset += maxSize; return maxSize; @@ -165,33 +170,33 @@ void DocStream::seek(int offset, bool absoluteOffset) { if (!absoluteOffset) { offset += myOffset; } - myOffset = std::min(mySize, (size_t)std::max(0, offset)); + myOffset = std::min(mySize, (std::size_t)std::max(0, offset)); } -size_t DocStream::offset() const { +std::size_t DocStream::offset() const { return myOffset; } -size_t DocStream::sizeOfOpened() { +std::size_t DocStream::sizeOfOpened() { return mySize; } -DocCharStream::DocCharStream(const ZLFile& file, size_t maxSize) : DocStream(file, maxSize) { -} - -DocCharStream::~DocCharStream() { -} - -shared_ptr DocCharStream::createReader(char *buffer, size_t maxSize) { - return new DocCharReader(buffer, maxSize); -} - -DocAnsiStream::DocAnsiStream(const ZLFile& file, size_t maxSize) : DocStream(file, maxSize) { +DocAnsiStream::DocAnsiStream(const ZLFile& file, std::size_t maxSize) : DocStream(file, maxSize) { } DocAnsiStream::~DocAnsiStream() { } -shared_ptr DocAnsiStream::createReader(char *buffer, size_t maxSize) { +shared_ptr DocAnsiStream::createReader(char *buffer, std::size_t maxSize) { return new DocAnsiReader(buffer, maxSize); } + +DocUcs2Stream::DocUcs2Stream(const ZLFile& file, std::size_t maxSize) : DocStream(file, maxSize) { +} + +DocUcs2Stream::~DocUcs2Stream() { +} + +shared_ptr DocUcs2Stream::createReader(char *buffer, std::size_t maxSize) { + return new DocUcs2Reader(buffer, maxSize); +} diff --git a/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.h b/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.h index d9a08f27f..4b1538a01 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/DocStreams.h @@ -28,46 +28,46 @@ class DocReader; class DocStream : public ZLInputStream { public: - DocStream(const ZLFile& file, size_t maxSize); + DocStream(const ZLFile& file, std::size_t maxSize); ~DocStream(); private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); protected: - virtual shared_ptr createReader(char *buffer, size_t maxSize) = 0; + virtual shared_ptr createReader(char *buffer, std::size_t maxSize) = 0; private: const ZLFile myFile; char *myBuffer; - size_t mySize; - size_t myOffset; -}; - -class DocCharStream : public DocStream { - -public: - DocCharStream(const ZLFile& file, size_t maxSize); - ~DocCharStream(); - -private: - shared_ptr createReader(char *buffer, size_t maxSize); + std::size_t mySize; + std::size_t myOffset; }; class DocAnsiStream : public DocStream { public: - DocAnsiStream(const ZLFile& file, size_t maxSize); + DocAnsiStream(const ZLFile& file, std::size_t maxSize); ~DocAnsiStream(); private: - shared_ptr createReader(char *buffer, size_t maxSize); + shared_ptr createReader(char *buffer, std::size_t maxSize); +}; + +class DocUcs2Stream : public DocStream { + +public: + DocUcs2Stream(const ZLFile& file, std::size_t maxSize); + ~DocUcs2Stream(); + +private: + shared_ptr createReader(char *buffer, std::size_t maxSize); }; #endif /* __DOCSTREAMS_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.cpp b/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.cpp index 77ff10599..fe829e67e 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.cpp @@ -56,12 +56,12 @@ OleMainStream::FloatImageInfo::FloatImageInfo() : ShapeId(0) { OleMainStream::OleMainStream(shared_ptr storage, OleEntry oleEntry, shared_ptr stream) : OleStream(storage, oleEntry, stream) { } -bool OleMainStream::open() { +bool OleMainStream::open(bool doReadFormattingData) { if (OleStream::open() == false) { return false; } - static const size_t HEADER_SIZE = 768; //size of data in header of main stream + static const std::size_t HEADER_SIZE = 768; //size of data in header of main stream char headerBuffer[HEADER_SIZE]; seek(0, true); @@ -83,7 +83,8 @@ bool OleMainStream::open() { if (!result) { // cant't find table stream (that can be only in case if file format is below Word 7/8), so building simple table stream - // TODO: CHECK may be not all old documents have ANSI + // TODO: CHECK may be not all old documents have ANSI + ZLLogger::Instance().println("DocPlugin", "cant't find table stream, building own simple piece table, that includes all charachters"); Piece piece = {myStartOfText, myEndOfText - myStartOfText, true, Piece::PIECE_TEXT, 0}; myPieces.push_back(piece); return true; @@ -92,10 +93,14 @@ bool OleMainStream::open() { result = readPieceTable(headerBuffer, tableEntry); if (!result) { - ZLLogger::Instance().println("OleMainStream", "error during reading piece table"); + ZLLogger::Instance().println("DocPlugin", "error during reading piece table"); return false; } + if (!doReadFormattingData) { + return true; + } + OleEntry dataEntry; if (myStorage->getEntryByName("Data", dataEntry)) { myDataStream = new OleStream(myStorage, dataEntry, myBaseStream); @@ -155,27 +160,27 @@ bool OleMainStream::readFIB(const char *headerBuffer) { int flags = OleUtil::getU2Bytes(headerBuffer, 0xA); //offset for flags if (flags & 0x0004) { //flag for complex format - ZLLogger::Instance().println("OleMainStream", "This was fast-saved. Some information is lost"); + ZLLogger::Instance().println("DocPlugin", "This was fast-saved. Some information is lost"); //lostInfo = (flags & 0xF0) >> 4); } if (flags & 0x1000) { //flag for using extending charset - ZLLogger::Instance().println("OleMainStream", "File uses extended character set (get_word8_char)"); + ZLLogger::Instance().println("DocPlugin", "File uses extended character set (get_word8_char)"); } else { - ZLLogger::Instance().println("OleMainStream", "File uses get_8bit_char character set"); + ZLLogger::Instance().println("DocPlugin", "File uses get_8bit_char character set"); } if (flags & 0x100) { //flag for encrypted files - ZLLogger::Instance().println("OleMainStream", "File is encrypted"); + ZLLogger::Instance().println("DocPlugin", "File is encrypted"); // Encryption key = %08lx ; NumUtil::get4Bytes(header, 14) return false; } unsigned int charset = OleUtil::getU2Bytes(headerBuffer, 0x14); //offset for charset number if (charset && charset != 0x100) { //0x100 = default charset - ZLLogger::Instance().println("OleMainStream", "Using not default character set %d"); + ZLLogger::Instance().println("DocPlugin", "Using not default character set %d"); } else { - ZLLogger::Instance().println("OleMainStream", "Using default character set"); + ZLLogger::Instance().println("DocPlugin", "Using default character set"); } myStartOfText = OleUtil::get4Bytes(headerBuffer, 0x18); //offset for start of text value @@ -189,7 +194,7 @@ void OleMainStream::splitPieces(const Pieces &s, Pieces &dest1, Pieces &dest2, P dest2.clear(); int sumLength = 0; - size_t i = 0; + std::size_t i = 0; for (i = 0; i < source.size(); ++i) { Piece piece = source.at(i); if (piece.Length + sumLength >= boundary) { @@ -229,17 +234,27 @@ std::string OleMainStream::getPiecesTableBuffer(const char *headerBuffer, OleStr //1 step : loading CLX table from table stream char *clxBuffer = new char[clxLength]; - tableStream.seek(clxOffset, true); - tableStream.read(clxBuffer, clxLength); + if (!tableStream.seek(clxOffset, true)) { + ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- error for seeking to CLX structure"); + return std::string(); + } + if (tableStream.read(clxBuffer, clxLength) != clxLength) { + ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure length is invalid"); + return std::string(); + } std::string clx(clxBuffer, clxLength); delete[] clxBuffer; //2 step: searching for pieces table buffer at CLX //(determines it by 0x02 as start symbol) - size_t from = 0; - size_t i; + std::size_t from = 0; + std::size_t i; std::string pieceTableBuffer; while ((i = clx.find_first_of(0x02, from)) != std::string::npos) { + if (clx.size() < i + 1 + 4) { + ZLLogger::Instance().println("DocPlugin", "getPiecesTableBuffer -- CLX structure has invalid format"); + return std::string(); + } unsigned int pieceTableLength = OleUtil::getU4Bytes(clx.c_str(), i + 1); pieceTableBuffer = std::string(clx, i + 1 + 4); if (pieceTableBuffer.length() != pieceTableLength) { @@ -256,6 +271,10 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab OleStream tableStream(myStorage, tableEntry, myBaseStream); std::string piecesTableBuffer = getPiecesTableBuffer(headerBuffer, tableStream); + if (piecesTableBuffer.empty()) { + return false; + } + //getting count of Character Positions for different types of subdocuments in Main Stream int ccpText = OleUtil::get4Bytes(headerBuffer, 0x004C); //text int ccpFtn = OleUtil::get4Bytes(headerBuffer, 0x0050); //footnote subdocument @@ -275,6 +294,10 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab std::vector cp; //array of character positions for pieces unsigned int j = 0; for (j = 0; ; j += 4) { + if (piecesTableBuffer.size() < j + 4) { + ZLLogger::Instance().println("DocPlugin", "invalid piece table, cp ends not with a lastcp"); + break; + } int curCP = OleUtil::get4Bytes(piecesTableBuffer.c_str(), j); cp.push_back(curCP); if (curCP == lastCP) { @@ -282,15 +305,31 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab } } + if (cp.size() < 2) { + ZLLogger::Instance().println("DocPlugin", "invalid piece table, < 2 pieces"); + return false; + } + std::vector descriptors; - for (size_t k = 0; k < cp.size() - 1; ++k) { + for (std::size_t k = 0; k < cp.size() - 1; ++k) { //j + 4, because it should be taken after CP in PiecesTable Buffer //k * 8, because it should be taken 8 byte for each descriptor - descriptors.push_back(piecesTableBuffer.substr(j + 4 + k * 8, 8)); + std::size_t substrFrom = j + 4 + k * 8; + if (piecesTableBuffer.size() < substrFrom + 8) { + ZLLogger::Instance().println("DocPlugin", "invalid piece table, problems with descriptors reading"); + break; + } + descriptors.push_back(piecesTableBuffer.substr(substrFrom, 8)); } //filling the Pieces vector - for (size_t i = 0; i < descriptors.size(); ++i) { + std::size_t minValidSize = std::min(cp.size() - 1, descriptors.size()); + if (minValidSize == 0) { + ZLLogger::Instance().println("DocPlugin", "invalid piece table, there are no pieces"); + return false; + } + + for (std::size_t i = 0; i < minValidSize; ++i) { //4byte integer with offset and ANSI flag int fcValue = OleUtil::get4Bytes(descriptors.at(i).c_str(), 0x2); //offset for piece structure Piece piece; @@ -306,18 +345,18 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab splitPieces(piecesFootnote, piecesFootnote, piecesOther, Piece::PIECE_FOOTNOTE, Piece::PIECE_OTHER, ccpFtn); myPieces.clear(); - for (size_t i = 0; i < piecesText.size(); ++i) { + for (std::size_t i = 0; i < piecesText.size(); ++i) { myPieces.push_back(piecesText.at(i)); } - for (size_t i = 0; i < piecesFootnote.size(); ++i) { + for (std::size_t i = 0; i < piecesFootnote.size(); ++i) { myPieces.push_back(piecesFootnote.at(i)); } - for (size_t i = 0; i < piecesOther.size(); ++i) { + for (std::size_t i = 0; i < piecesOther.size(); ++i) { myPieces.push_back(piecesOther.at(i)); } //converting length and offset depending on isANSI - for (size_t i = 0; i < myPieces.size(); ++i) { + for (std::size_t i = 0; i < myPieces.size(); ++i) { Piece &piece = myPieces.at(i); if (!piece.IsANSI) { piece.Length *= 2; @@ -328,7 +367,7 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab //filling startCP field unsigned int curStartCP = 0; - for (size_t i = 0; i < myPieces.size(); ++i) { + for (std::size_t i = 0; i < myPieces.size(); ++i) { Piece &piece = myPieces.at(i); piece.startCP = curStartCP; if (piece.IsANSI) { @@ -343,7 +382,7 @@ bool OleMainStream::readPieceTable(const char *headerBuffer, const OleEntry &tab bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tableEntry) { //SttbfBkmk structure is a table of bookmark name strings unsigned int beginNamesInfo = OleUtil::getU4Bytes(headerBuffer, 0x142); // address of SttbfBkmk structure - size_t namesInfoLength = (size_t)OleUtil::getU4Bytes(headerBuffer, 0x146); // length of SttbfBkmk structure + std::size_t namesInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x146); // length of SttbfBkmk structure if (namesInfoLength == 0) { return true; //there's no bookmarks @@ -360,7 +399,11 @@ bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tabl std::vector names; unsigned int offset = 0x6; //initial offset for (unsigned int i = 0; i < recordsNumber; ++i) { - unsigned int length = OleUtil::getU2Bytes(buffer.c_str(), offset) * 2; //legnth of string in bytes + if (buffer.size() < offset + 2) { + ZLLogger::Instance().println("DocPlugin", "problmes with reading bookmarks names"); + break; + } + unsigned int length = OleUtil::getU2Bytes(buffer.c_str(), offset) * 2; //length of string in bytes ZLUnicodeUtil::Ucs2String name; for (unsigned int j = 0; j < length; j+=2) { char ch1 = buffer.at(offset + 2 + j); @@ -376,7 +419,7 @@ bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tabl //plcfBkmkf structure is table recording beginning CPs of bookmarks unsigned int beginCharPosInfo = OleUtil::getU4Bytes(headerBuffer, 0x14A); // address of plcfBkmkf structure - size_t charPosInfoLen = (size_t)OleUtil::getU4Bytes(headerBuffer, 0x14E); // length of plcfBkmkf structure + std::size_t charPosInfoLen = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x14E); // length of plcfBkmkf structure if (charPosInfoLen == 0) { return true; //there's no bookmarks @@ -387,13 +430,13 @@ bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tabl } static const unsigned int BKF_SIZE = 4; - size_t size = calcCountOfPLC(charPosInfoLen, BKF_SIZE); + std::size_t size = calcCountOfPLC(charPosInfoLen, BKF_SIZE); std::vector charPage; - for (size_t index = 0, offset = 0; index < size; ++index, offset += 4) { + for (std::size_t index = 0, offset = 0; index < size; ++index, offset += 4) { charPage.push_back(OleUtil::getU4Bytes(buffer.c_str(), offset)); } - for (size_t i = 0; i < names.size(); ++i) { + for (std::size_t i = 0; i < names.size(); ++i) { if (i >= charPage.size()) { break; //for the case if something in these structures goes wrong, to not to lose all bookmarks } @@ -409,28 +452,32 @@ bool OleMainStream::readBookmarks(const char *headerBuffer, const OleEntry &tabl bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tableEntry) { //STSH structure is a stylesheet unsigned int beginStshInfo = OleUtil::getU4Bytes(headerBuffer, 0xa2); // address of STSH structure - size_t stshInfoLength = (size_t)OleUtil::getU4Bytes(headerBuffer, 0xa6); // length of STSH structure + std::size_t stshInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xa6); // length of STSH structure OleStream tableStream(myStorage, tableEntry, myBaseStream); char *buffer = new char[stshInfoLength]; - tableStream.seek(beginStshInfo, true); + if (!tableStream.seek(beginStshInfo, true)) { + ZLLogger::Instance().println("DocPlugin", "problems with reading STSH structure"); + return false; + } if (tableStream.read(buffer, stshInfoLength) != stshInfoLength) { + ZLLogger::Instance().println("DocPlugin", "problems with reading STSH structure, invalid length"); return false; } - size_t stdCount = (size_t)OleUtil::getU2Bytes(buffer, 2); - size_t stdBaseInFile = (size_t)OleUtil::getU2Bytes(buffer, 4); + std::size_t stdCount = (std::size_t)OleUtil::getU2Bytes(buffer, 2); + std::size_t stdBaseInFile = (std::size_t)OleUtil::getU2Bytes(buffer, 4); myStyleSheet.resize(stdCount); std::vector isFilled; isFilled.resize(stdCount, false); - size_t stdLen = 0; + std::size_t stdLen = 0; bool styleSheetWasChanged = false; do { //make it in while loop, because some base style can be after their successors styleSheetWasChanged = false; - for (size_t index = 0, offset = 2 + (size_t)OleUtil::getU2Bytes(buffer, 0); index < stdCount; index++, offset += 2 + stdLen) { - stdLen = (size_t)OleUtil::getU2Bytes(buffer, offset); + for (std::size_t index = 0, offset = 2 + (std::size_t)OleUtil::getU2Bytes(buffer, 0); index < stdCount; index++, offset += 2 + stdLen) { + stdLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset); if (isFilled.at(index)) { continue; } @@ -468,8 +515,8 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab isFilled[index] = true; styleSheetWasChanged = true; - size_t pos = 2 + stdBaseInFile; - size_t nameLen = (size_t)OleUtil::getU2Bytes(buffer, offset + pos); + std::size_t pos = 2 + stdBaseInFile; + std::size_t nameLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); nameLen = nameLen * 2 + 2; //from Unicode characters to bytes + Unicode null charachter length pos += 2 + nameLen; if (pos % 2 != 0) { @@ -478,7 +525,7 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab if (pos >= stdLen) { continue; } - size_t upxLen = (size_t)OleUtil::getU2Bytes(buffer, offset + pos); + std::size_t upxLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); if (pos + upxLen > stdLen) { //UPX length too large continue; @@ -494,7 +541,7 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab if (pos % 2 != 0) { ++pos; } - upxLen = (size_t)OleUtil::getU2Bytes(buffer, offset + pos); + upxLen = (std::size_t)OleUtil::getU2Bytes(buffer, offset + pos); } if (upxLen == 0 || pos + upxLen > stdLen) { //too small/too large @@ -516,7 +563,7 @@ bool OleMainStream::readStylesheet(const char *headerBuffer, const OleEntry &tab bool OleMainStream::readCharInfoTable(const char *headerBuffer, const OleEntry &tableEntry) { //PlcfbteChpx structure is table with formatting for particular run of text unsigned int beginCharInfo = OleUtil::getU4Bytes(headerBuffer, 0xfa); // address of PlcfbteChpx structure - size_t charInfoLength = (size_t)OleUtil::getU4Bytes(headerBuffer, 0xfe); // length of PlcfbteChpx structure + std::size_t charInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xfe); // length of PlcfbteChpx structure if (charInfoLength < 4) { return false; } @@ -528,14 +575,14 @@ bool OleMainStream::readCharInfoTable(const char *headerBuffer, const OleEntry & } static const unsigned int CHPX_SIZE = 4; - size_t size = calcCountOfPLC(charInfoLength, CHPX_SIZE); + std::size_t size = calcCountOfPLC(charInfoLength, CHPX_SIZE); std::vector charBlocks; - for (size_t index = 0, offset = (size + 1) * 4; index < size; ++index, offset += CHPX_SIZE) { + for (std::size_t index = 0, offset = (size + 1) * 4; index < size; ++index, offset += CHPX_SIZE) { charBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), offset)); } char *formatPageBuffer = new char[OleStorage::BBD_BLOCK_SIZE]; - for (size_t index = 0; index < charBlocks.size(); ++index) { + for (std::size_t index = 0; index < charBlocks.size(); ++index) { seek(charBlocks.at(index) * OleStorage::BBD_BLOCK_SIZE, true); if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) { return false; @@ -587,16 +634,15 @@ bool OleMainStream::readFloatingImages(const char *headerBuffer, const OleEntry return false; } - static const unsigned int SPA_SIZE = 26; - size_t size = calcCountOfPLC(picturesInfoLength, SPA_SIZE); + std::size_t size = calcCountOfPLC(picturesInfoLength, SPA_SIZE); std::vector picturesBlocks; - for (size_t index = 0, tOffset = 0; index < size; ++index, tOffset += 4) { + for (std::size_t index = 0, tOffset = 0; index < size; ++index, tOffset += 4) { picturesBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset)); } - for (size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += SPA_SIZE) { + for (std::size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += SPA_SIZE) { unsigned int spid = OleUtil::getU4Bytes(buffer.c_str(), tOffset); FloatImageInfo info; unsigned int charPos = picturesBlocks.at(index); @@ -626,7 +672,7 @@ bool OleMainStream::readFloatingImages(const char *headerBuffer, const OleEntry bool OleMainStream::readParagraphStyleTable(const char *headerBuffer, const OleEntry &tableEntry) { //PlcBtePapx structure is table with formatting for all paragraphs unsigned int beginParagraphInfo = OleUtil::getU4Bytes(headerBuffer, 0x102); // address of PlcBtePapx structure - size_t paragraphInfoLength = (size_t)OleUtil::getU4Bytes(headerBuffer, 0x106); // length of PlcBtePapx structure + std::size_t paragraphInfoLength = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0x106); // length of PlcBtePapx structure if (paragraphInfoLength < 4) { return false; } @@ -638,15 +684,15 @@ bool OleMainStream::readParagraphStyleTable(const char *headerBuffer, const OleE } static const unsigned int PAPX_SIZE = 4; - size_t size = calcCountOfPLC(paragraphInfoLength, PAPX_SIZE); + std::size_t size = calcCountOfPLC(paragraphInfoLength, PAPX_SIZE); std::vector paragraphBlocks; - for (size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += PAPX_SIZE) { + for (std::size_t index = 0, tOffset = (size + 1) * 4; index < size; ++index, tOffset += PAPX_SIZE) { paragraphBlocks.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset)); } char *formatPageBuffer = new char[OleStorage::BBD_BLOCK_SIZE]; - for (size_t index = 0; index < paragraphBlocks.size(); ++index) { + for (std::size_t index = 0; index < paragraphBlocks.size(); ++index) { seek(paragraphBlocks.at(index) * OleStorage::BBD_BLOCK_SIZE, true); if (read(formatPageBuffer, OleStorage::BBD_BLOCK_SIZE) != OleStorage::BBD_BLOCK_SIZE) { return false; @@ -687,7 +733,7 @@ bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEnt unsigned int beginOfText = OleUtil::getU4Bytes(headerBuffer, 0x18); //address of text's begin in main stream unsigned int beginSectInfo = OleUtil::getU4Bytes(headerBuffer, 0xca); //address if PlcfSed structure - size_t sectInfoLen = (size_t)OleUtil::getU4Bytes(headerBuffer, 0xce); //length of PlcfSed structure + std::size_t sectInfoLen = (std::size_t)OleUtil::getU4Bytes(headerBuffer, 0xce); //length of PlcfSed structure if (sectInfoLen < 4) { return false; } @@ -699,24 +745,24 @@ bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEnt } static const unsigned int SED_SIZE = 12; - size_t decriptorsCount = calcCountOfPLC(sectInfoLen, SED_SIZE); + std::size_t decriptorsCount = calcCountOfPLC(sectInfoLen, SED_SIZE); //saving the section offsets (in character positions) std::vector charPos; - for (size_t index = 0, tOffset = 0; index < decriptorsCount; ++index, tOffset += 4) { + for (std::size_t index = 0, tOffset = 0; index < decriptorsCount; ++index, tOffset += 4) { unsigned int ulTextOffset = OleUtil::getU4Bytes(buffer.c_str(), tOffset); charPos.push_back(beginOfText + ulTextOffset); } //saving sepx offsets std::vector sectPage; - for (size_t index = 0, tOffset = (decriptorsCount + 1) * 4; index < decriptorsCount; ++index, tOffset += SED_SIZE) { + for (std::size_t index = 0, tOffset = (decriptorsCount + 1) * 4; index < decriptorsCount; ++index, tOffset += SED_SIZE) { sectPage.push_back(OleUtil::getU4Bytes(buffer.c_str(), tOffset + 2)); } //reading the section properties char tmpBuffer[2]; - for (size_t index = 0; index < sectPage.size(); ++index) { + for (std::size_t index = 0; index < sectPage.size(); ++index) { if (sectPage.at(index) == 0xffffffffUL) { //check for invalid record, to make default section info SectionInfo sectionInfo; sectionInfo.CharPosition = charPos.at(index); @@ -730,7 +776,7 @@ bool OleMainStream::readSectionsInfoTable(const char *headerBuffer, const OleEnt if (read(tmpBuffer, 2) != 2) { continue; } - size_t bytes = 2 + (size_t)OleUtil::getU2Bytes(tmpBuffer, 0); + std::size_t bytes = 2 + (std::size_t)OleUtil::getU2Bytes(tmpBuffer, 0); if (!seek(sectPage.at(index), true)) { continue; @@ -863,9 +909,9 @@ void OleMainStream::getCharInfo(unsigned int chpxOffset, unsigned int /*styleId* } -void OleMainStream::getSectionInfo(const char *grpprlBuffer, size_t bytes, SectionInfo §ionInfo) { +void OleMainStream::getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo §ionInfo) { unsigned int tmp; - size_t offset = 0; + std::size_t offset = 0; while (bytes >= offset + 2) { switch (OleUtil::getU2Bytes(grpprlBuffer, offset)) { case 0x3009: //new page @@ -916,7 +962,7 @@ OleMainStream::Style OleMainStream::getStyleFromStylesheet(unsigned int styleId, //TODO optimize it: StyleSheet can be map structure with styleId key Style style; if (styleId != Style::STYLE_INVALID && styleId != Style::STYLE_NIL && styleId != Style::STYLE_USER) { - for (size_t index = 0; index < stylesheet.size(); ++index) { + for (std::size_t index = 0; index < stylesheet.size(); ++index) { if (stylesheet.at(index).StyleIdCurrent == styleId) { return stylesheet.at(index); } @@ -942,7 +988,7 @@ int OleMainStream::getStyleIndex(unsigned int styleId, const std::vector & unsigned int OleMainStream::getStyleIdByCharPos(unsigned int charPos, const StyleInfoList &styleInfoList) { unsigned int styleId = Style::STYLE_INVALID; - for (size_t i = 0; i < styleInfoList.size(); ++i) { + for (std::size_t i = 0; i < styleInfoList.size(); ++i) { const Style &info = styleInfoList.at(i).second; if (i == styleInfoList.size() - 1) { //if last styleId = info.StyleIdCurrent; @@ -970,8 +1016,8 @@ bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos, return false; } - size_t pieceNumber = 0; - for (size_t i = 0; i < pieces.size(); ++i) { + std::size_t pieceNumber = 0; + for (std::size_t i = 0; i < pieces.size(); ++i) { if (i == pieces.size() - 1) { //if last pieceNumber = i; break; @@ -993,7 +1039,7 @@ bool OleMainStream::offsetToCharPos(unsigned int offset, unsigned int &charPos, return true; } -bool OleMainStream::readToBuffer(std::string &result, unsigned int offset, size_t length, OleStream &stream) { +bool OleMainStream::readToBuffer(std::string &result, unsigned int offset, std::size_t length, OleStream &stream) { char *buffer = new char[length]; stream.seek(offset, true); if (stream.read(buffer, length) != length) { diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.h b/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.h index 79c3d33eb..378f0378a 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleMainStream.h @@ -150,7 +150,7 @@ public: OleMainStream(shared_ptr storage, OleEntry oleEntry, shared_ptr stream); public: - bool open(); + bool open(bool doReadFormattingData); const Pieces &getPieces() const; const CharInfoList &getCharInfoList() const; const StyleInfoList &getStyleInfoList() const; @@ -179,7 +179,7 @@ private: //formatting reader helpers methods static unsigned int getPrlLength(const char *grpprlBuffer, unsigned int byteNumber); static void getCharInfo(unsigned int chpxOffset, unsigned int styleId, const char *grpprlBuffer, unsigned int bytes, CharInfo &charInfo); static void getStyleInfo(unsigned int papxOffset, const char *grpprlBuffer, unsigned int bytes, Style &styleInfo); - static void getSectionInfo(const char *grpprlBuffer, size_t bytes, SectionInfo §ionInfo); + static void getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo §ionInfo); static bool getInlineImageInfo(unsigned int chpxOffset, const char *grpprlBuffer, unsigned int bytes, InlineImageInfo &pictureInfo); static Style getStyleFromStylesheet(unsigned int styleId, const StyleSheet &stylesheet); @@ -187,7 +187,7 @@ private: //formatting reader helpers methods static unsigned int getStyleIdByCharPos(unsigned int offset, const StyleInfoList &styleInfoList); static bool offsetToCharPos(unsigned int offset, unsigned int &charPos, const Pieces &pieces); - static bool readToBuffer(std::string &result, unsigned int offset, size_t length, OleStream &stream); + static bool readToBuffer(std::string &result, unsigned int offset, std::size_t length, OleStream &stream); static unsigned int calcCountOfPLC(unsigned int totalSize, unsigned int elementSize); diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.cpp b/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.cpp index fbdb13513..016f9fd84 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.cpp @@ -24,7 +24,7 @@ #include -const size_t OleStorage::BBD_BLOCK_SIZE = 512; +const std::size_t OleStorage::BBD_BLOCK_SIZE = 512; OleStorage::OleStorage() { clear(); @@ -46,7 +46,7 @@ void OleStorage::clear() { -bool OleStorage::init(shared_ptr stream, size_t streamSize) { +bool OleStorage::init(shared_ptr stream, std::size_t streamSize) { clear(); myInputStream = stream; @@ -54,13 +54,13 @@ bool OleStorage::init(shared_ptr stream, size_t streamSize) { myInputStream->seek(0, true); char oleBuf[BBD_BLOCK_SIZE]; - size_t ret = myInputStream->read(oleBuf, BBD_BLOCK_SIZE); + std::size_t ret = myInputStream->read(oleBuf, BBD_BLOCK_SIZE); if (ret != BBD_BLOCK_SIZE) { clear(); return false; } static const char OLE_SIGN[] = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, 0}; - if (strncmp(oleBuf, OLE_SIGN, 8) != 0) { + if (std::strncmp(oleBuf, OLE_SIGN, 8) != 0) { clear(); return false; } @@ -85,11 +85,11 @@ bool OleStorage::readDIFAT(char *oleBuf) { //for files > 6.78 mb we need read additional DIFAT fields for (int i = 0; difatBlock > 0 && i < difatSectorNumbers; ++i) { - ZLLogger::Instance().println("OleStorage", "Read additional data for DIFAT"); + ZLLogger::Instance().println("DocPlugin", "Read additional data for DIFAT"); char buffer[mySectorSize]; myInputStream->seek(BBD_BLOCK_SIZE + difatBlock * mySectorSize, true); if (myInputStream->read(buffer, mySectorSize) != mySectorSize) { - ZLLogger::Instance().println("OleStorage", "Error read DIFAT!"); + ZLLogger::Instance().println("DocPlugin", "Error read DIFAT!"); return false; } for (unsigned int j = 0; j < (mySectorSize - 4); j += 4) { @@ -112,19 +112,19 @@ bool OleStorage::readBBD(char *oleBuf) { if (myDIFAT.size() < bbdNumberBlocks) { //TODO maybe add check on myDIFAT == bbdNumberBlocks - ZLLogger::Instance().println("OleStorage", "Wrong number of FAT blocks value"); + ZLLogger::Instance().println("DocPlugin", "Wrong number of FAT blocks value"); return false; } for (unsigned int i = 0; i < bbdNumberBlocks; ++i) { int bbdSector = myDIFAT.at(i); if (bbdSector >= (int)(myStreamSize / mySectorSize) || bbdSector < 0) { - ZLLogger::Instance().println("OleStorage", "Bad BBD entry!"); + ZLLogger::Instance().println("DocPlugin", "Bad BBD entry!"); return false; } myInputStream->seek(BBD_BLOCK_SIZE + bbdSector * mySectorSize, true); if (myInputStream->read(buffer, mySectorSize) != mySectorSize) { - ZLLogger::Instance().println("OleStorage", "Error during reading BBD!"); + ZLLogger::Instance().println("DocPlugin", "Error during reading BBD!"); return false; } for (unsigned int j = 0; j < mySectorSize; j += 4) { @@ -139,7 +139,7 @@ bool OleStorage::readSBD(char *oleBuf) { int sbdCount = OleUtil::get4Bytes(oleBuf, 0x40); //count of small sectors if (sbdCur <= 0) { - ZLLogger::Instance().println("OleStorage", "There's no SBD, don't read it"); + ZLLogger::Instance().println("DocPlugin", "There's no SBD, don't read it"); return true; } @@ -147,7 +147,7 @@ bool OleStorage::readSBD(char *oleBuf) { for (int i = 0; i < sbdCount; ++i) { if (i != 0) { if (sbdCur < 0 || (unsigned int)sbdCur >= myBBD.size()) { - ZLLogger::Instance().println("OleStorage", "error during parsing SBD"); + ZLLogger::Instance().println("DocPlugin", "error during parsing SBD"); return false; } sbdCur = myBBD.at(sbdCur); @@ -157,7 +157,7 @@ bool OleStorage::readSBD(char *oleBuf) { } myInputStream->seek(BBD_BLOCK_SIZE + sbdCur * mySectorSize, true); if (myInputStream->read(buffer, mySectorSize) != mySectorSize) { - ZLLogger::Instance().println("OleStorage", "reading error during parsing SBD"); + ZLLogger::Instance().println("DocPlugin", "reading error during parsing SBD"); return false; } for (unsigned int j = 0; j < mySectorSize; j += 4) { @@ -171,7 +171,7 @@ bool OleStorage::readSBD(char *oleBuf) { bool OleStorage::readProperties(char *oleBuf) { int propCur = OleUtil::get4Bytes(oleBuf, 0x30); //offset for address of sector with first property if (propCur < 0) { - ZLLogger::Instance().println("OleStorage", "Wrong first directory sector location"); + ZLLogger::Instance().println("DocPlugin", "Wrong first directory sector location"); return false; } @@ -179,13 +179,13 @@ bool OleStorage::readProperties(char *oleBuf) { do { myInputStream->seek(BBD_BLOCK_SIZE + propCur * mySectorSize, true); if (myInputStream->read(buffer, mySectorSize) != mySectorSize) { - ZLLogger::Instance().println("OleStorage", "Error during reading properties"); + ZLLogger::Instance().println("DocPlugin", "Error during reading properties"); return false; } for (unsigned int j = 0; j < mySectorSize; j += 128) { myProperties.push_back(std::string(buffer + j, 128)); } - if (propCur < 0 || (size_t)propCur >= myBBD.size()) { + if (propCur < 0 || (std::size_t)propCur >= myBBD.size()) { break; } propCur = myBBD.at(propCur); @@ -219,7 +219,7 @@ bool OleStorage::readOleEntry(int propNumber, OleEntry &e) { char oleType = property.at(0x42); //offset for Ole Type if (oleType != 1 && oleType != 2 && oleType != 3 && oleType != 5) { - ZLLogger::Instance().println("OleStorage", "entry -- not right ole type"); + ZLLogger::Instance().println("DocPlugin", "entry -- not right ole type"); return false; } @@ -243,14 +243,18 @@ bool OleStorage::readOleEntry(int propNumber, OleEntry &e) { e.isBigBlock = e.length >= 0x1000 || e.name == ROOT_ENTRY; // Read sector chain + if (property.size() < 0x74 + 4) { + ZLLogger::Instance().println("DocPlugin", "problems with reading ole entry"); + return false; + } int chainCur = OleUtil::get4Bytes(property.c_str(), 0x74); //offset for start block of entry if (chainCur >= 0 && (chainCur <= (int)(myStreamSize / (e.isBigBlock ? mySectorSize : myShortSectorSize)))) { //filling blocks with chains do { e.blocks.push_back((unsigned int)chainCur); - if (e.isBigBlock && (size_t)chainCur < myBBD.size()) { + if (e.isBigBlock && (std::size_t)chainCur < myBBD.size()) { chainCur = myBBD.at(chainCur); - } else if (!mySBD.empty() && (size_t)chainCur < mySBD.size()) { + } else if (!mySBD.empty() && (std::size_t)chainCur < mySBD.size()) { chainCur = mySBD.at(chainCur); } else { chainCur = -1; @@ -263,26 +267,38 @@ bool OleStorage::readOleEntry(int propNumber, OleEntry &e) { return true; } -unsigned int OleStorage::getFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber) const { - unsigned int res; +bool OleStorage::countFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber, unsigned int &result) const { + //TODO maybe better syntax can be used? + if (e.blocks.size() <= (std::size_t)blockNumber) { + ZLLogger::Instance().println("DocPlugin", "countFileOffsetOfBlock can't be done, blockNumber is invalid"); + return false; + } if (e.isBigBlock) { - res = BBD_BLOCK_SIZE + e.blocks.at(blockNumber) * mySectorSize; + result = BBD_BLOCK_SIZE + e.blocks.at(blockNumber) * mySectorSize; } else { unsigned int sbdPerSector = mySectorSize / myShortSectorSize; unsigned int sbdSectorNumber = e.blocks.at(blockNumber) / sbdPerSector; unsigned int sbdSectorMod = e.blocks.at(blockNumber) % sbdPerSector; - res = BBD_BLOCK_SIZE + myEntries.at(myRootEntryIndex).blocks.at(sbdSectorNumber) * mySectorSize + sbdSectorMod * myShortSectorSize; + if (myEntries.at(myRootEntryIndex).blocks.size() <= (std::size_t)sbdSectorNumber) { + ZLLogger::Instance().println("DocPlugin", "countFileOffsetOfBlock can't be done, invalid sbd data"); + return false; + } + result = BBD_BLOCK_SIZE + myEntries.at(myRootEntryIndex).blocks.at(sbdSectorNumber) * mySectorSize + sbdSectorMod * myShortSectorSize; } - return res; + return true; } bool OleStorage::getEntryByName(std::string name, OleEntry &returnEntry) const { - for (size_t i = 0; i < myEntries.size(); ++i) { + //TODO fix the workaround for duplicates streams: now it takes a stream with max length + unsigned int maxLength = 0; + for (std::size_t i = 0; i < myEntries.size(); ++i) { const OleEntry &entry = myEntries.at(i); - if (entry.name == name) { + if (entry.name == name && entry.length >= maxLength) { returnEntry = entry; - return true; + maxLength = entry.length; } } - return false; + return maxLength > 0; } + + diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.h b/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.h index 715ffa50c..584ee94dd 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStorage.h @@ -46,11 +46,11 @@ struct OleEntry { class OleStorage { public: - static const size_t BBD_BLOCK_SIZE; + static const std::size_t BBD_BLOCK_SIZE; public: OleStorage(); - bool init(shared_ptr, size_t streamSize); + bool init(shared_ptr, std::size_t streamSize); void clear(); const std::vector &getEntries() const; bool getEntryByName(std::string name, OleEntry &entry) const; @@ -59,7 +59,7 @@ public: unsigned int getShortSectorSize() const; public: //TODO make private - unsigned int getFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber) const; + bool countFileOffsetOfBlock(const OleEntry &e, unsigned int blockNumber, unsigned int &result) const; private: bool readDIFAT(char *oleBuf); @@ -75,7 +75,7 @@ private: shared_ptr myInputStream; unsigned int mySectorSize, myShortSectorSize; - size_t myStreamSize; + std::size_t myStreamSize; std::vector myDIFAT; //double-indirect file allocation table std::vector myBBD; //Big Block Depot std::vector mySBD; //Small Block Depot diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStream.cpp b/jni/NativeFormats/fbreader/src/formats/doc/OleStream.cpp index 5838a62ab..8de1cc447 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStream.cpp @@ -37,20 +37,20 @@ bool OleStream::open() { return true; } -size_t OleStream::read(char *buffer, size_t maxSize) { - size_t length = maxSize; - size_t readedBytes = 0; - size_t bytesLeftInCurBlock; +std::size_t OleStream::read(char *buffer, std::size_t maxSize) { + std::size_t length = maxSize; + std::size_t readedBytes = 0; + std::size_t bytesLeftInCurBlock; unsigned int newFileOffset; unsigned int curBlockNumber, modBlock; - size_t toReadBlocks, toReadBytes; + std::size_t toReadBlocks, toReadBytes; if (myOleOffset + length > myOleEntry.length) { length = myOleEntry.length - myOleOffset; } - size_t sectorSize = (size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); + std::size_t sectorSize = (std::size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); curBlockNumber = myOleOffset / sectorSize; if (curBlockNumber >= myOleEntry.blocks.size()) { @@ -65,20 +65,28 @@ size_t OleStream::read(char *buffer, size_t maxSize) { toReadBlocks = toReadBytes = 0; } - newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber) + modBlock; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { + return 0; + } + newFileOffset += modBlock; + myBaseStream->seek(newFileOffset, true); readedBytes = myBaseStream->read(buffer, std::min(length, bytesLeftInCurBlock)); - for (size_t i = 0; i < toReadBlocks; ++i) { + for (std::size_t i = 0; i < toReadBlocks; ++i) { if (++curBlockNumber >= myOleEntry.blocks.size()) { break; } - newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber); + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { + return readedBytes; + } myBaseStream->seek(newFileOffset, true); readedBytes += myBaseStream->read(buffer + readedBytes, std::min(length - readedBytes, sectorSize)); } if (toReadBytes > 0 && ++curBlockNumber < myOleEntry.blocks.size()) { - newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber); + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { + return readedBytes; + } myBaseStream->seek(newFileOffset, true); readedBytes += myBaseStream->read(buffer + readedBytes, toReadBytes); } @@ -113,13 +121,16 @@ bool OleStream::seek(unsigned int offset, bool absoluteOffset) { } unsigned int modBlock = newOleOffset % sectorSize; - newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, blockNumber) + modBlock; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, blockNumber, newFileOffset)) { + return false; + } + newFileOffset += modBlock; myBaseStream->seek(newFileOffset, true); myOleOffset = newOleOffset; return true; } -size_t OleStream::offset() { +std::size_t OleStream::offset() { return myOleOffset; } @@ -131,7 +142,11 @@ ZLFileImage::Blocks OleStream::getBlockPieceInfoList(unsigned int offset, unsign return list; } unsigned int modBlock = offset % sectorSize; - unsigned int startFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber) + modBlock; + unsigned int startFileOffset = 0; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, startFileOffset)) { + return ZLFileImage::Blocks(); + } + startFileOffset += modBlock; unsigned int bytesLeftInCurBlock = sectorSize - modBlock; unsigned int toReadBlocks = 0, toReadBytes = 0; @@ -147,13 +162,19 @@ ZLFileImage::Blocks OleStream::getBlockPieceInfoList(unsigned int offset, unsign if (++curBlockNumber >= myOleEntry.blocks.size()) { break; } - unsigned int newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber); + unsigned int newFileOffset = 0; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { + return ZLFileImage::Blocks(); + } unsigned int readbytes = std::min(size - readedBytes, sectorSize); list.push_back(ZLFileImage::Block(newFileOffset, readbytes)); readedBytes += readbytes; } if (toReadBytes > 0 && ++curBlockNumber < myOleEntry.blocks.size()) { - unsigned int newFileOffset = myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber); + unsigned int newFileOffset = 0; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, newFileOffset)) { + return ZLFileImage::Blocks(); + } unsigned int readbytes = toReadBytes; list.push_back(ZLFileImage::Block(newFileOffset, readbytes)); readedBytes += readbytes; @@ -169,7 +190,7 @@ ZLFileImage::Blocks OleStream::concatBlocks(const ZLFileImage::Blocks &blocks) { ZLFileImage::Blocks optList; ZLFileImage::Block curBlock = blocks.at(0); unsigned int nextOffset = curBlock.offset + curBlock.size; - for (size_t i = 1; i < blocks.size(); ++i) { + for (std::size_t i = 1; i < blocks.size(); ++i) { ZLFileImage::Block b = blocks.at(i); if (b.offset == nextOffset) { curBlock.size += b.size; @@ -184,12 +205,17 @@ ZLFileImage::Blocks OleStream::concatBlocks(const ZLFileImage::Blocks &blocks) { return optList; } -size_t OleStream::fileOffset() { - size_t sectorSize = (size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); +std::size_t OleStream::fileOffset() { + //TODO maybe remove this method, it doesn't use at this time + std::size_t sectorSize = (std::size_t)(myOleEntry.isBigBlock ? myStorage->getSectorSize() : myStorage->getShortSectorSize()); unsigned int curBlockNumber = myOleOffset / sectorSize; if (curBlockNumber >= myOleEntry.blocks.size()) { return 0; } unsigned int modBlock = myOleOffset % sectorSize; - return myStorage->getFileOffsetOfBlock(myOleEntry, curBlockNumber) + modBlock; + unsigned int curOffset = 0; + if (!myStorage->countFileOffsetOfBlock(myOleEntry, curBlockNumber, curOffset)) { + return 0; //TODO maybe remove -1? + } + return curOffset + modBlock; } diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStream.h b/jni/NativeFormats/fbreader/src/formats/doc/OleStream.h index 2108fa295..861c7cb3b 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStream.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStream.h @@ -31,17 +31,17 @@ public: public: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); public: bool seek(unsigned int offset, bool absoluteOffset); - size_t offset(); + std::size_t offset(); public: ZLFileImage::Blocks getBlockPieceInfoList(unsigned int offset, unsigned int size) const; static ZLFileImage::Blocks concatBlocks(const ZLFileImage::Blocks &blocks); - size_t fileOffset(); + std::size_t fileOffset(); public: bool eof() const; diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamParser.h b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamParser.h index 373e19a15..1adec2f5f 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamParser.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamParser.h @@ -87,15 +87,15 @@ private: protected: ZLUnicodeUtil::Ucs2String myBuffer; private: - size_t myCurBufferPosition; + std::size_t myCurBufferPosition; unsigned int myCurCharPos; - size_t myNextStyleInfoIndex; - size_t myNextCharInfoIndex; - size_t myNextBookmarkIndex; - size_t myNextInlineImageInfoIndex; - size_t myNextFloatImageInfoIndex; + std::size_t myNextStyleInfoIndex; + std::size_t myNextCharInfoIndex; + std::size_t myNextBookmarkIndex; + std::size_t myNextInlineImageInfoIndex; + std::size_t myNextFloatImageInfoIndex; }; #endif /* __OLESTREAMPARSER_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.cpp b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.cpp index ee5d10b28..224489a12 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.cpp @@ -26,13 +26,13 @@ OleStreamReader::OleStreamReader() : myNextPieceNumber(0) { } -bool OleStreamReader::readDocument(shared_ptr inputStream) { +bool OleStreamReader::readDocument(shared_ptr inputStream, bool doReadFormattingData) { static const std::string WORD_DOCUMENT = "WordDocument"; shared_ptr storage = new OleStorage; if (!storage->init(inputStream, inputStream->sizeOfOpened())) { - ZLLogger::Instance().println("OleStreamReader", "Broken OLE file"); + ZLLogger::Instance().println("DocPlugin", "Broken OLE file"); return false; } @@ -42,8 +42,8 @@ bool OleStreamReader::readDocument(shared_ptr inputStream) { } OleMainStream oleStream(storage, wordDocumentEntry, inputStream); - if (!oleStream.open()) { - ZLLogger::Instance().println("OleStreamReader", "Cannot open OleMainStream"); + if (!oleStream.open(doReadFormattingData)) { + ZLLogger::Instance().println("DocPlugin", "Cannot open OleMainStream"); return false; } return readStream(oleStream); @@ -57,7 +57,7 @@ bool OleStreamReader::readNextPiece(OleMainStream &stream) { const OleMainStream::Piece &piece = pieces.at(myNextPieceNumber); if (piece.Type == OleMainStream::Piece::PIECE_FOOTNOTE) { - footnoteHandler(); + footnotesStartHandler(); } else if (piece.Type == OleMainStream::Piece::PIECE_OTHER) { return false; } @@ -67,17 +67,17 @@ bool OleStreamReader::readNextPiece(OleMainStream &stream) { return false; } char *textBuffer = new char[piece.Length]; - size_t readBytes = stream.read(textBuffer, piece.Length); - if (readBytes != (size_t)piece.Length) { - ZLLogger::Instance().println("OleStreamReader", "not all bytes have been read from piece"); + std::size_t readBytes = stream.read(textBuffer, piece.Length); + if (readBytes != (std::size_t)piece.Length) { + ZLLogger::Instance().println("DocPlugin", "not all bytes have been read from piece"); } if (!piece.IsANSI) { - for (size_t i = 0; i < readBytes; i += 2) { - ansiSymbolHandler(OleUtil::getU2Bytes(textBuffer, i)); + for (std::size_t i = 0; i < readBytes; i += 2) { + ucs2SymbolHandler(OleUtil::getU2Bytes(textBuffer, i)); } } else { - dataHandler(textBuffer, readBytes); + ansiDataHandler(textBuffer, readBytes); } ++myNextPieceNumber; delete[] textBuffer; diff --git a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.h b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.h index 7959b519a..2d2a0ae19 100644 --- a/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.h +++ b/jni/NativeFormats/fbreader/src/formats/doc/OleStreamReader.h @@ -28,19 +28,19 @@ class OleStreamReader { public: OleStreamReader(); - bool readDocument(shared_ptr stream); + bool readDocument(shared_ptr stream, bool doReadFormattingData); protected: virtual bool readStream(OleMainStream &stream) = 0; bool readNextPiece(OleMainStream &stream); - virtual void dataHandler(const char *buffer, size_t len) = 0; - virtual void ansiSymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) = 0; - virtual void footnoteHandler() = 0; + virtual void ansiDataHandler(const char *buffer, std::size_t len) = 0; + virtual void ucs2SymbolHandler(ZLUnicodeUtil::Ucs2Char symbol) = 0; + virtual void footnotesStartHandler() = 0; private: - size_t myNextPieceNumber; + std::size_t myNextPieceNumber; }; #endif /* __OLESTREAMREADER_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.cpp b/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.cpp index 0d44cac01..0cc07a721 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.cpp @@ -32,7 +32,7 @@ FB2BookReader::FB2BookReader(BookModel &model) : myModelReader(model) { myInsideCoverpage = false; - myParagraphsBeforeBodyNumber = (size_t)-1; + myParagraphsBeforeBodyNumber = (std::size_t)-1; myInsidePoem = false; mySectionDepth = 0; myBodyCounter = 0; @@ -42,7 +42,7 @@ FB2BookReader::FB2BookReader(BookModel &model) : myModelReader(model) { myInsideTitle = false; } -void FB2BookReader::characterDataHandler(const char *text, size_t len) { +void FB2BookReader::characterDataHandler(const char *text, std::size_t len) { if ((len > 0) && (!myCurrentImageId.empty() || myModelReader.paragraphIsOpen())) { std::string str(text, len); if (!myCurrentImageId.empty()) { diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.h index e8523f47d..aac2d3cd3 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2BookReader.h @@ -34,14 +34,14 @@ public: bool processNamespaces() const; void startElementHandler(int tag, const char **attributes); void endElementHandler(int tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); private: int mySectionDepth; int myBodyCounter; bool myReadMainText; bool myInsideCoverpage; - size_t myParagraphsBeforeBodyNumber; + std::size_t myParagraphsBeforeBodyNumber; std::string myCoverImageReference; bool myInsidePoem; BookReader myModelReader; diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp index bb0e623dc..93ccfa570 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.cpp @@ -84,7 +84,7 @@ void FB2CoverReader::endElementHandler(int tag) { } } -void FB2CoverReader::characterDataHandler(const char *text, size_t len) { +void FB2CoverReader::characterDataHandler(const char *text, std::size_t len) { if (len > 0 && myLookForImage) { myImageStart = getCurrentPosition(); myLookForImage = false; diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h index 5e219b82f..6807aa92d 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2CoverReader.h @@ -35,7 +35,7 @@ private: bool processNamespaces() const; void startElementHandler(int tag, const char **attributes); void endElementHandler(int tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); private: const ZLFile myFile; diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.cpp b/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.cpp index 8abbae701..2326878d2 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.cpp @@ -34,7 +34,7 @@ FB2MetaInfoReader::FB2MetaInfoReader(Book &book) : myBook(book) { myBook.removeAllTags(); } -void FB2MetaInfoReader::characterDataHandler(const char *text, size_t len) { +void FB2MetaInfoReader::characterDataHandler(const char *text, std::size_t len) { switch (myReadState) { case READ_TITLE: myBuffer.append(text, len); diff --git a/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.h b/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.h index 9c4237d7d..cc0990962 100644 --- a/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.h +++ b/jni/NativeFormats/fbreader/src/formats/fb2/FB2MetaInfoReader.h @@ -34,7 +34,7 @@ public: void startElementHandler(int tag, const char **attributes); void endElementHandler(int tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); private: Book &myBook; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp index 630bcd11b..c60a84fbd 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.cpp @@ -401,7 +401,7 @@ HtmlBookReader::HtmlBookReader(const std::string &baseDirectoryPath, BookModel & HtmlBookReader::~HtmlBookReader() { } -void HtmlBookReader::addConvertedDataToBuffer(const char *text, size_t len, bool convert) { +void HtmlBookReader::addConvertedDataToBuffer(const char *text, std::size_t len, bool convert) { if (len > 0) { if (myDontBreakParagraph) { while ((len > 0) && isspace(*text)) { @@ -445,7 +445,7 @@ bool HtmlBookReader::tagHandler(const HtmlTag &tag) { return true; } -void HtmlBookReader::preformattedCharacterDataHandler(const char *text, size_t len, bool convert) { +void HtmlBookReader::preformattedCharacterDataHandler(const char *text, std::size_t len, bool convert) { const char *start = text; const char *end = text + len; @@ -517,7 +517,7 @@ void HtmlBookReader::preformattedCharacterDataHandler(const char *text, size_t l } } -bool HtmlBookReader::characterDataHandler(const char *text, size_t len, bool convert) { +bool HtmlBookReader::characterDataHandler(const char *text, std::size_t len, bool convert) { if (!myStyleSheetParser.isNull()) { myStyleSheetParser->parse(text, len); return true; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.h b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.h index fab3a21ec..c8d4e3217 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.h +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlBookReader.h @@ -50,11 +50,11 @@ protected: void startDocumentHandler(); void endDocumentHandler(); bool tagHandler(const HtmlTag &tag); - bool characterDataHandler(const char *text, size_t len, bool convert); + bool characterDataHandler(const char *text, std::size_t len, bool convert); private: - void preformattedCharacterDataHandler(const char *text, size_t len, bool convert); - void addConvertedDataToBuffer(const char *text, size_t len, bool convert); + void preformattedCharacterDataHandler(const char *text, std::size_t len, bool convert); + void addConvertedDataToBuffer(const char *text, std::size_t len, bool convert); protected: BookReader myBookReader; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.cpp index fa113e6f5..6ebcb8bbe 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.cpp @@ -56,7 +56,7 @@ bool HtmlDescriptionReader::tagHandler(const HtmlTag &tag) { } if (it != tag.Attributes.end()) { const std::string prefix = "charset="; - size_t index = it->Value.find(prefix); + std::size_t index = it->Value.find(prefix); if (index != std::string::npos) { std::string charset = it->Value.substr(index + prefix.length()); index = charset.find(';'); @@ -74,7 +74,7 @@ bool HtmlDescriptionReader::tagHandler(const HtmlTag &tag) { return tag.Name != "BODY"; } -bool HtmlDescriptionReader::characterDataHandler(const char *text, size_t len, bool) { +bool HtmlDescriptionReader::characterDataHandler(const char *text, std::size_t len, bool) { if (myReadTitle) { myBuffer.append(text, len); } diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.h b/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.h index 1f66bc0fc..159d4b039 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.h +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlDescriptionReader.h @@ -35,7 +35,7 @@ protected: void endDocumentHandler(); bool tagHandler(const HtmlTag &tag); - bool characterDataHandler(const char *text, size_t len, bool convert); + bool characterDataHandler(const char *text, std::size_t len, bool convert); private: bool myReadTitle; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.cpp index 1bb96c359..23799f799 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.cpp @@ -50,8 +50,8 @@ void HtmlReader::setTag(HtmlTag &tag, const std::string &name) { tag.Name = name.substr(1); } - const size_t len = tag.Name.length(); - for (size_t i = 0; i < len; ++i) { + const std::size_t len = tag.Name.length(); + for (std::size_t i = 0; i < len; ++i) { tag.Name[i] = toupper(tag.Name[i]); } } @@ -124,10 +124,10 @@ void HtmlReader::readDocument(ZLInputStream &stream) { HtmlTag currentTag; char endOfComment[2] = "\0"; - const size_t BUFSIZE = 2048; + const std::size_t BUFSIZE = 2048; char *buffer = new char[BUFSIZE]; - size_t length; - size_t offset = 0; + std::size_t length; + std::size_t offset = 0; do { length = stream.read(buffer, BUFSIZE); char *start = buffer; diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.h b/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.h index b52feeda0..876fad82b 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.h +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlReader.h @@ -43,7 +43,7 @@ public: struct HtmlTag { std::string Name; - size_t Offset; + std::size_t Offset; bool Start; std::vector Attributes; @@ -74,7 +74,7 @@ protected: // returns false iff processing must be stopped virtual bool tagHandler(const HtmlTag &tag) = 0; // returns false iff processing must be stopped - virtual bool characterDataHandler(const char *text, size_t len, bool convert) = 0; + virtual bool characterDataHandler(const char *text, std::size_t len, bool convert) = 0; private: void appendString(std::string &to, std::string &from); diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.cpp b/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.cpp index 051dec73e..08c43aed6 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.cpp @@ -27,27 +27,27 @@ class HtmlTextOnlyReader : public HtmlReader { public: - HtmlTextOnlyReader(char *buffer, size_t maxSize); - size_t size() const; + HtmlTextOnlyReader(char *buffer, std::size_t maxSize); + std::size_t size() const; private: void startDocumentHandler(); void endDocumentHandler(); bool tagHandler(const HtmlTag &tag); - bool characterDataHandler(const char *text, size_t len, bool convert); + bool characterDataHandler(const char *text, std::size_t len, bool convert); private: char *myBuffer; - size_t myMaxSize; - size_t myFilledSize; + std::size_t myMaxSize; + std::size_t myFilledSize; bool myIgnoreText; }; -HtmlTextOnlyReader::HtmlTextOnlyReader(char *buffer, size_t maxSize) : HtmlReader(std::string()), myBuffer(buffer), myMaxSize(maxSize), myFilledSize(0), myIgnoreText(false) { +HtmlTextOnlyReader::HtmlTextOnlyReader(char *buffer, std::size_t maxSize) : HtmlReader(std::string()), myBuffer(buffer), myMaxSize(maxSize), myFilledSize(0), myIgnoreText(false) { } -size_t HtmlTextOnlyReader::size() const { +std::size_t HtmlTextOnlyReader::size() const { return myFilledSize; } @@ -67,16 +67,16 @@ bool HtmlTextOnlyReader::tagHandler(const HtmlTag &tag) { return myFilledSize < myMaxSize; } -bool HtmlTextOnlyReader::characterDataHandler(const char *text, size_t len, bool) { +bool HtmlTextOnlyReader::characterDataHandler(const char *text, std::size_t len, bool) { if (!myIgnoreText) { - len = std::min((size_t)len, myMaxSize - myFilledSize); - memcpy(myBuffer + myFilledSize, text, len); + len = std::min((std::size_t)len, myMaxSize - myFilledSize); + std::memcpy(myBuffer + myFilledSize, text, len); myFilledSize += len; } return myFilledSize < myMaxSize; } -HtmlReaderStream::HtmlReaderStream(shared_ptr base, size_t maxSize) : myBase(base), myBuffer(0), mySize(maxSize) { +HtmlReaderStream::HtmlReaderStream(shared_ptr base, std::size_t maxSize) : myBase(base), myBuffer(0), mySize(maxSize) { } HtmlReaderStream::~HtmlReaderStream() { @@ -96,10 +96,10 @@ bool HtmlReaderStream::open() { return true; } -size_t HtmlReaderStream::read(char *buffer, size_t maxSize) { +std::size_t HtmlReaderStream::read(char *buffer, std::size_t maxSize) { maxSize = std::min(maxSize, mySize - myOffset); if (buffer != 0) { - memcpy(buffer, myBuffer, maxSize); + std::memcpy(buffer, myBuffer, maxSize); } myOffset += maxSize; return maxSize; @@ -116,13 +116,13 @@ void HtmlReaderStream::seek(int offset, bool absoluteOffset) { if (!absoluteOffset) { offset += myOffset; } - myOffset = std::min(mySize, (size_t)std::max(0, offset)); + myOffset = std::min(mySize, (std::size_t)std::max(0, offset)); } -size_t HtmlReaderStream::offset() const { +std::size_t HtmlReaderStream::offset() const { return myOffset; } -size_t HtmlReaderStream::sizeOfOpened() { +std::size_t HtmlReaderStream::sizeOfOpened() { return mySize; } diff --git a/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.h b/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.h index 924b5ef95..c5c15b88f 100644 --- a/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.h +++ b/jni/NativeFormats/fbreader/src/formats/html/HtmlReaderStream.h @@ -26,23 +26,23 @@ class HtmlReaderStream : public ZLInputStream { public: - HtmlReaderStream(shared_ptr base, size_t maxSize); + HtmlReaderStream(shared_ptr base, std::size_t maxSize); ~HtmlReaderStream(); private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myBase; char *myBuffer; - size_t mySize; - size_t myOffset; + std::size_t mySize; + std::size_t myOffset; }; #endif /* __HTMLREADERSTREAM_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp index fe0206782..de1432a2d 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.cpp @@ -34,7 +34,7 @@ static const std::string TAG_TEXT = "text"; void NCXReader::startElementHandler(const char *fullTag, const char **attributes) { std::string tag = fullTag; - const size_t index = tag.rfind(':'); + const std::size_t index = tag.rfind(':'); if (index != std::string::npos) { tag = tag.substr(index + 1); } @@ -76,7 +76,7 @@ void NCXReader::startElementHandler(const char *fullTag, const char **attributes void NCXReader::endElementHandler(const char *fullTag) { std::string tag = fullTag; - const size_t index = tag.rfind(':'); + const std::size_t index = tag.rfind(':'); if (index != std::string::npos) { tag = tag.substr(index + 1); } @@ -110,7 +110,7 @@ void NCXReader::endElementHandler(const char *fullTag) { } } -void NCXReader::characterDataHandler(const char *text, size_t len) { +void NCXReader::characterDataHandler(const char *text, std::size_t len) { if (myReadState == READ_TEXT) { myPointStack.back().Text.append(text, len); } @@ -127,5 +127,5 @@ const std::map &NCXReader::navigationMap() const { NCXReader::NavPoint::NavPoint() { } -NCXReader::NavPoint::NavPoint(int order, size_t level) : Order(order), Level(level) { +NCXReader::NavPoint::NavPoint(int order, std::size_t level) : Order(order), Level(level) { } diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.h b/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.h index 255f2a2d0..c10d2ab55 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/NCXReader.h @@ -32,10 +32,10 @@ class NCXReader : public ZLXMLReader { public: struct NavPoint { NavPoint(); - NavPoint(int order, size_t level); + NavPoint(int order, std::size_t level); int Order; - size_t Level; + std::size_t Level; std::string Text; std::string ContentHRef; }; @@ -47,7 +47,7 @@ public: private: void startElementHandler(const char *tag, const char **attributes); void endElementHandler(const char *tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); const std::vector &externalDTDs() const; private: diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp index e19e3e5df..6542a9854 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBBookReader.cpp @@ -229,7 +229,7 @@ void OEBBookReader::generateTOC(const XHTMLReader &xhtmlReader) { if (ncxReader.readDocument(ZLFile(myFilePrefix + myNCXTOCFileName))) { const std::map navigationMap = ncxReader.navigationMap(); if (!navigationMap.empty()) { - size_t level = 0; + std::size_t level = 0; for (std::map::const_iterator it = navigationMap.begin(); it != navigationMap.end(); ++it) { const NCXReader::NavPoint &point = it->second; int index = myModelReader.model().label(xhtmlReader.normalizedReference(point.ContentHRef)).ParagraphNumber; diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp b/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp index fb4724240..0d2826b0f 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.cpp @@ -40,7 +40,7 @@ static const std::string DC_METADATA = "dc-metadata"; static const std::string META = "meta"; static const std::string AUTHOR_ROLE = "aut"; -void OEBMetaInfoReader::characterDataHandler(const char *text, size_t len) { +void OEBMetaInfoReader::characterDataHandler(const char *text, std::size_t len) { switch (myReadState) { case READ_NONE: case READ_METADATA: diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.h index df3ce4d2a..2337c50d6 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBMetaInfoReader.h @@ -34,7 +34,7 @@ public: void startElementHandler(const char *tag, const char **attributes); void endElementHandler(const char *tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); bool processNamespaces() const; const std::vector &externalDTDs() const; diff --git a/jni/NativeFormats/fbreader/src/formats/oeb/OEBTextStream.h b/jni/NativeFormats/fbreader/src/formats/oeb/OEBTextStream.h index 64c41c5fe..6ddd2c9df 100644 --- a/jni/NativeFormats/fbreader/src/formats/oeb/OEBTextStream.h +++ b/jni/NativeFormats/fbreader/src/formats/oeb/OEBTextStream.h @@ -37,7 +37,7 @@ private: private: std::string myFilePrefix; std::vector myXHTMLFileNames; - size_t myIndex; + std::size_t myIndex; }; #endif /* __OEBTEXTSTREAM_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp index a08ff06f2..08bf2447c 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.cpp @@ -29,9 +29,9 @@ RtfBookReader::RtfBookReader(BookModel &model, const std::string &encoding) : RtfReader(encoding), myBookReader(model) { } -static const size_t maxBufferSize = 1024; +static const std::size_t maxBufferSize = 1024; -void RtfBookReader::addCharData(const char *data, size_t len, bool convert) { +void RtfBookReader::addCharData(const char *data, std::size_t len, bool convert) { if (myCurrentState.ReadText) { if (convert || myConverter.isNull()) { myOutputBuffer.append(data, len); @@ -119,7 +119,7 @@ void RtfBookReader::switchDestination(DestinationType destination, bool on) { } } -void RtfBookReader::insertImage(const std::string &mimeType, const std::string &fileName, size_t startOffset, size_t size) { +void RtfBookReader::insertImage(const std::string &mimeType, const std::string &fileName, std::size_t startOffset, std::size_t size) { std::string id; ZLStringUtil::appendNumber(id, myImageIndex++); myBookReader.addImageReference(id, 0, false); diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.h index a729c56c4..03dbc67d7 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfBookReader.h @@ -44,8 +44,8 @@ public: void setEncoding(int code); void setAlignment(); void switchDestination(DestinationType destination, bool on); - void addCharData(const char *data, size_t len, bool convert); - void insertImage(const std::string &mimeType, const std::string &fileName, size_t startOffset, size_t size); + void addCharData(const char *data, std::size_t len, bool convert); + void insertImage(const std::string &mimeType, const std::string &fileName, std::size_t startOffset, std::size_t size); void setFontProperty(FontProperty property); void newParagraph(); diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp index 846712766..d0015dc90 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.cpp @@ -43,7 +43,7 @@ bool RtfDescriptionReader::readDocument(const ZLFile &file) { return RtfReader::readDocument(file); } -void RtfDescriptionReader::addCharData(const char *data, size_t len, bool convert) { +void RtfDescriptionReader::addCharData(const char *data, std::size_t len, bool convert) { if (myDoRead && len > 0) { if (convert) { myConverter->convert(myBuffer, data, data + len); @@ -82,7 +82,7 @@ void RtfDescriptionReader::switchDestination(DestinationType destination, bool o } } -void RtfDescriptionReader::insertImage(const std::string&, const std::string&, size_t, size_t) { +void RtfDescriptionReader::insertImage(const std::string&, const std::string&, std::size_t, std::size_t) { } void RtfDescriptionReader::setFontProperty(FontProperty) { diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.h index 0442bd743..80f2fef4d 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfDescriptionReader.h @@ -37,8 +37,8 @@ public: void setEncoding(int code); void setAlignment(); void switchDestination(DestinationType destination, bool on); - void addCharData(const char *data, size_t len, bool convert); - void insertImage(const std::string &mimeType, const std::string &fileName, size_t startOffset, size_t size); + void addCharData(const char *data, std::size_t len, bool convert); + void insertImage(const std::string &mimeType, const std::string &fileName, std::size_t startOffset, std::size_t size); void setFontProperty(FontProperty property); void newParagraph(); diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp index 0170d1e7b..2bd4bb3e7 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.cpp @@ -424,7 +424,7 @@ void RtfReader::processKeyword(const std::string &keyword, int *parameter) { it->second->run(*this, parameter); } -void RtfReader::processCharData(const char *data, size_t len, bool convert) { +void RtfReader::processCharData(const char *data, std::size_t len, bool convert) { if (myState.Destination != RtfReader::DESTINATION_SKIP) { addCharData(data, len, convert); } diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h index 428f69e2e..ab73f7fd6 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReader.h @@ -68,8 +68,8 @@ protected: FONT_UNDERLINED }; - virtual void addCharData(const char *data, size_t len, bool convert) = 0; - virtual void insertImage(const std::string &mimeType, const std::string &fileName, size_t startOffset, size_t size) = 0; + virtual void addCharData(const char *data, std::size_t len, bool convert) = 0; + virtual void insertImage(const std::string &mimeType, const std::string &fileName, std::size_t startOffset, std::size_t size) = 0; virtual void setEncoding(int code) = 0; virtual void switchDestination(DestinationType destination, bool on) = 0; virtual void setAlignment() = 0; @@ -81,7 +81,7 @@ protected: private: bool parseDocument(); void processKeyword(const std::string &keyword, int *parameter = 0); - void processCharData(const char *data, size_t len, bool convert = true); + void processCharData(const char *data, std::size_t len, bool convert = true); protected: struct RtfReaderState { diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.cpp b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.cpp index 2eb8dcdff..2eae84cf2 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.cpp @@ -27,13 +27,13 @@ class RtfTextOnlyReader : public RtfReader { public: - RtfTextOnlyReader(char *buffer, size_t maxSize); + RtfTextOnlyReader(char *buffer, std::size_t maxSize); ~RtfTextOnlyReader(); - size_t readSize() const; + std::size_t readSize() const; protected: - void addCharData(const char *data, size_t len, bool convert); - void insertImage(const std::string &mimeType, const std::string &fileName, size_t startOffset, size_t size); + void addCharData(const char *data, std::size_t len, bool convert); + void insertImage(const std::string &mimeType, const std::string &fileName, std::size_t startOffset, std::size_t size); void setEncoding(int code); void switchDestination(DestinationType destination, bool on); void setAlignment(); @@ -51,25 +51,25 @@ private: private: char* myBuffer; - const size_t myMaxSize; - size_t myFilledSize; + const std::size_t myMaxSize; + std::size_t myFilledSize; }; -RtfTextOnlyReader::RtfTextOnlyReader(char *buffer, size_t maxSize) : RtfReader(std::string()), myBuffer(buffer), myMaxSize(maxSize), myFilledSize(0) { +RtfTextOnlyReader::RtfTextOnlyReader(char *buffer, std::size_t maxSize) : RtfReader(std::string()), myBuffer(buffer), myMaxSize(maxSize), myFilledSize(0) { myCurrentState.ReadText = true; } RtfTextOnlyReader::~RtfTextOnlyReader() { } -void RtfTextOnlyReader::addCharData(const char *data, size_t len, bool) { +void RtfTextOnlyReader::addCharData(const char *data, std::size_t len, bool) { if (myBuffer == 0) { return; } if (myCurrentState.ReadText) { if (myFilledSize < myMaxSize) { - len = std::min((size_t)len, myMaxSize - myFilledSize); - memcpy(myBuffer + myFilledSize, data, len); + len = std::min((std::size_t)len, myMaxSize - myFilledSize); + std::memcpy(myBuffer + myFilledSize, data, len); myFilledSize += len; } if (myFilledSize < myMaxSize) { @@ -80,11 +80,11 @@ void RtfTextOnlyReader::addCharData(const char *data, size_t len, bool) { } } -size_t RtfTextOnlyReader::readSize() const { +std::size_t RtfTextOnlyReader::readSize() const { return myFilledSize; } -void RtfTextOnlyReader::insertImage(const std::string&, const std::string&, size_t, size_t) { +void RtfTextOnlyReader::insertImage(const std::string&, const std::string&, std::size_t, std::size_t) { } void RtfTextOnlyReader::setEncoding(int) { @@ -124,7 +124,7 @@ void RtfTextOnlyReader::newParagraph() { void RtfTextOnlyReader::interrupt() { } -RtfReaderStream::RtfReaderStream(const ZLFile& file, size_t maxSize) : myFile(file), myBuffer(0), mySize(maxSize) { +RtfReaderStream::RtfReaderStream(const ZLFile& file, std::size_t maxSize) : myFile(file), myBuffer(0), mySize(maxSize) { } RtfReaderStream::~RtfReaderStream() { @@ -142,10 +142,10 @@ bool RtfReaderStream::open() { return true; } -size_t RtfReaderStream::read(char *buffer, size_t maxSize) { +std::size_t RtfReaderStream::read(char *buffer, std::size_t maxSize) { maxSize = std::min(maxSize, mySize - myOffset); if ((buffer != 0) && (myBuffer !=0)) { - memcpy(buffer, myBuffer + myOffset, maxSize); + std::memcpy(buffer, myBuffer + myOffset, maxSize); } myOffset += maxSize; return maxSize; @@ -162,13 +162,13 @@ void RtfReaderStream::seek(int offset, bool absoluteOffset) { if (!absoluteOffset) { offset += myOffset; } - myOffset = std::min(mySize, (size_t)std::max(0, offset)); + myOffset = std::min(mySize, (std::size_t)std::max(0, offset)); } -size_t RtfReaderStream::offset() const { +std::size_t RtfReaderStream::offset() const { return myOffset; } -size_t RtfReaderStream::sizeOfOpened() { +std::size_t RtfReaderStream::sizeOfOpened() { return mySize; } diff --git a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.h b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.h index da4163a26..71555b41c 100644 --- a/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.h +++ b/jni/NativeFormats/fbreader/src/formats/rtf/RtfReaderStream.h @@ -28,23 +28,23 @@ class RtfReaderStream : public ZLInputStream { public: - RtfReaderStream(const ZLFile& file, size_t maxSize); + RtfReaderStream(const ZLFile& file, std::size_t maxSize); ~RtfReaderStream(); private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: const ZLFile myFile; char *myBuffer; - size_t mySize; - size_t myOffset; + std::size_t mySize; + std::size_t myOffset; }; #endif /* __RTFREADERSTREAM_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp b/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp index 92c08e7b9..1b18ef85a 100644 --- a/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/txt/TxtReader.cpp @@ -94,10 +94,10 @@ TxtReaderCoreUtf16::TxtReaderCoreUtf16(TxtReader &reader) : TxtReaderCore(reader } void TxtReaderCore::readDocument(ZLInputStream &stream) { - const size_t BUFSIZE = 2048; + const std::size_t BUFSIZE = 2048; char *buffer = new char[BUFSIZE]; std::string str; - size_t length; + std::size_t length; do { length = stream.read(buffer, BUFSIZE); char *start = buffer; @@ -136,10 +136,10 @@ void TxtReaderCore::readDocument(ZLInputStream &stream) { } void TxtReaderCoreUtf16::readDocument(ZLInputStream &stream) { - const size_t BUFSIZE = 2048; + const std::size_t BUFSIZE = 2048; char *buffer = new char[BUFSIZE]; std::string str; - size_t length; + std::size_t length; do { length = stream.read(buffer, BUFSIZE); char *start = buffer; diff --git a/jni/NativeFormats/fbreader/src/formats/util/MergedStream.cpp b/jni/NativeFormats/fbreader/src/formats/util/MergedStream.cpp index 91df63178..1a26a3358 100644 --- a/jni/NativeFormats/fbreader/src/formats/util/MergedStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/util/MergedStream.cpp @@ -27,10 +27,10 @@ bool MergedStream::open() { return !myCurrentStream.isNull() && myCurrentStream->open(); } -size_t MergedStream::read(char *buffer, size_t maxSize) { - size_t bytesToRead = maxSize; +std::size_t MergedStream::read(char *buffer, std::size_t maxSize) { + std::size_t bytesToRead = maxSize; while ((bytesToRead > 0) && !myCurrentStream.isNull()) { - size_t len = myCurrentStream->read(buffer, bytesToRead); + std::size_t len = myCurrentStream->read(buffer, bytesToRead); bytesToRead -= len; if (buffer != 0) { buffer += len; @@ -62,11 +62,11 @@ void MergedStream::seek(int offset, bool absoluteOffset) { read(0, offset); } -size_t MergedStream::offset() const { +std::size_t MergedStream::offset() const { return myOffset; } -size_t MergedStream::sizeOfOpened() { +std::size_t MergedStream::sizeOfOpened() { // coudn't be implemented return 0; } diff --git a/jni/NativeFormats/fbreader/src/formats/util/MergedStream.h b/jni/NativeFormats/fbreader/src/formats/util/MergedStream.h index 274dfbfaf..3f982ee1d 100644 --- a/jni/NativeFormats/fbreader/src/formats/util/MergedStream.h +++ b/jni/NativeFormats/fbreader/src/formats/util/MergedStream.h @@ -31,15 +31,15 @@ protected: private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myCurrentStream; - size_t myOffset; + std::size_t myOffset; }; #endif /* __MERGEDSTREAM_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.cpp b/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.cpp index 9cdf3ebcf..19343a1ef 100644 --- a/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.cpp +++ b/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.cpp @@ -33,7 +33,7 @@ public: private: void startElementHandler(const char *tag, const char **attributes); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); private: const std::string myStartTag; @@ -50,7 +50,7 @@ void XMLTextReader::startElementHandler(const char *tag, const char**) { } } -void XMLTextReader::characterDataHandler(const char *text, size_t len) { +void XMLTextReader::characterDataHandler(const char *text, std::size_t len) { if (myStarted) { myBuffer.append(text, len); } @@ -73,9 +73,9 @@ bool XMLTextStream::open() { return true; } -size_t XMLTextStream::read(char *buffer, size_t maxSize) { +std::size_t XMLTextStream::read(char *buffer, std::size_t maxSize) { while (myDataBuffer.size() < maxSize) { - size_t len = myBase->read((char*)myStreamBuffer.data(), 2048); + std::size_t len = myBase->read((char*)myStreamBuffer.data(), 2048); /*if ((len == 0) || !myReader->readFromBuffer(myStreamBuffer.data(), len)) { break; }*/ @@ -87,9 +87,9 @@ size_t XMLTextStream::read(char *buffer, size_t maxSize) { break; } } - size_t realSize = std::min(myDataBuffer.size(), maxSize); + std::size_t realSize = std::min(myDataBuffer.size(), maxSize); if (buffer != 0) { - memcpy(buffer, myDataBuffer.data(), realSize); + std::memcpy(buffer, myDataBuffer.data(), realSize); } myDataBuffer.erase(0, realSize); myOffset += realSize; @@ -114,11 +114,11 @@ void XMLTextStream::seek(int offset, bool absoluteOffset) { read(0, offset); } -size_t XMLTextStream::offset() const { +std::size_t XMLTextStream::offset() const { return myOffset; } -size_t XMLTextStream::sizeOfOpened() { +std::size_t XMLTextStream::sizeOfOpened() { // couldn't be implemented return 0; } diff --git a/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.h b/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.h index 017c2af5d..f3151c6db 100644 --- a/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.h +++ b/jni/NativeFormats/fbreader/src/formats/util/XMLTextStream.h @@ -34,11 +34,11 @@ public: private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myBase; @@ -46,7 +46,7 @@ private: shared_ptr myStream; std::string myStreamBuffer; std::string myDataBuffer; - size_t myOffset; + std::size_t myOffset; }; #endif /* __XMLTEXTSTREAM_H__ */ diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp index a3f76bffb..dae586ce9 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.cpp @@ -630,7 +630,7 @@ void XHTMLReader::endParagraph() { myModelReader.endParagraph(); } -void XHTMLReader::characterDataHandler(const char *text, size_t len) { +void XHTMLReader::characterDataHandler(const char *text, std::size_t len) { switch (myReadState) { case READ_NOTHING: break; @@ -648,7 +648,7 @@ void XHTMLReader::characterDataHandler(const char *text, size_t len) { beginParagraph(); myModelReader.addControl(PREFORMATTED, true); } - size_t spaceCounter = 0; + std::size_t spaceCounter = 0; while (spaceCounter < len && isspace((unsigned char)*(text + spaceCounter))) { ++spaceCounter; } @@ -684,7 +684,7 @@ bool XHTMLReader::processNamespaces() const { } const std::string XHTMLReader::normalizedReference(const std::string &reference) const { - const size_t index = reference.find('#'); + const std::size_t index = reference.find('#'); if (index == std::string::npos) { return fileAlias(reference); } else { diff --git a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h index 0a513f358..08d4c02ec 100644 --- a/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h +++ b/jni/NativeFormats/fbreader/src/formats/xhtml/XHTMLReader.h @@ -67,7 +67,7 @@ public: private: void startElementHandler(const char *tag, const char **attributes); void endElementHandler(const char *tag); - void characterDataHandler(const char *text, size_t len); + void characterDataHandler(const char *text, std::size_t len); const std::vector &externalDTDs() const; diff --git a/jni/NativeFormats/fbreader/src/library/Author.cpp b/jni/NativeFormats/fbreader/src/library/Author.cpp index af5b54a23..2672d0101 100644 --- a/jni/NativeFormats/fbreader/src/library/Author.cpp +++ b/jni/NativeFormats/fbreader/src/library/Author.cpp @@ -34,7 +34,7 @@ shared_ptr Author::getAuthor(const std::string &name, const std::string ZLStringUtil::stripWhiteSpaces(strippedKey); if (strippedKey.empty()) { - const size_t index = strippedName.find(','); + const std::size_t index = strippedName.find(','); if (index != std::string::npos) { strippedKey = strippedName.substr(0, index); ZLStringUtil::stripWhiteSpaces(strippedKey); @@ -42,12 +42,12 @@ shared_ptr Author::getAuthor(const std::string &name, const std::string } if (strippedKey.empty()) { - size_t index = strippedName.rfind(' '); + std::size_t index = strippedName.rfind(' '); if (index == std::string::npos) { strippedKey = strippedName; } else { strippedKey = strippedName.substr(index + 1); - const size_t size = strippedName.size(); + const std::size_t size = strippedName.size(); while (index < size && strippedName[index] == ' ') { --index; } diff --git a/jni/NativeFormats/fbreader/src/library/Book.cpp b/jni/NativeFormats/fbreader/src/library/Book.cpp index 38ccb6bfc..8e9f8871c 100644 --- a/jni/NativeFormats/fbreader/src/library/Book.cpp +++ b/jni/NativeFormats/fbreader/src/library/Book.cpp @@ -217,9 +217,9 @@ bool Book::cloneTag(shared_ptr from, shared_ptr to, bool includeSubTag const std::string &tagList = info.TagsOption.value(); if (!tagList.empty()) { - size_t index = 0; + std::size_t index = 0; do { - size_t newIndex = tagList.find(',', index); + std::size_t newIndex = tagList.find(',', index); book->addTag(Tag::getTagByFullName(tagList.substr(index, newIndex - index))); index = newIndex + 1; } while (index != 0); @@ -227,9 +227,9 @@ bool Book::cloneTag(shared_ptr from, shared_ptr to, bool includeSubTag const std::string &authorList = info.AuthorDisplayNameOption.value(); if (!authorList.empty()) { - size_t index = 0; + std::size_t index = 0; do { - size_t newIndex = authorList.find(',', index); + std::size_t newIndex = authorList.find(',', index); book->addAuthor(authorList.substr(index, newIndex - index)); index = newIndex + 1; } while (index != 0); diff --git a/jni/NativeFormats/fbreader/src/library/Comparators.cpp b/jni/NativeFormats/fbreader/src/library/Comparators.cpp index f901aecd7..6c689dd19 100644 --- a/jni/NativeFormats/fbreader/src/library/Comparators.cpp +++ b/jni/NativeFormats/fbreader/src/library/Comparators.cpp @@ -79,8 +79,8 @@ bool TagComparator::operator() ( return false; } - size_t level0 = tag0->level(); - size_t level1 = tag1->level(); + std::size_t level0 = tag0->level(); + std::size_t level1 = tag1->level(); if (level0 > level1) { for (; level0 > level1; --level0) { tag0 = tag0->parent(); diff --git a/jni/NativeFormats/fbreader/src/library/Tag.cpp b/jni/NativeFormats/fbreader/src/library/Tag.cpp index b615740be..4f885f4bd 100644 --- a/jni/NativeFormats/fbreader/src/library/Tag.cpp +++ b/jni/NativeFormats/fbreader/src/library/Tag.cpp @@ -53,7 +53,7 @@ shared_ptr Tag::getTag(const std::string &name, shared_ptr parent, int shared_ptr Tag::getTagByFullName(const std::string &fullName) { std::string tag = fullName; ZLStringUtil::stripWhiteSpaces(tag); - size_t index = tag.rfind(DELIMITER); + std::size_t index = tag.rfind(DELIMITER); if (index == std::string::npos) { return getTag(tag); } else { diff --git a/jni/NativeFormats/fbreader/src/library/Tag.h b/jni/NativeFormats/fbreader/src/library/Tag.h index bea7bed32..731f40772 100644 --- a/jni/NativeFormats/fbreader/src/library/Tag.h +++ b/jni/NativeFormats/fbreader/src/library/Tag.h @@ -69,7 +69,7 @@ public: bool isAncestorOf(shared_ptr tag) const; int tagId() const; - size_t level() const; + std::size_t level() const; private: const std::string myName; @@ -77,7 +77,7 @@ private: shared_ptr myParent; TagList myChildren; - const size_t myLevel; + const std::size_t myLevel; int myTagId; @@ -102,6 +102,6 @@ inline const std::string &Tag::name() const { return myName; } inline shared_ptr Tag::parent() const { return myParent; } inline int Tag::tagId() const { return myTagId; } -inline size_t Tag::level() const { return myLevel; } +inline std::size_t Tag::level() const { return myLevel; } #endif /* __TAG_H__ */ diff --git a/jni/NativeFormats/util/AndroidUtil.cpp b/jni/NativeFormats/util/AndroidUtil.cpp index 529bb00e3..184a403ed 100644 --- a/jni/NativeFormats/util/AndroidUtil.cpp +++ b/jni/NativeFormats/util/AndroidUtil.cpp @@ -215,7 +215,7 @@ jobject AndroidUtil::createJavaImage(JNIEnv *env, const ZLFileImage &image) { std::vector offsets, sizes; const ZLFileImage::Blocks &blocks = image.blocks(); - for (size_t i = 0; i < blocks.size(); ++i) { + for (std::size_t i = 0; i < blocks.size(); ++i) { offsets.push_back((jint)blocks.at(i).offset); sizes.push_back((jint)blocks.at(i).size); } @@ -274,14 +274,14 @@ std::string AndroidUtil::convertNonUtfString(const std::string &str) { } jintArray AndroidUtil::createJavaIntArray(JNIEnv *env, const std::vector &data) { - size_t size = data.size(); + std::size_t size = data.size(); jintArray array = env->NewIntArray(size); env->SetIntArrayRegion(array, 0, size, &data.front()); return array; } jbyteArray AndroidUtil::createJavaByteArray(JNIEnv *env, const std::vector &data) { - size_t size = data.size(); + std::size_t size = data.size(); jbyteArray array = env->NewByteArray(size); env->SetByteArrayRegion(array, 0, size, &data.front()); return array; diff --git a/jni/NativeFormats/zlibrary/core/src/encoding/Utf8EncodingConverter.cpp b/jni/NativeFormats/zlibrary/core/src/encoding/Utf8EncodingConverter.cpp index 043012403..5fe3924cd 100644 --- a/jni/NativeFormats/zlibrary/core/src/encoding/Utf8EncodingConverter.cpp +++ b/jni/NativeFormats/zlibrary/core/src/encoding/Utf8EncodingConverter.cpp @@ -61,11 +61,11 @@ std::string Utf8EncodingConverter::name() const { void Utf8EncodingConverter::convert(std::string &dst, const char *srcStart, const char *srcEnd) { if (myBuffer.size() > 0) { - const size_t len = ZLUnicodeUtil::length(myBuffer, 1); + const std::size_t len = ZLUnicodeUtil::length(myBuffer, 1); if (len < myBuffer.size()) { return; } - const size_t diff = std::min(len - myBuffer.size(), (size_t)(srcEnd - srcStart)); + const std::size_t diff = std::min(len - myBuffer.size(), (std::size_t)(srcEnd - srcStart)); myBuffer.append(srcStart, diff); srcStart += diff; if (myBuffer.size() == len) { diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp index d5bf86adf..65fdd4207 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.cpp @@ -38,7 +38,7 @@ ZLFile::ZLFile() : myMimeTypeIsUpToDate(true), myInfoIsFilled(true) { ZLFile::ZLFile(const std::string &path, const std::string &mimeType) : myPath(path), myMimeType(mimeType), myMimeTypeIsUpToDate(!mimeType.empty()), myInfoIsFilled(false) { ZLFSManager::Instance().normalize(myPath); { - size_t index = ZLFSManager::Instance().findLastFileNameDelimiter(myPath); + std::size_t index = ZLFSManager::Instance().findLastFileNameDelimiter(myPath); if (index < myPath.length() - 1) { myNameWithExtension = myPath.substr(index + 1); } else { @@ -224,7 +224,7 @@ bool ZLFile::exists() const { return myInfo.Exists; } -size_t ZLFile::size() const { +std::size_t ZLFile::size() const { if (!myInfoIsFilled) { fillInfo(); } @@ -252,9 +252,9 @@ bool ZLFile::canRemove() const { std::string ZLFile::replaceIllegalCharacters(const std::string &fileName, char replaceWith) { static const char charsToReplace[] = ":;<|>+\\/\"*?"; - const size_t len = fileName.length(); + const std::size_t len = fileName.length(); char *data = new char[len]; - memcpy(data, fileName.data(), len); + std::memcpy(data, fileName.data(), len); char *end = data + len; for (char *ptr = data; ptr != end; ++ptr) { if (strchr(charsToReplace, *ptr) != 0) { diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h index 8271119d0..698c04d8e 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFile.h @@ -57,7 +57,7 @@ public: ~ZLFile(); bool exists() const; - size_t size() const; + std::size_t size() const; void forceArchiveType(ArchiveType type) const; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h index 5ba9e0235..498c9269a 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLFileInfo.h @@ -23,7 +23,7 @@ struct ZLFileInfo { bool Exists; bool IsDirectory; - size_t Size; + std::size_t Size; ZLFileInfo(); }; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h index 4de7dc0a5..eb4eb51bb 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStream.h @@ -32,12 +32,12 @@ protected: public: virtual ~ZLInputStream(); virtual bool open() = 0; - virtual size_t read(char *buffer, size_t maxSize) = 0; + virtual std::size_t read(char *buffer, std::size_t maxSize) = 0; virtual void close() = 0; virtual void seek(int offset, bool absoluteOffset) = 0; - virtual size_t offset() const = 0; - virtual size_t sizeOfOpened() = 0; + virtual std::size_t offset() const = 0; + virtual std::size_t sizeOfOpened() = 0; private: // disable copying @@ -52,16 +52,16 @@ public: private: bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myBaseStream; - size_t myBaseOffset; + std::size_t myBaseOffset; }; inline ZLInputStream::ZLInputStream() {} diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp index 481594222..9b2ba2d08 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLInputStreamDecorator.cpp @@ -28,9 +28,9 @@ bool ZLInputStreamDecorator::open() { return result; } -size_t ZLInputStreamDecorator::read(char *buffer, size_t maxSize) { +std::size_t ZLInputStreamDecorator::read(char *buffer, std::size_t maxSize) { myBaseStream->seek(myBaseOffset, true); - size_t result = myBaseStream->read(buffer, maxSize); + std::size_t result = myBaseStream->read(buffer, maxSize); myBaseOffset = myBaseStream->offset(); return result; } @@ -48,10 +48,10 @@ void ZLInputStreamDecorator::seek(int offset, bool absoluteOffset) { myBaseOffset = myBaseStream->offset(); } -size_t ZLInputStreamDecorator::offset() const { +std::size_t ZLInputStreamDecorator::offset() const { return myBaseOffset; } -size_t ZLInputStreamDecorator::sizeOfOpened() { +std::size_t ZLInputStreamDecorator::sizeOfOpened() { return myBaseStream->sizeOfOpened(); } diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLOutputStream.h b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLOutputStream.h index 14a226885..63da97f0e 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/ZLOutputStream.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/ZLOutputStream.h @@ -30,7 +30,7 @@ protected: public: virtual ~ZLOutputStream(); virtual bool open() = 0; - virtual void write(const char *data, size_t len) = 0; + virtual void write(const char *data, std::size_t len) = 0; virtual void write(const std::string &str) = 0; virtual void close() = 0; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp index f3ca254b6..d2058eb5d 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLGzipInputStream.cpp @@ -85,8 +85,8 @@ bool ZLGzipInputStream::open() { return true; } -size_t ZLGzipInputStream::read(char *buffer, size_t maxSize) { - size_t realSize = myDecompressor->decompress(*myBaseStream, buffer, maxSize); +std::size_t ZLGzipInputStream::read(char *buffer, std::size_t maxSize) { + std::size_t realSize = myDecompressor->decompress(*myBaseStream, buffer, maxSize); myOffset += realSize; return realSize; } @@ -111,11 +111,11 @@ void ZLGzipInputStream::seek(int offset, bool absoluteOffset) { } } -size_t ZLGzipInputStream::offset() const { +std::size_t ZLGzipInputStream::offset() const { return myOffset; } -size_t ZLGzipInputStream::sizeOfOpened() { +std::size_t ZLGzipInputStream::sizeOfOpened() { // TODO: implement return 0; } diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp index aa86650df..75bc358b0 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.cpp @@ -24,10 +24,10 @@ #include "../ZLInputStream.h" #include "ZLZDecompressor.h" -const size_t IN_BUFFER_SIZE = 2048; -const size_t OUT_BUFFER_SIZE = 32768; +const std::size_t IN_BUFFER_SIZE = 2048; +const std::size_t OUT_BUFFER_SIZE = 32768; -ZLZDecompressor::ZLZDecompressor(size_t size) : myAvailableSize(size) { +ZLZDecompressor::ZLZDecompressor(std::size_t size) : myAvailableSize(size) { myZStream = new z_stream; memset(myZStream, 0, sizeof(z_stream)); inflateInit2(myZStream, -MAX_WBITS); @@ -44,9 +44,9 @@ ZLZDecompressor::~ZLZDecompressor() { delete myZStream; } -size_t ZLZDecompressor::decompress(ZLInputStream &stream, char *buffer, size_t maxSize) { +std::size_t ZLZDecompressor::decompress(ZLInputStream &stream, char *buffer, std::size_t maxSize) { while ((myBuffer.length() < maxSize) && (myAvailableSize > 0)) { - size_t size = std::min(myAvailableSize, (size_t)IN_BUFFER_SIZE); + std::size_t size = std::min(myAvailableSize, (std::size_t)IN_BUFFER_SIZE); myZStream->next_in = (Bytef*)myInBuffer; myZStream->avail_in = stream.read(myInBuffer, size); @@ -76,9 +76,9 @@ size_t ZLZDecompressor::decompress(ZLInputStream &stream, char *buffer, size_t m } } - size_t realSize = std::min(maxSize, myBuffer.length()); + std::size_t realSize = std::min(maxSize, myBuffer.length()); if (buffer != 0) { - memcpy(buffer, myBuffer.data(), realSize); + std::memcpy(buffer, myBuffer.data(), realSize); } myBuffer.erase(0, realSize); return realSize; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.h b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.h index 74867fed7..3264bc356 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZDecompressor.h @@ -29,14 +29,14 @@ class ZLInputStream; class ZLZDecompressor { public: - ZLZDecompressor(size_t size); + ZLZDecompressor(std::size_t size); ~ZLZDecompressor(); - size_t decompress(ZLInputStream &stream, char *buffer, size_t maxSize); + std::size_t decompress(ZLInputStream &stream, char *buffer, std::size_t maxSize); private: z_stream *myZStream; - size_t myAvailableSize; + std::size_t myAvailableSize; char *myInBuffer; char *myOutBuffer; std::string myBuffer; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZip.h b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZip.h index fe72cf6f2..c51e1db3d 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZip.h +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZip.h @@ -36,9 +36,9 @@ public: static shared_ptr cache(const std::string &containerName, ZLInputStream &containerStream); private: - static const size_t ourStorageSize; + static const std::size_t ourStorageSize; static shared_ptr *ourStoredCaches; - static size_t ourIndex; + static std::size_t ourIndex; public: struct Info { @@ -70,12 +70,12 @@ private: public: ~ZLZipInputStream(); bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myBaseStream; @@ -83,9 +83,9 @@ private: std::string myEntryName; bool myIsDeflated; - size_t myUncompressedSize; - size_t myAvailableSize; - size_t myOffset; + std::size_t myUncompressedSize; + std::size_t myAvailableSize; + std::size_t myOffset; shared_ptr myDecompressor; @@ -100,18 +100,18 @@ private: public: ~ZLGzipInputStream(); bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: shared_ptr myBaseStream; - size_t myFileSize; + std::size_t myFileSize; - size_t myOffset; + std::size_t myOffset; shared_ptr myDecompressor; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp index dfd6a44d4..a9ecbbe34 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipEntryCache.cpp @@ -23,15 +23,15 @@ #include "ZLZip.h" #include "ZLZipHeader.h" -const size_t ZLZipEntryCache::ourStorageSize = 5; +const std::size_t ZLZipEntryCache::ourStorageSize = 5; shared_ptr *ZLZipEntryCache::ourStoredCaches = new shared_ptr[ourStorageSize]; -size_t ZLZipEntryCache::ourIndex = 0; +std::size_t ZLZipEntryCache::ourIndex = 0; shared_ptr ZLZipEntryCache::cache(const std::string &containerName, ZLInputStream &containerStream) { //ZLLogger::Instance().registerClass("ZipEntryCache"); //ZLLogger::Instance().println("ZipEntryCache", "requesting cache for " + containerName); - for (size_t i = 0; i < ourStorageSize; ++i) { + for (std::size_t i = 0; i < ourStorageSize; ++i) { shared_ptr cache = ourStoredCaches[i]; if (!cache.isNull() && cache->myContainerName == containerName) { return cache; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp index b48baa2bb..c093050b8 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipHeader.cpp @@ -29,7 +29,7 @@ const int ZLZipHeader::SignatureEndOfCentralDirectory = 0x06054B50; const int ZLZipHeader::SignatureData = 0x08074B50; bool ZLZipHeader::readFrom(ZLInputStream &stream) { - size_t startOffset = stream.offset(); + std::size_t startOffset = stream.offset(); Signature = readLong(stream); switch (Signature) { default: @@ -95,8 +95,8 @@ void ZLZipHeader::skipEntry(ZLInputStream &stream, ZLZipHeader &header) { case SignatureLocalFile: if ((header.Flags & 0x08) == 0x08 && header.CompressionMethod != 0) { stream.seek(header.ExtraLength, false); - ZLZDecompressor decompressor((size_t)-1); - size_t size; + ZLZDecompressor decompressor((std::size_t)-1); + std::size_t size; do { size = decompressor.decompress(stream, 0, 2048); header.UncompressedSize += size; diff --git a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp index b174c5231..5fd64d8fd 100644 --- a/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp +++ b/jni/NativeFormats/zlibrary/core/src/filesystem/zip/ZLZipInputStream.cpp @@ -57,7 +57,7 @@ bool ZLZipInputStream::open() { myUncompressedSize = info.UncompressedSize; myAvailableSize = info.CompressedSize; if (myAvailableSize == 0) { - myAvailableSize = (size_t)-1; + myAvailableSize = (std::size_t)-1; } if (myIsDeflated) { @@ -68,8 +68,8 @@ bool ZLZipInputStream::open() { return true; } -size_t ZLZipInputStream::read(char *buffer, size_t maxSize) { - size_t realSize = 0; +std::size_t ZLZipInputStream::read(char *buffer, std::size_t maxSize) { + std::size_t realSize = 0; if (myIsDeflated) { realSize = myDecompressor->decompress(*myBaseStream, buffer, maxSize); myOffset += realSize; @@ -103,10 +103,10 @@ void ZLZipInputStream::seek(int offset, bool absoluteOffset) { } } -size_t ZLZipInputStream::offset() const { +std::size_t ZLZipInputStream::offset() const { return myOffset; } -size_t ZLZipInputStream::sizeOfOpened() { +std::size_t ZLZipInputStream::sizeOfOpened() { return myUncompressedSize; } diff --git a/jni/NativeFormats/zlibrary/core/src/image/ZLFileImage.h b/jni/NativeFormats/zlibrary/core/src/image/ZLFileImage.h index 25e55effa..08cccd1a3 100644 --- a/jni/NativeFormats/zlibrary/core/src/image/ZLFileImage.h +++ b/jni/NativeFormats/zlibrary/core/src/image/ZLFileImage.h @@ -38,7 +38,7 @@ public: typedef std::vector Blocks; public: - ZLFileImage(const ZLFile &file, const std::string &encoding, size_t offset, size_t size = 0); + ZLFileImage(const ZLFile &file, const std::string &encoding, std::size_t offset, std::size_t size = 0); ZLFileImage(const ZLFile &file, const std::string &encoding, const Blocks &blocks); //Kind kind() const; @@ -57,7 +57,7 @@ private: inline ZLFileImage::Block::Block(unsigned int off, unsigned int s) : offset(off), size(s) {} -inline ZLFileImage::ZLFileImage(const ZLFile &file, const std::string &encoding, size_t offset, size_t size) : ZLSingleImage(file.mimeType()), myFile(file), myEncoding(encoding) { +inline ZLFileImage::ZLFileImage(const ZLFile &file, const std::string &encoding, std::size_t offset, std::size_t size) : ZLSingleImage(file.mimeType()), myFile(file), myEncoding(encoding) { myBlocks.push_back(Block(offset, size)); } diff --git a/jni/NativeFormats/zlibrary/core/src/image/ZLStreamImage.h b/jni/NativeFormats/zlibrary/core/src/image/ZLStreamImage.h index 5c2497db2..69781c01d 100644 --- a/jni/NativeFormats/zlibrary/core/src/image/ZLStreamImage.h +++ b/jni/NativeFormats/zlibrary/core/src/image/ZLStreamImage.h @@ -28,25 +28,25 @@ class ZLStreamImage : public ZLSingleImage { public: - ZLStreamImage(const std::string &mimeType, const std::string &encoding, size_t offset, size_t size = 0); + ZLStreamImage(const std::string &mimeType, const std::string &encoding, std::size_t offset, std::size_t size = 0); //const shared_ptr stringData() const; const std::string &encoding() const; - size_t offset() const; - size_t size() const; + std::size_t offset() const; + std::size_t size() const; private: //virtual shared_ptr inputStream() const = 0; private: const std::string myEncoding; - const size_t myOffset; - mutable size_t mySize; + const std::size_t myOffset; + mutable std::size_t mySize; }; -inline ZLStreamImage::ZLStreamImage(const std::string &mimeType, const std::string &encoding, size_t offset, size_t size) : ZLSingleImage(mimeType), myEncoding(encoding), myOffset(offset), mySize(size) {} +inline ZLStreamImage::ZLStreamImage(const std::string &mimeType, const std::string &encoding, std::size_t offset, std::size_t size) : ZLSingleImage(mimeType), myEncoding(encoding), myOffset(offset), mySize(size) {} inline const std::string &ZLStreamImage::encoding() const { return myEncoding; } -inline size_t ZLStreamImage::offset() const { return myOffset; } -inline size_t ZLStreamImage::size() const { return mySize; } +inline std::size_t ZLStreamImage::offset() const { return myOffset; } +inline std::size_t ZLStreamImage::size() const { return mySize; } #endif /* __ZLSTREAMIMAGE_H__ */ diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp index 156584609..091d34e96 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.cpp @@ -21,13 +21,13 @@ #include "ZLCharSequence.h" -ZLCharSequence::ZLCharSequence(const char *ptr, size_t size) : mySize(size) { +ZLCharSequence::ZLCharSequence(const char *ptr, std::size_t size) : mySize(size) { if (mySize == 0) { myHead = 0; return; } myHead = new char[mySize]; - for (size_t count = 0; count < mySize; ++count){ + for (std::size_t count = 0; count < mySize; ++count){ myHead[count] = ptr[count]; } } @@ -38,7 +38,7 @@ ZLCharSequence::ZLCharSequence(const ZLCharSequence& other) : mySize(other.mySiz return; } myHead = new char[other.mySize]; - for (size_t count = 0; count < mySize; ++count) { + for (std::size_t count = 0; count < mySize; ++count) { myHead[count] = other.myHead[count]; } } @@ -46,7 +46,7 @@ ZLCharSequence::ZLCharSequence(const ZLCharSequence& other) : mySize(other.mySiz ZLCharSequence::ZLCharSequence(const std::string &hexSequence) { mySize = (hexSequence.size() + 1) / 5; myHead = new char[mySize]; - for (size_t count = 0; count < mySize; ++count){ + for (std::size_t count = 0; count < mySize; ++count){ char a = hexSequence[count * 5 + 2]; char b = hexSequence[count * 5 + 3]; a -= (a >= 97) ? 87 : 48; @@ -66,7 +66,7 @@ ZLCharSequence& ZLCharSequence::operator= (const ZLCharSequence& other) { if (myHead == 0) { myHead = new char[mySize]; } - for (size_t count = 0; count < mySize; ++count) { + for (std::size_t count = 0; count < mySize; ++count) { myHead[count] = other.myHead[count]; } } @@ -77,7 +77,7 @@ ZLCharSequence& ZLCharSequence::operator= (const ZLCharSequence& other) { std::string ZLCharSequence::toHexSequence() const { std::string result; static const char table[] = "0123456789abcdef"; - for (size_t count = 0;; ++count) { + for (std::size_t count = 0;; ++count) { result += "0x"; result += table[(myHead[count] >> 4) & 0x0F]; result += table[myHead[count] & 0x0F]; @@ -94,7 +94,7 @@ int ZLCharSequence::compareTo(const ZLCharSequence &other) const { if (difference != 0) { return difference; } - for (size_t i = 0; i < mySize; ++i) { + for (std::size_t i = 0; i < mySize; ++i) { int a = (int)(unsigned int)(unsigned char) myHead[i]; int b = (int)(unsigned int)(unsigned char) other.myHead[i]; difference = a - b; diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.h b/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.h index c73b35647..6b4b11227 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.h +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLCharSequence.h @@ -26,13 +26,13 @@ class ZLCharSequence { public: ZLCharSequence(); - ZLCharSequence(const char *ptr, size_t size); + ZLCharSequence(const char *ptr, std::size_t size); ZLCharSequence(const std::string &hexSequence); ZLCharSequence(const ZLCharSequence &other); ~ZLCharSequence(); - size_t getSize() const; - const char &operator [] (size_t index) const; + std::size_t getSize() const; + const char &operator [] (std::size_t index) const; ZLCharSequence &operator = (const ZLCharSequence& other); std::string toHexSequence() const; @@ -44,13 +44,13 @@ public: int compareTo(const ZLCharSequence &other) const; private: - size_t mySize; + std::size_t mySize; char *myHead; }; inline ZLCharSequence::ZLCharSequence() : mySize(0), myHead(0) {} -inline const char& ZLCharSequence::operator [] (size_t index) const { +inline const char& ZLCharSequence::operator [] (std::size_t index) const { return myHead[index]; } @@ -64,7 +64,7 @@ inline ZLCharSequence::~ZLCharSequence() { } } -inline size_t ZLCharSequence::getSize() const { +inline std::size_t ZLCharSequence::getSize() const { return mySize; } diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp index 1a5669554..ac337de80 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.cpp @@ -55,7 +55,7 @@ ZLLanguageDetector::ZLLanguageDetector() { ZLLanguageDetector::~ZLLanguageDetector() { } -static std::string naiveEncodingDetection(const unsigned char *buffer, size_t length) { +static std::string naiveEncodingDetection(const unsigned char *buffer, std::size_t length) { if (buffer[0] == 0xFE && buffer[1] == 0xFF) { return ZLEncodingConverter::UTF16BE; } @@ -89,7 +89,7 @@ static std::string naiveEncodingDetection(const unsigned char *buffer, size_t le return ascii ? ZLEncodingConverter::ASCII : ZLEncodingConverter::UTF8; } -shared_ptr ZLLanguageDetector::findInfo(const char *buffer, size_t length, int matchingCriterion) { +shared_ptr ZLLanguageDetector::findInfo(const char *buffer, std::size_t length, int matchingCriterion) { std::string naive; if ((unsigned char)buffer[0] == 0xFE && (unsigned char)buffer[1] == 0xFF) { @@ -103,7 +103,7 @@ shared_ptr ZLLanguageDetector::findInfo(const return findInfoForEncoding(naive, buffer, length, matchingCriterion); } -shared_ptr ZLLanguageDetector::findInfoForEncoding(const std::string &encoding, const char *buffer, size_t length, int matchingCriterion) { +shared_ptr ZLLanguageDetector::findInfoForEncoding(const std::string &encoding, const char *buffer, std::size_t length, int matchingCriterion) { shared_ptr info; std::map > statisticsMap; for (SBVector::const_iterator it = myMatchers.begin(); it != myMatchers.end(); ++it) { diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h index cef024d4f..7f5d8dc63 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLLanguageDetector.h @@ -40,8 +40,8 @@ public: ZLLanguageDetector(); ~ZLLanguageDetector(); - shared_ptr findInfo(const char *buffer, size_t length, int matchingCriterion = 0); - shared_ptr findInfoForEncoding(const std::string &encoding, const char *buffer, size_t length, int matchingCriterion = 0); + shared_ptr findInfo(const char *buffer, std::size_t length, int matchingCriterion = 0); + shared_ptr findInfoForEncoding(const std::string &encoding, const char *buffer, std::size_t length, int matchingCriterion = 0); private: typedef std::vector > SBVector; diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.cpp index 39b779c82..d9365e301 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.cpp @@ -28,12 +28,12 @@ ZLStatistics::ZLStatistics() : myCharSequenceSize(0), myVolumesAreUpToDate(true) myVolume(0), mySquaresVolume(0) { } -ZLStatistics::ZLStatistics(size_t charSequenceSize) : +ZLStatistics::ZLStatistics(std::size_t charSequenceSize) : myCharSequenceSize(charSequenceSize), myVolumesAreUpToDate(true), myVolume(0), mySquaresVolume(0) { } -ZLStatistics::ZLStatistics(size_t charSequenceSize, size_t volume, unsigned long long squaresVolume) : +ZLStatistics::ZLStatistics(std::size_t charSequenceSize, std::size_t volume, unsigned long long squaresVolume) : myCharSequenceSize(charSequenceSize), myVolumesAreUpToDate(true), myVolume(volume), mySquaresVolume(squaresVolume) { } @@ -41,7 +41,7 @@ ZLStatistics::ZLStatistics(size_t charSequenceSize, size_t volume, unsigned long ZLStatistics::~ZLStatistics() { } -size_t ZLStatistics::getVolume() const { +std::size_t ZLStatistics::getVolume() const { if (!myVolumesAreUpToDate) { calculateVolumes(); } @@ -86,7 +86,7 @@ int ZLStatistics::correlation(const ZLStatistics& candidate, const ZLStatistics& const shared_ptr endA = candidate.end(); const shared_ptr endB = pattern.end(); - size_t count = 0; + std::size_t count = 0; long long correlationSum = 0; while ((*ptrA != *endA) && (*ptrB != *endB)) { ++count; @@ -172,14 +172,14 @@ void ZLMapBasedStatistics::calculateVolumes() const { myVolume = 0; mySquaresVolume = 0; for (Dictionary::const_iterator it = myDictionary.begin(); it != myDictionary.end(); ++it) { - const size_t frequency = it->second; + const std::size_t frequency = it->second; myVolume += frequency; mySquaresVolume += frequency * frequency; } myVolumesAreUpToDate = true; } -ZLMapBasedStatistics ZLMapBasedStatistics::top(size_t amount) const { +ZLMapBasedStatistics ZLMapBasedStatistics::top(std::size_t amount) const { if (myDictionary.empty()) { return ZLMapBasedStatistics(); } @@ -237,10 +237,10 @@ void ZLMapBasedStatistics::retain(const ZLMapBasedStatistics &other) { } void ZLMapBasedStatistics::scaleToShort() { - const size_t maxFrequency = std::max_element(myDictionary.begin(), myDictionary.end(), LessFrequency())->second; - const size_t maxShort = 65535; + const std::size_t maxFrequency = std::max_element(myDictionary.begin(), myDictionary.end(), LessFrequency())->second; + const std::size_t maxShort = 65535; if (maxFrequency > maxShort) { - const size_t devider = maxFrequency / maxShort + 1; + const std::size_t devider = maxFrequency / maxShort + 1; Dictionary::iterator it = myDictionary.begin(); const Dictionary::iterator end = myDictionary.end(); while (it != end) { @@ -266,7 +266,7 @@ ZLArrayBasedStatistics::ZLArrayBasedStatistics() : ZLStatistics(), myCapacity(0), myBack(0), mySequences(0), myFrequencies(0) { } -ZLArrayBasedStatistics::ZLArrayBasedStatistics(size_t charSequenceSize, size_t size, size_t volume, unsigned long long squaresVolume) : +ZLArrayBasedStatistics::ZLArrayBasedStatistics(std::size_t charSequenceSize, std::size_t size, std::size_t volume, unsigned long long squaresVolume) : ZLStatistics(charSequenceSize, volume, squaresVolume), myCapacity(size) { myBack = 0; mySequences = new char[myCharSequenceSize * size]; @@ -280,11 +280,11 @@ ZLArrayBasedStatistics::~ZLArrayBasedStatistics() { } } -void ZLArrayBasedStatistics::insert(const ZLCharSequence &charSequence, size_t frequency) { +void ZLArrayBasedStatistics::insert(const ZLCharSequence &charSequence, std::size_t frequency) { if (myBack == myCapacity) { return; } - for (size_t i = 0; i < myCharSequenceSize; ++i) { + for (std::size_t i = 0; i < myCharSequenceSize; ++i) { mySequences[myBack * myCharSequenceSize + i] = charSequence[i]; } myFrequencies[myBack] = (unsigned short) frequency; @@ -295,8 +295,8 @@ void ZLArrayBasedStatistics::insert(const ZLCharSequence &charSequence, size_t f void ZLArrayBasedStatistics::calculateVolumes() const { myVolume = 0; mySquaresVolume = 0; - for (size_t i = 0; i != myBack; ++i) { - const size_t frequency = myFrequencies[i]; + for (std::size_t i = 0; i != myBack; ++i) { + const std::size_t frequency = myFrequencies[i]; myVolume += frequency; mySquaresVolume += frequency * frequency; } diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.h b/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.h index 27d280b47..d9b7f6f6b 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.h +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatistics.h @@ -32,13 +32,13 @@ class ZLStatistics { public: ZLStatistics(); - ZLStatistics(size_t charSequenceSize); - ZLStatistics(size_t charSequenceSize, size_t volume, unsigned long long squaresVolume); + ZLStatistics(std::size_t charSequenceSize); + ZLStatistics(std::size_t charSequenceSize, std::size_t volume, unsigned long long squaresVolume); virtual ~ZLStatistics(); - size_t getVolume() const; + std::size_t getVolume() const; unsigned long long getSquaresVolume() const; - size_t getCharSequenceSize() const; + std::size_t getCharSequenceSize() const; public: virtual shared_ptr begin() const = 0; @@ -51,26 +51,26 @@ public: static int correlation(const ZLStatistics &candidate, const ZLStatistics &pattern); protected: - size_t myCharSequenceSize; + std::size_t myCharSequenceSize; mutable bool myVolumesAreUpToDate; - mutable size_t myVolume; + mutable std::size_t myVolume; mutable unsigned long long mySquaresVolume; }; class ZLMapBasedStatistics : public ZLStatistics { private: - typedef std::vector > Vector; - typedef std::map Dictionary; + typedef std::vector > Vector; + typedef std::map Dictionary; public: ZLMapBasedStatistics(); ZLMapBasedStatistics(const Dictionary &dictionary); ~ZLMapBasedStatistics(); - size_t getSize() const; + std::size_t getSize() const; - ZLMapBasedStatistics top(size_t amount) const; + ZLMapBasedStatistics top(std::size_t amount) const; void scaleToShort(); void retain(const ZLMapBasedStatistics &other); @@ -85,7 +85,7 @@ protected: private: struct LessFrequency { - bool operator() (const std::pair a, const std::pair b) { + bool operator() (const std::pair a, const std::pair b) { return (a.second < b.second); } }; @@ -97,11 +97,11 @@ private: class ZLArrayBasedStatistics : public ZLStatistics { public: ZLArrayBasedStatistics(); - ZLArrayBasedStatistics(size_t charSequenceSize, size_t size, size_t volume, unsigned long long squaresVolume); + ZLArrayBasedStatistics(std::size_t charSequenceSize, std::size_t size, std::size_t volume, unsigned long long squaresVolume); ~ZLArrayBasedStatistics(); ZLArrayBasedStatistics &operator = (const ZLArrayBasedStatistics &other); - void insert(const ZLCharSequence &charSequence, size_t frequency); + void insert(const ZLCharSequence &charSequence, std::size_t frequency); bool empty() const; @@ -112,17 +112,17 @@ protected: void calculateVolumes() const; private: - size_t myCapacity; - size_t myBack; + std::size_t myCapacity; + std::size_t myBack; char* mySequences; unsigned short* myFrequencies; }; -inline size_t ZLStatistics::getCharSequenceSize() const { +inline std::size_t ZLStatistics::getCharSequenceSize() const { return myCharSequenceSize; } -inline size_t ZLMapBasedStatistics::getSize() const { +inline std::size_t ZLMapBasedStatistics::getSize() const { return myDictionary.size(); } diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.cpp index 21e21ec02..46046e12f 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.cpp @@ -28,7 +28,7 @@ #include "ZLStatistics.h" #include "ZLStatisticsGenerator.h" -size_t ZLStatisticsGenerator::ourBufferSize = 102400; +std::size_t ZLStatisticsGenerator::ourBufferSize = 102400; ZLStatisticsGenerator::ZLStatisticsGenerator(const std::string &breakSymbols) { myBreakSymbolsTable = new char[256]; @@ -56,21 +56,21 @@ int ZLStatisticsGenerator::read(const std::string &inputFileName) { return 0; } -void ZLStatisticsGenerator::generate(const std::string &inputFileName, size_t charSequenceSize, ZLMapBasedStatistics &statistics) { +void ZLStatisticsGenerator::generate(const std::string &inputFileName, std::size_t charSequenceSize, ZLMapBasedStatistics &statistics) { if (read(inputFileName) == 1) { return; } - if ((size_t)(myEnd - myStart) < (charSequenceSize-1)) { + if ((std::size_t)(myEnd - myStart) < (charSequenceSize-1)) { return; } generate(myStart, myEnd - myStart, charSequenceSize, statistics); } -void ZLStatisticsGenerator::generate(const char* buffer, size_t length, size_t charSequenceSize, ZLMapBasedStatistics &statistics) { +void ZLStatisticsGenerator::generate(const char* buffer, std::size_t length, std::size_t charSequenceSize, ZLMapBasedStatistics &statistics) { const char *start = buffer; const char *end = buffer + length; - std::map dictionary; - size_t locker = charSequenceSize; + std::map dictionary; + std::size_t locker = charSequenceSize; for (const char *ptr = start; ptr < end;) { if (myBreakSymbolsTable[(unsigned char)*(ptr)] == 1) { locker = charSequenceSize; diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.h b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.h index 822051318..219672542 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.h +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsGenerator.h @@ -30,8 +30,8 @@ public: ZLStatisticsGenerator(const std::string &breakSymbols); ~ZLStatisticsGenerator(); - void generate(const std::string &inputFileName, size_t charSequenceSizpe, ZLMapBasedStatistics &statistics); - void generate(const char* buffer, size_t length, size_t charSequenceSize, ZLMapBasedStatistics &statistics); + void generate(const std::string &inputFileName, std::size_t charSequenceSizpe, ZLMapBasedStatistics &statistics); + void generate(const char* buffer, std::size_t length, std::size_t charSequenceSize, ZLMapBasedStatistics &statistics); private: int read(const std::string &inputFileName); @@ -42,7 +42,7 @@ private: char *myStart; char *myEnd; - static size_t ourBufferSize; + static std::size_t ourBufferSize; }; #endif //__ZLSTATISTICSGENERATOR_H__ diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.cpp index 888b9d131..94c0efb1a 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.cpp @@ -19,7 +19,7 @@ #include "ZLStatisticsItem.h" -ZLMapBasedStatisticsItem::ZLMapBasedStatisticsItem(const std::map::const_iterator it, size_t index) : ZLStatisticsItem(index), +ZLMapBasedStatisticsItem::ZLMapBasedStatisticsItem(const std::map::const_iterator it, std::size_t index) : ZLStatisticsItem(index), myIterator(it) { } @@ -27,7 +27,7 @@ ZLCharSequence ZLMapBasedStatisticsItem::sequence() const { return myIterator->first; } -size_t ZLMapBasedStatisticsItem::frequency() const { +std::size_t ZLMapBasedStatisticsItem::frequency() const { return myIterator->second; } @@ -36,7 +36,7 @@ void ZLMapBasedStatisticsItem::next() { ++myIterator; } -ZLArrayBasedStatisticsItem::ZLArrayBasedStatisticsItem(size_t sequenceLength, char* sequencePtr, unsigned short* frequencyPtr, size_t index) : +ZLArrayBasedStatisticsItem::ZLArrayBasedStatisticsItem(std::size_t sequenceLength, char* sequencePtr, unsigned short* frequencyPtr, std::size_t index) : ZLStatisticsItem(index), mySequencePtr(sequencePtr), myFrequencyPtr(frequencyPtr), @@ -47,8 +47,8 @@ ZLCharSequence ZLArrayBasedStatisticsItem::sequence() const { return ZLCharSequence(mySequencePtr, mySequenceLength); } -size_t ZLArrayBasedStatisticsItem::frequency() const { - return (size_t) *myFrequencyPtr; +std::size_t ZLArrayBasedStatisticsItem::frequency() const { + return (std::size_t) *myFrequencyPtr; } void ZLArrayBasedStatisticsItem::next() { diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.h b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.h index 29ce19c83..4038b439b 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.h +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsItem.h @@ -28,53 +28,53 @@ struct ZLStatisticsItem { public: - ZLStatisticsItem(size_t index); + ZLStatisticsItem(std::size_t index); virtual ~ZLStatisticsItem(); virtual ZLCharSequence sequence() const = 0; - virtual size_t frequency() const = 0; + virtual std::size_t frequency() const = 0; virtual void next() = 0; bool operator == (const ZLStatisticsItem &otherItem) const; bool operator != (const ZLStatisticsItem &otherItem) const; - size_t index() const; + std::size_t index() const; protected: - size_t myIndex; + std::size_t myIndex; }; struct ZLMapBasedStatisticsItem : public ZLStatisticsItem { - ZLMapBasedStatisticsItem(const std::map::const_iterator it, size_t index); + ZLMapBasedStatisticsItem(const std::map::const_iterator it, std::size_t index); ZLCharSequence sequence() const; - size_t frequency() const; + std::size_t frequency() const; void next(); private: - std::map::const_iterator myIterator; + std::map::const_iterator myIterator; }; struct ZLArrayBasedStatisticsItem : public ZLStatisticsItem { - ZLArrayBasedStatisticsItem(size_t sequenceLength, char* sequencePtr, unsigned short* frequencyPtr, size_t index); + ZLArrayBasedStatisticsItem(std::size_t sequenceLength, char* sequencePtr, unsigned short* frequencyPtr, std::size_t index); ZLCharSequence sequence() const; - size_t frequency() const; + std::size_t frequency() const; void next(); private: char const *mySequencePtr; unsigned short const *myFrequencyPtr; - const size_t mySequenceLength; + const std::size_t mySequenceLength; }; -inline ZLStatisticsItem::ZLStatisticsItem(size_t index) : myIndex(index) { +inline ZLStatisticsItem::ZLStatisticsItem(std::size_t index) : myIndex(index) { } inline ZLStatisticsItem::~ZLStatisticsItem() { } -inline size_t ZLStatisticsItem::index() const { +inline std::size_t ZLStatisticsItem::index() const { return myIndex; } diff --git a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp index 1f3e72f2f..57d672353 100644 --- a/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp +++ b/jni/NativeFormats/zlibrary/core/src/language/ZLStatisticsXMLReader.cpp @@ -33,7 +33,7 @@ const std::string ZLStatisticsXMLReader::STATISTICS_TAG = "statistics"; void ZLStatisticsXMLReader::startElementHandler(const char *tag, const char **attributes) { if (STATISTICS_TAG == tag) { - size_t volume = atoi(attributeValue(attributes, "volume")); + std::size_t volume = atoi(attributeValue(attributes, "volume")); unsigned long long squaresVolume = atoll(attributeValue(attributes, "squaresVolume")); //std::cerr << "XMLReader: frequencies sum & ^2: " << volume << ":" << squaresVolume << "\n"; myStatisticsPtr = new ZLArrayBasedStatistics( atoi(attributeValue(attributes, "charSequenceSize")), atoi(attributeValue(attributes, "size")), volume, squaresVolume); diff --git a/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.cpp b/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.cpp index 2b18ab6a0..2521f8ecf 100644 --- a/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.cpp +++ b/jni/NativeFormats/zlibrary/core/src/library/ZLibrary.cpp @@ -60,7 +60,7 @@ void ZLibrary::parseArguments(int &argc, char **&argv) { } } else*/ if (LOGGER_OPTION == argument) { std::string loggerClasses = argv[2]; - while (size_t index = loggerClasses.find(':') != std::string::npos) { + while (std::size_t index = loggerClasses.find(':') != std::string::npos) { ZLLogger::Instance().registerClass(loggerClasses.substr(0, index)); loggerClasses.erase(0, index + 1); } diff --git a/jni/NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp b/jni/NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp index a41888ff6..839874998 100644 --- a/jni/NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp +++ b/jni/NativeFormats/zlibrary/core/src/logger/ZLLogger.cpp @@ -41,7 +41,7 @@ void ZLLogger::registerClass(const std::string &className) { void ZLLogger::print(const std::string &className, const std::string &message) const { std::string m = message; - for (size_t index = m.find('%'); index != std::string::npos; index = m.find('%', index + 2)) { + for (std::size_t index = m.find('%'); index != std::string::npos; index = m.find('%', index + 2)) { m.replace(index, 1, "%%"); } if (className == DEFAULT_CLASS) { diff --git a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp index 328513222..a73bdcde8 100644 --- a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp +++ b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.cpp @@ -38,7 +38,7 @@ bool ZLUnixFileInputStream::open() { return myFile != 0; } -size_t ZLUnixFileInputStream::read(char *buffer, size_t maxSize) { +std::size_t ZLUnixFileInputStream::read(char *buffer, std::size_t maxSize) { if (buffer != 0) { if (myNeedRepositionToStart) { fseek(myFile, 0, SEEK_SET); @@ -65,7 +65,7 @@ void ZLUnixFileInputStream::close() { } } -size_t ZLUnixFileInputStream::sizeOfOpened() { +std::size_t ZLUnixFileInputStream::sizeOfOpened() { if (myFile == 0) { return 0; } @@ -84,6 +84,6 @@ void ZLUnixFileInputStream::seek(int offset, bool absoluteOffset) { fseek(myFile, offset, absoluteOffset ? SEEK_SET : SEEK_CUR); } -size_t ZLUnixFileInputStream::offset() const { +std::size_t ZLUnixFileInputStream::offset() const { return myNeedRepositionToStart ? 0 : ftell(myFile); } diff --git a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.h b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.h index 5653c6214..470489ebf 100644 --- a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.h +++ b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileInputStream.h @@ -30,12 +30,12 @@ public: ZLUnixFileInputStream(const std::string &name); ~ZLUnixFileInputStream(); bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: std::string myName; diff --git a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp index f5e524f0f..4223825a9 100644 --- a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp +++ b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.cpp @@ -46,14 +46,14 @@ bool ZLUnixFileOutputStream::open() { return myFile != 0; } -void ZLUnixFileOutputStream::write(const char *data, size_t len) { +void ZLUnixFileOutputStream::write(const char *data, std::size_t len) { if (::fwrite(data, 1, len, myFile) != len) { myHasErrors = true; } } void ZLUnixFileOutputStream::write(const std::string &str) { - if (::fwrite(str.data(), 1, str.length(), myFile) != (size_t)str.length()) { + if (::fwrite(str.data(), 1, str.length(), myFile) != (std::size_t)str.length()) { myHasErrors = true; } } diff --git a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.h b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.h index f0badb1c5..7f61a0c2b 100644 --- a/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.h +++ b/jni/NativeFormats/zlibrary/core/src/unix/filesystem/ZLUnixFileOutputStream.h @@ -30,7 +30,7 @@ public: ZLUnixFileOutputStream(const std::string &name); ~ZLUnixFileOutputStream(); bool open(); - void write(const char *data, size_t len); + void write(const char *data, std::size_t len); void write(const std::string &str); void close(); diff --git a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp index db097389c..f099f100e 100644 --- a/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp +++ b/jni/NativeFormats/zlibrary/core/src/util/ZLStringUtil.cpp @@ -64,7 +64,7 @@ void ZLStringUtil::appendNumber(std::string &str, unsigned int n) { } void ZLStringUtil::append(std::string &str, const std::vector &text) { - size_t len = str.length(); + std::size_t len = str.length(); for (std::vector::const_iterator it = text.begin(); it != text.end(); ++it) { len += it->length(); } @@ -75,15 +75,15 @@ void ZLStringUtil::append(std::string &str, const std::vector &text } void ZLStringUtil::stripWhiteSpaces(std::string &str) { - size_t counter = 0; - size_t length = str.length(); + std::size_t counter = 0; + std::size_t length = str.length(); while ((counter < length) && isspace((unsigned char)str[counter])) { counter++; } str.erase(0, counter); length -= counter; - size_t r_counter = length; + std::size_t r_counter = length; while ((r_counter > 0) && isspace((unsigned char)str[r_counter - 1])) { r_counter--; } @@ -92,8 +92,8 @@ void ZLStringUtil::stripWhiteSpaces(std::string &str) { std::vector ZLStringUtil::split(const std::string &str, const std::string &delimiter) { std::vector result; - size_t start = 0; - size_t index = str.find(delimiter); + std::size_t start = 0; + std::size_t index = str.find(delimiter); while (index != std::string::npos) { result.push_back(str.substr(start, index - start)); start = index + delimiter.length(); @@ -135,7 +135,7 @@ int ZLStringUtil::stringToInteger(const std::string &str, int defaultValue) { return defaultValue; } - for (size_t i = 1; i < str.length(); ++i) { + for (std::size_t i = 1; i < str.length(); ++i) { if (!isdigit(str[i])) { return defaultValue; } diff --git a/jni/NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.h b/jni/NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.h index 82ab17db4..371d70367 100644 --- a/jni/NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.h +++ b/jni/NativeFormats/zlibrary/core/src/xml/ZLAsynchronousInputStream.h @@ -32,7 +32,7 @@ public: virtual ~Handler(); virtual void initialize(const char *encoding) = 0; virtual void shutdown() = 0; - virtual bool handleBuffer(const char *data, size_t len) = 0; + virtual bool handleBuffer(const char *data, std::size_t len) = 0; }; public: @@ -40,7 +40,7 @@ public: virtual ~ZLAsynchronousInputStream(); void setEof(); - void setBuffer(const char *data, size_t len); + void setBuffer(const char *data, std::size_t len); bool eof() const; bool initialized() const; @@ -51,7 +51,7 @@ protected: protected: const char *myData; - size_t myDataLen; + std::size_t myDataLen; private: std::string myEncoding; @@ -65,7 +65,7 @@ private: }; inline void ZLAsynchronousInputStream::setEof() { myEof = true; myData = 0; myDataLen = 0; } -inline void ZLAsynchronousInputStream::setBuffer(const char *data, size_t len) { myData = data; myDataLen = len; } +inline void ZLAsynchronousInputStream::setBuffer(const char *data, std::size_t len) { myData = data; myDataLen = len; } inline bool ZLAsynchronousInputStream::eof() const { return myEof; } inline bool ZLAsynchronousInputStream::initialized() const { return myInitialized; } diff --git a/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp b/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp index 61a6613ce..01e12ec21 100644 --- a/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp +++ b/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.cpp @@ -39,7 +39,7 @@ public: void initialize(const char *encoding); void shutdown(); - bool handleBuffer(const char *data, size_t len); + bool handleBuffer(const char *data, std::size_t len); private: ZLXMLReader &myReader; @@ -56,11 +56,11 @@ void ZLXMLReaderHandler::shutdown() { myReader.shutdown(); } -bool ZLXMLReaderHandler::handleBuffer(const char *data, size_t len) { +bool ZLXMLReaderHandler::handleBuffer(const char *data, std::size_t len) { return myReader.readFromBuffer(data, len); } -static const size_t BUFFER_SIZE = 2048; +static const std::size_t BUFFER_SIZE = 2048; void ZLXMLReader::startElementHandler(const char*, const char**) { } @@ -68,7 +68,7 @@ void ZLXMLReader::startElementHandler(const char*, const char**) { void ZLXMLReader::endElementHandler(const char*) { } -void ZLXMLReader::characterDataHandler(const char*, size_t) { +void ZLXMLReader::characterDataHandler(const char*, std::size_t) { } const ZLXMLReader::nsMap &ZLXMLReader::namespaces() const { @@ -108,7 +108,7 @@ bool ZLXMLReader::readDocument(shared_ptr stream) { } initialize(useWindows1252 ? "windows-1252" : 0); - size_t length; + std::size_t length; do { length = stream->read(myParserBuffer, BUFFER_SIZE); if (!readFromBuffer(myParserBuffer, length)) { @@ -133,7 +133,7 @@ void ZLXMLReader::shutdown() { myNamespaces.clear(); } -bool ZLXMLReader::readFromBuffer(const char *data, size_t len) { +bool ZLXMLReader::readFromBuffer(const char *data, std::size_t len) { return myInternalReader->parseBuffer(data, len); } @@ -179,7 +179,7 @@ ZLXMLReader::NamespaceAttributeNamePredicate::NamespaceAttributeNamePredicate(co bool ZLXMLReader::NamespaceAttributeNamePredicate::accepts(const ZLXMLReader &reader, const char *name) const { const std::string full(name); - const size_t index = full.find(':'); + const std::size_t index = full.find(':'); const std::string namespaceId = index == std::string::npos ? std::string() : full.substr(0, index); @@ -239,6 +239,6 @@ void ZLXMLReader::setErrorMessage(const std::string &message) { interrupt(); } -size_t ZLXMLReader::getCurrentPosition() const { - return myInternalReader != 0 ? myInternalReader->getCurrentPosition() : (size_t)-1; +std::size_t ZLXMLReader::getCurrentPosition() const { + return myInternalReader != 0 ? myInternalReader->getCurrentPosition() : (std::size_t)-1; } diff --git a/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.h b/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.h index 08fcf36f1..002f1bd3f 100644 --- a/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.h +++ b/jni/NativeFormats/zlibrary/core/src/xml/ZLXMLReader.h @@ -83,19 +83,19 @@ public: private: void initialize(const char *encoding = 0); void shutdown(); - bool readFromBuffer(const char *data, size_t len); + bool readFromBuffer(const char *data, std::size_t len); protected: virtual void startElementHandler(const char *tag, const char **attributes); virtual void endElementHandler(const char *tag); - virtual void characterDataHandler(const char *text, size_t len); + virtual void characterDataHandler(const char *text, std::size_t len); virtual bool processNamespaces() const; virtual const std::vector &externalDTDs() const; virtual void collectExternalEntities(std::map &entityMap); bool testTag(const std::string &ns, const std::string &name, const std::string &tag) const; bool isInterrupted() const; - size_t getCurrentPosition() const; + std::size_t getCurrentPosition() const; protected: void interrupt(); diff --git a/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp b/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp index df266b38f..3ac9b8eb8 100644 --- a/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp +++ b/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.cpp @@ -39,7 +39,7 @@ void ZLXMLReaderInternal::fStartElementHandler(void *userData, const char *name, if (reader.processNamespaces()) { int count = 0; for (const char **a = attributes; (*a != 0) && (*(a + 1) != 0); a += 2) { - if (strncmp(*a, "xmlns", 5) == 0) { + if (std::strncmp(*a, "xmlns", 5) == 0) { std::string id; if ((*a)[5] == ':') { id = *a + 6; @@ -83,7 +83,7 @@ static int fUnknownEncodingHandler(void*, const XML_Char *name, XML_Encoding *en return XML_STATUS_ERROR; } -static const size_t BUFSIZE = 2048; +static const std::size_t BUFSIZE = 2048; static void parseDTD(XML_Parser parser, const std::string &fileName) { XML_Parser entityParser = XML_ExternalEntityParserCreate(parser, 0, 0); @@ -91,7 +91,7 @@ static void parseDTD(XML_Parser parser, const std::string &fileName) { shared_ptr entityStream = dtdFile.inputStream(); if (!entityStream.isNull() && entityStream->open()) { char buffer[BUFSIZE]; - size_t length; + std::size_t length; do { length = entityStream->read(buffer, BUFSIZE); if (XML_Parse(entityParser, buffer, length, 0) == XML_STATUS_ERROR) { @@ -160,10 +160,10 @@ void ZLXMLReaderInternal::init(const char *encoding) { XML_SetUnknownEncodingHandler(myParser, fUnknownEncodingHandler, 0); } -bool ZLXMLReaderInternal::parseBuffer(const char *buffer, size_t len) { +bool ZLXMLReaderInternal::parseBuffer(const char *buffer, std::size_t len) { return XML_Parse(myParser, buffer, len, 0) != XML_STATUS_ERROR; } -size_t ZLXMLReaderInternal::getCurrentPosition() const { +std::size_t ZLXMLReaderInternal::getCurrentPosition() const { return XML_GetCurrentByteIndex(myParser); } diff --git a/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.h b/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.h index 8eeebdc55..1fc73af44 100644 --- a/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.h +++ b/jni/NativeFormats/zlibrary/core/src/xml/expat/ZLXMLReaderInternal.h @@ -37,8 +37,8 @@ public: ZLXMLReaderInternal(ZLXMLReader &reader, const char *encoding); ~ZLXMLReaderInternal(); void init(const char *encoding = 0); - bool parseBuffer(const char *buffer, size_t len); - size_t getCurrentPosition() const; + bool parseBuffer(const char *buffer, std::size_t len); + std::size_t getCurrentPosition() const; private: void setupEntities(); diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp index 605b9a47b..659ccff12 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.cpp @@ -30,7 +30,7 @@ #include "ZLCachedMemoryAllocator.h" -ZLCachedMemoryAllocator::ZLCachedMemoryAllocator(const size_t rowSize, +ZLCachedMemoryAllocator::ZLCachedMemoryAllocator(const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension) : myRowSize(rowSize), myCurrentRowSize(0), @@ -60,18 +60,18 @@ void ZLCachedMemoryAllocator::flush() { myHasChanges = false; } -std::string ZLCachedMemoryAllocator::makeFileName(size_t index) { +std::string ZLCachedMemoryAllocator::makeFileName(std::size_t index) { std::string name(myDirectoryName); name.append("/"); ZLStringUtil::appendNumber(name, index); return name.append(".").append(myFileExtension); } -void ZLCachedMemoryAllocator::writeCache(size_t blockLength) { +void ZLCachedMemoryAllocator::writeCache(std::size_t blockLength) { if (myFailed || myPool.size() == 0) { return; } - const size_t index = myPool.size() - 1; + const std::size_t index = myPool.size() - 1; const std::string fileName = makeFileName(index); ZLFile file(fileName); shared_ptr stream = file.outputStream(); @@ -83,7 +83,7 @@ void ZLCachedMemoryAllocator::writeCache(size_t blockLength) { stream->close(); } -char *ZLCachedMemoryAllocator::allocate(size_t size) { +char *ZLCachedMemoryAllocator::allocate(std::size_t size) { myHasChanges = true; if (myPool.empty()) { myCurrentRowSize = std::max(myRowSize, size + 2 + sizeof(char*)); @@ -95,7 +95,7 @@ char *ZLCachedMemoryAllocator::allocate(size_t size) { char *ptr = myPool.back() + myOffset; *ptr++ = 0; *ptr++ = 0; - memcpy(ptr, &row, sizeof(char*)); + std::memcpy(ptr, &row, sizeof(char*)); writeCache(myOffset + 2); myPool.push_back(row); @@ -106,20 +106,20 @@ char *ZLCachedMemoryAllocator::allocate(size_t size) { return ptr; } -char *ZLCachedMemoryAllocator::reallocateLast(char *ptr, size_t newSize) { +char *ZLCachedMemoryAllocator::reallocateLast(char *ptr, std::size_t newSize) { myHasChanges = true; - const size_t oldOffset = ptr - myPool.back(); + const std::size_t oldOffset = ptr - myPool.back(); if (oldOffset + newSize + 2 + sizeof(char*) <= myCurrentRowSize) { myOffset = oldOffset + newSize; return ptr; } else { myCurrentRowSize = std::max(myRowSize, newSize + 2 + sizeof(char*)); char *row = new char[myCurrentRowSize]; - memcpy(row, ptr, myOffset - oldOffset); + std::memcpy(row, ptr, myOffset - oldOffset); *ptr++ = 0; *ptr++ = 0; - memcpy(ptr, &row, sizeof(char*)); + std::memcpy(ptr, &row, sizeof(char*)); writeCache(oldOffset + 2); myPool.push_back(row); diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h index 40815c0fa..615336ba0 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLCachedMemoryAllocator.h @@ -27,11 +27,11 @@ class ZLCachedMemoryAllocator { public: - ZLCachedMemoryAllocator(const size_t rowSize, const std::string &directoryName, const std::string &fileExtension); + ZLCachedMemoryAllocator(const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension); ~ZLCachedMemoryAllocator(); - char *allocate(size_t size); - char *reallocateLast(char *ptr, size_t newSize); + char *allocate(std::size_t size); + char *reallocateLast(char *ptr, std::size_t newSize); void flush(); @@ -44,19 +44,19 @@ public: public: const std::string &directoryName() const; const std::string &fileExtension() const; - size_t blocksNumber() const; - size_t currentBytesOffset() const; + std::size_t blocksNumber() const; + std::size_t currentBytesOffset() const; bool failed() const; private: - std::string makeFileName(size_t index); - void writeCache(size_t blockLength); + std::string makeFileName(std::size_t index); + void writeCache(std::size_t blockLength); private: - const size_t myRowSize; - size_t myCurrentRowSize; + const std::size_t myRowSize; + std::size_t myCurrentRowSize; std::vector myPool; - size_t myOffset; + std::size_t myOffset; bool myHasChanges; bool myFailed; @@ -71,8 +71,8 @@ private: // disable copying inline const std::string &ZLCachedMemoryAllocator::directoryName() const { return myDirectoryName; } inline const std::string &ZLCachedMemoryAllocator::fileExtension() const { return myFileExtension; } -inline size_t ZLCachedMemoryAllocator::blocksNumber() const { return myPool.size(); } -inline size_t ZLCachedMemoryAllocator::currentBytesOffset() const { return myOffset; } +inline std::size_t ZLCachedMemoryAllocator::blocksNumber() const { return myPool.size(); } +inline std::size_t ZLCachedMemoryAllocator::currentBytesOffset() const { return myOffset; } inline bool ZLCachedMemoryAllocator::failed() const { return myFailed; } inline char *ZLCachedMemoryAllocator::writeUInt16(char *ptr, uint16_t value) { @@ -91,7 +91,7 @@ inline char *ZLCachedMemoryAllocator::writeUInt32(char *ptr, uint32_t value) { return ptr; } inline char *ZLCachedMemoryAllocator::writeString(char *ptr, const ZLUnicodeUtil::Ucs2String &str) { - const size_t size = str.size(); + const std::size_t size = str.size(); writeUInt16(ptr, size); memcpy(ptr + 2, &str.front(), size * 2); return ptr + size * 2 + 2; diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.cpp b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.cpp index 98c2bf6cb..3d4cfdd47 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.cpp +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.cpp @@ -32,7 +32,7 @@ #include "ZLTextParagraph.h" #include "ZLTextStyleEntry.h" -ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, const size_t rowSize, +ZLTextModel::ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension) : myId(id), myLanguage(language.empty() ? ZLibrary::Language() : language), @@ -58,7 +58,7 @@ bool ZLTextModel::isRtl() const { return ZLLanguageUtil::isRTLLanguage(myLanguage); } -void ZLTextModel::search(const std::string &text, size_t startIndex, size_t endIndex, bool ignoreCase) const { +void ZLTextModel::search(const std::string &text, std::size_t startIndex, std::size_t endIndex, bool ignoreCase) const { ZLSearchPattern pattern(text, ignoreCase); myMarks.clear(); @@ -72,7 +72,7 @@ void ZLTextModel::search(const std::string &text, size_t startIndex, size_t endI if (jt.entryKind() == ZLTextParagraphEntry::TEXT_ENTRY) { const ZLTextEntry& textEntry = (ZLTextEntry&)*jt.entry(); const char *str = textEntry.data(); - const size_t len = textEntry.dataLength(); + const std::size_t len = textEntry.dataLength(); for (int pos = ZLSearchUtil::find(str, len, pattern); pos != -1; pos = ZLSearchUtil::find(str, len, pattern, pos + 1)) { myMarks.push_back(ZLTextMark(it - myParagraphs.begin(), offset + pos, pattern.length())); } @@ -82,7 +82,7 @@ void ZLTextModel::search(const std::string &text, size_t startIndex, size_t endI } } -void ZLTextModel::selectParagraph(size_t index) const { +void ZLTextModel::selectParagraph(std::size_t index) const { if (index < paragraphsNumber()) { myMarks.push_back(ZLTextMark(index, 0, (*this)[index]->textDataLength())); } @@ -120,8 +120,8 @@ ZLTextMark ZLTextModel::previousMark(ZLTextMark position) const { */ void ZLTextModel::addParagraphInternal(ZLTextParagraph *paragraph) { - const size_t dataSize = myAllocator->blocksNumber(); - const size_t bytesOffset = myAllocator->currentBytesOffset(); + const std::size_t dataSize = myAllocator->blocksNumber(); + const std::size_t bytesOffset = myAllocator->currentBytesOffset(); myStartEntryIndices.push_back((dataSize == 0) ? 0 : (dataSize - 1)); myStartEntryOffsets.push_back(bytesOffset / 2); // offset in words for future use in Java @@ -133,7 +133,7 @@ void ZLTextModel::addParagraphInternal(ZLTextParagraph *paragraph) { myLastEntryStart = 0; } -ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, const size_t rowSize, +ZLTextPlainModel::ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension) : ZLTextModel(id, language, rowSize, directoryName, fileExtension) { } @@ -150,20 +150,20 @@ void ZLTextPlainModel::createParagraph(ZLTextParagraph::Kind kind) { void ZLTextModel::addText(const std::string &text) { ZLUnicodeUtil::Ucs2String ucs2str; ZLUnicodeUtil::utf8ToUcs2(ucs2str, text); - const size_t len = ucs2str.size(); + const std::size_t len = ucs2str.size(); if (myLastEntryStart != 0 && *myLastEntryStart == ZLTextParagraphEntry::TEXT_ENTRY) { - const size_t oldLen = ZLCachedMemoryAllocator::readUInt32(myLastEntryStart + 2); - const size_t newLen = oldLen + len; + const std::size_t oldLen = ZLCachedMemoryAllocator::readUInt32(myLastEntryStart + 2); + const std::size_t newLen = oldLen + len; myLastEntryStart = myAllocator->reallocateLast(myLastEntryStart, 2 * newLen + 6); ZLCachedMemoryAllocator::writeUInt32(myLastEntryStart + 2, newLen); - memcpy(myLastEntryStart + 6 + oldLen, &ucs2str.front(), 2 * newLen); + std::memcpy(myLastEntryStart + 6 + oldLen, &ucs2str.front(), 2 * newLen); } else { myLastEntryStart = myAllocator->allocate(2 * len + 6); *myLastEntryStart = ZLTextParagraphEntry::TEXT_ENTRY; *(myLastEntryStart + 1) = 0; ZLCachedMemoryAllocator::writeUInt32(myLastEntryStart + 2, len); - memcpy(myLastEntryStart + 6, &ucs2str.front(), 2 * len); + std::memcpy(myLastEntryStart + 6, &ucs2str.front(), 2 * len); myParagraphs.back()->addEntry(myLastEntryStart); ++myParagraphLengths.back(); } @@ -174,22 +174,22 @@ void ZLTextModel::addText(const std::vector &text) { if (text.size() == 0) { return; } - size_t fullLength = 0; + std::size_t fullLength = 0; for (std::vector::const_iterator it = text.begin(); it != text.end(); ++it) { fullLength += ZLUnicodeUtil::utf8Length(*it); } ZLUnicodeUtil::Ucs2String ucs2str; if (myLastEntryStart != 0 && *myLastEntryStart == ZLTextParagraphEntry::TEXT_ENTRY) { - const size_t oldLen = ZLCachedMemoryAllocator::readUInt32(myLastEntryStart + 2); - const size_t newLen = oldLen + fullLength; + const std::size_t oldLen = ZLCachedMemoryAllocator::readUInt32(myLastEntryStart + 2); + const std::size_t newLen = oldLen + fullLength; myLastEntryStart = myAllocator->reallocateLast(myLastEntryStart, 2 * newLen + 6); ZLCachedMemoryAllocator::writeUInt32(myLastEntryStart + 2, newLen); - size_t offset = 6 + oldLen; + std::size_t offset = 6 + oldLen; for (std::vector::const_iterator it = text.begin(); it != text.end(); ++it) { ZLUnicodeUtil::utf8ToUcs2(ucs2str, *it); - const size_t len = 2 * ucs2str.size(); - memcpy(myLastEntryStart + offset, &ucs2str.front(), len); + const std::size_t len = 2 * ucs2str.size(); + std::memcpy(myLastEntryStart + offset, &ucs2str.front(), len); offset += len; ucs2str.clear(); } @@ -198,11 +198,11 @@ void ZLTextModel::addText(const std::vector &text) { *myLastEntryStart = ZLTextParagraphEntry::TEXT_ENTRY; *(myLastEntryStart + 1) = 0; ZLCachedMemoryAllocator::writeUInt32(myLastEntryStart + 2, fullLength); - size_t offset = 6; + std::size_t offset = 6; for (std::vector::const_iterator it = text.begin(); it != text.end(); ++it) { ZLUnicodeUtil::utf8ToUcs2(ucs2str, *it); - const size_t len = 2 * ucs2str.size(); - memcpy(myLastEntryStart + offset, &ucs2str.front(), len); + const std::size_t len = 2 * ucs2str.size(); + std::memcpy(myLastEntryStart + offset, &ucs2str.front(), len); offset += len; ucs2str.clear(); } @@ -237,7 +237,7 @@ void ZLTextModel::addControl(ZLTextKind textKind, bool isStart) { void ZLTextModel::addStyleEntry(const ZLTextStyleEntry &entry) { // +++ calculating entry size - size_t len = 4; // entry type + feature mask + std::size_t len = 4; // entry type + feature mask for (int i = 0; i < ZLTextStyleEntry::NUMBER_OF_LENGTHS; ++i) { if (entry.isFeatureSupported((ZLTextStyleEntry::Feature)i)) { len += 4; // each supported length @@ -314,7 +314,7 @@ void ZLTextModel::addHyperlinkControl(ZLTextKind textKind, ZLHyperlinkType hyper ZLUnicodeUtil::Ucs2String ucs2label; ZLUnicodeUtil::utf8ToUcs2(ucs2label, label); - const size_t len = ucs2label.size() * 2; + const std::size_t len = ucs2label.size() * 2; myLastEntryStart = myAllocator->allocate(len + 6); *myLastEntryStart = ZLTextParagraphEntry::HYPERLINK_CONTROL_ENTRY; @@ -322,7 +322,7 @@ void ZLTextModel::addHyperlinkControl(ZLTextKind textKind, ZLHyperlinkType hyper *(myLastEntryStart + 2) = textKind; *(myLastEntryStart + 3) = hyperlinkType; ZLCachedMemoryAllocator::writeUInt16(myLastEntryStart + 4, ucs2label.size()); - memcpy(myLastEntryStart + 6, &ucs2label.front(), len); + std::memcpy(myLastEntryStart + 6, &ucs2label.front(), len); myParagraphs.back()->addEntry(myLastEntryStart); ++myParagraphLengths.back(); } @@ -331,14 +331,14 @@ void ZLTextModel::addImage(const std::string &id, short vOffset, bool isCover) { ZLUnicodeUtil::Ucs2String ucs2id; ZLUnicodeUtil::utf8ToUcs2(ucs2id, id); - const size_t len = ucs2id.size() * 2; + const std::size_t len = ucs2id.size() * 2; myLastEntryStart = myAllocator->allocate(len + 8); *myLastEntryStart = ZLTextParagraphEntry::IMAGE_ENTRY; *(myLastEntryStart + 1) = 0; ZLCachedMemoryAllocator::writeUInt16(myLastEntryStart + 2, vOffset); ZLCachedMemoryAllocator::writeUInt16(myLastEntryStart + 4, ucs2id.size()); - memcpy(myLastEntryStart + 6, &ucs2id.front(), len); + std::memcpy(myLastEntryStart + 6, &ucs2id.front(), len); ZLCachedMemoryAllocator::writeUInt16(myLastEntryStart + 6 + len, isCover ? 1 : 0); myParagraphs.back()->addEntry(myLastEntryStart); ++myParagraphLengths.back(); diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h index d2487e516..1fb5b8087 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextModel.h @@ -37,7 +37,7 @@ class ZLTextStyleEntry; class ZLTextModel { protected: - ZLTextModel(const std::string &id, const std::string &language, const size_t rowSize, + ZLTextModel(const std::string &id, const std::string &language, const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension); ZLTextModel(const std::string &id, const std::string &language, shared_ptr allocator); @@ -49,14 +49,14 @@ public: const std::string &language() const; //bool isRtl() const; - size_t paragraphsNumber() const; - ZLTextParagraph *operator [] (size_t index); - const ZLTextParagraph *operator [] (size_t index) const; + std::size_t paragraphsNumber() const; + ZLTextParagraph *operator [] (std::size_t index); + const ZLTextParagraph *operator [] (std::size_t index) const; /* const std::vector &marks() const; - virtual void search(const std::string &text, size_t startIndex, size_t endIndex, bool ignoreCase) const; - virtual void selectParagraph(size_t index) const; + virtual void search(const std::string &text, std::size_t startIndex, std::size_t endIndex, bool ignoreCase) const; + virtual void selectParagraph(std::size_t index) const; void removeAllMarks(); ZLTextMark firstMark() const; @@ -110,7 +110,7 @@ private: class ZLTextPlainModel : public ZLTextModel { public: - ZLTextPlainModel(const std::string &id, const std::string &language, const size_t rowSize, + ZLTextPlainModel(const std::string &id, const std::string &language, const std::size_t rowSize, const std::string &directoryName, const std::string &fileExtension); ZLTextPlainModel(const std::string &id, const std::string &language, shared_ptr allocator); @@ -119,7 +119,7 @@ public: inline const std::string &ZLTextModel::id() const { return myId; } inline const std::string &ZLTextModel::language() const { return myLanguage; } -inline size_t ZLTextModel::paragraphsNumber() const { return myParagraphs.size(); } +inline std::size_t ZLTextModel::paragraphsNumber() const { return myParagraphs.size(); } //inline const std::vector &ZLTextModel::marks() const { return myMarks; } //inline void ZLTextModel::removeAllMarks() { myMarks.clear(); } inline const ZLCachedMemoryAllocator &ZLTextModel::allocator() const { return *myAllocator; } @@ -129,11 +129,11 @@ inline const std::vector &ZLTextModel::paragraphLengths() const { return m inline const std::vector &ZLTextModel::textSizes() const { return myTextSizes; }; inline const std::vector &ZLTextModel::paragraphKinds() const { return myParagraphKinds; }; -inline ZLTextParagraph *ZLTextModel::operator [] (size_t index) { +inline ZLTextParagraph *ZLTextModel::operator [] (std::size_t index) { return myParagraphs[std::min(myParagraphs.size() - 1, index)]; } -inline const ZLTextParagraph *ZLTextModel::operator [] (size_t index) const { +inline const ZLTextParagraph *ZLTextModel::operator [] (std::size_t index) const { return myParagraphs[std::min(myParagraphs.size() - 1, index)]; } diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp index 44788914c..2e6833d87 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.cpp @@ -83,7 +83,7 @@ ZLTextStyleEntry::ZLTextStyleEntry(char *address) { myAlignmentType = (ZLTextAlignmentType)*address++; myFontSizeMagnification = *address++; if (isFeatureSupported(FONT_FAMILY)) { - const size_t len = ZLCachedMemoryAllocator::readUInt16(address); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(address); ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 2); ZLUnicodeUtil::Ucs2String ucs2str(ucs2data, ucs2data + len); ZLUnicodeUtil::ucs2ToUtf8(myFontFamily, ucs2str); @@ -106,14 +106,14 @@ shared_ptr ZLTextControlEntryPool::controlEntry(ZLTextKind /* ZLTextHyperlinkControlEntry::ZLTextHyperlinkControlEntry(const char *address) : ZLTextControlEntry((ZLTextKind)*address, true), myHyperlinkType((ZLHyperlinkType)*(address + 1)) { - const size_t len = ZLCachedMemoryAllocator::readUInt16(address + 2); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(address + 2); ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 4); ZLUnicodeUtil::Ucs2String ucs2str(ucs2data, ucs2data + len); ZLUnicodeUtil::ucs2ToUtf8(myLabel, ucs2str); } ZLTextEntry::ZLTextEntry(const char *address) { - const size_t len = ZLCachedMemoryAllocator::readUInt32(address); + const std::size_t len = ZLCachedMemoryAllocator::readUInt32(address); ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 4); ZLUnicodeUtil::Ucs2String ucs2str(ucs2data, ucs2data + len); ZLUnicodeUtil::ucs2ToUtf8(myText, ucs2str); @@ -121,7 +121,7 @@ ZLTextEntry::ZLTextEntry(const char *address) { ImageEntry::ImageEntry(const char *address) { myVOffset = ZLCachedMemoryAllocator::readUInt16(address); - const size_t len = ZLCachedMemoryAllocator::readUInt16(address + 2); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(address + 2); ZLUnicodeUtil::Ucs2Char *ucs2data = (ZLUnicodeUtil::Ucs2Char *)(address + 4); ZLUnicodeUtil::Ucs2String ucs2str(ucs2data, ucs2data + len); ZLUnicodeUtil::ucs2ToUtf8(myId, ucs2str); @@ -165,7 +165,7 @@ void ZLTextParagraph::Iterator::next() { switch (*myPointer) { case ZLTextParagraphEntry::TEXT_ENTRY: { - const size_t len = ZLCachedMemoryAllocator::readUInt32(myPointer + 2); + const std::size_t len = ZLCachedMemoryAllocator::readUInt32(myPointer + 2); myPointer += len * 2 + 6; break; } @@ -174,13 +174,13 @@ void ZLTextParagraph::Iterator::next() { break; case ZLTextParagraphEntry::HYPERLINK_CONTROL_ENTRY: { - const size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer + 4); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer + 4); myPointer += len * 2 + 6; break; } case ZLTextParagraphEntry::IMAGE_ENTRY: { - const size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer + 4); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer + 4); myPointer += len * 2 + 6; break; } @@ -192,7 +192,7 @@ void ZLTextParagraph::Iterator::next() { myPointer += 10 + 2 * (ZLTextStyleEntry::NUMBER_OF_LENGTHS + (ZLTextStyleEntry::NUMBER_OF_LENGTHS + 1) / 2); if (withFontFamily) { - const size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer); + const std::size_t len = ZLCachedMemoryAllocator::readUInt16(myPointer); myPointer += 2 + 2 * len; } break; @@ -205,13 +205,13 @@ void ZLTextParagraph::Iterator::next() { break; } if (*myPointer == 0) { - memcpy(&myPointer, myPointer + 1, sizeof(char*)); + std::memcpy(&myPointer, myPointer + 1, sizeof(char*)); } } } -size_t ZLTextParagraph::textDataLength() const { - size_t len = 0; +std::size_t ZLTextParagraph::textDataLength() const { + std::size_t len = 0; for (Iterator it = *this; !it.isEnd(); it.next()) { if (it.entryKind() == ZLTextParagraphEntry::TEXT_ENTRY) { len += ((ZLTextEntry&)*it.entry()).dataLength(); @@ -220,8 +220,8 @@ size_t ZLTextParagraph::textDataLength() const { return len; } -size_t ZLTextParagraph::characterNumber() const { - size_t len = 0; +std::size_t ZLTextParagraph::characterNumber() const { + std::size_t len = 0; for (Iterator it = *this; !it.isEnd(); it.next()) { switch (it.entryKind()) { case ZLTextParagraphEntry::TEXT_ENTRY: diff --git a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h index 92fc6ba46..2d838cc25 100644 --- a/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h +++ b/jni/NativeFormats/zlibrary/text/src/model/ZLTextParagraph.h @@ -122,7 +122,7 @@ public: //ZLTextEntry(const char *address); ~ZLTextEntry(); - size_t dataLength() const; + std::size_t dataLength() const; const char *data() const; private: @@ -168,8 +168,8 @@ public: private: char *myPointer; - size_t myIndex; - size_t myEndIndex; + std::size_t myIndex; + std::size_t myEndIndex; mutable shared_ptr myEntry; }; */ @@ -191,17 +191,17 @@ public: virtual ~ZLTextParagraph(); virtual Kind kind() const; - size_t entryNumber() const; + std::size_t entryNumber() const; - //size_t textDataLength() const; - //size_t characterNumber() const; + //std::size_t textDataLength() const; + //std::size_t characterNumber() const; private: void addEntry(char *address); private: char *myFirstEntryAddress; - size_t myEntryNumber; + std::size_t myEntryNumber; friend class Iterator; friend class ZLTextModel; @@ -245,7 +245,7 @@ inline bool ZLTextHyperlinkControlEntry::isHyperlink() const { return true; } inline ZLTextEntry::~ZLTextEntry() {} inline const char *ZLTextEntry::data() const { return myText.data(); } -inline size_t ZLTextEntry::dataLength() const { return myText.length(); } +inline std::size_t ZLTextEntry::dataLength() const { return myText.length(); } inline ImageEntry::~ImageEntry() {} inline const std::string &ImageEntry::id() const { return myId; } @@ -256,7 +256,7 @@ inline ResetBidiEntry::ResetBidiEntry() {} inline ZLTextParagraph::ZLTextParagraph() : myEntryNumber(0) {} inline ZLTextParagraph::~ZLTextParagraph() {} inline ZLTextParagraph::Kind ZLTextParagraph::kind() const { return TEXT_PARAGRAPH; } -inline size_t ZLTextParagraph::entryNumber() const { return myEntryNumber; } +inline std::size_t ZLTextParagraph::entryNumber() const { return myEntryNumber; } inline void ZLTextParagraph::addEntry(char *address) { if (myEntryNumber == 0) myFirstEntryAddress = address; ++myEntryNumber; } //inline ZLTextParagraph::Iterator::Iterator(const ZLTextParagraph ¶graph) : myPointer(paragraph.myFirstEntryAddress), myIndex(0), myEndIndex(paragraph.entryNumber()) {} diff --git a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp index 9ac740c0b..0cbea900c 100644 --- a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp +++ b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaFSDir.cpp @@ -70,7 +70,7 @@ void JavaFSDir::collectFiles(std::vector &names, bool includeSymlin std::string path = AndroidUtil::Method_ZLFile_getPath->callForCppString(file); env->DeleteLocalRef(file); - size_t index = path.rfind('/'); + std::size_t index = path.rfind('/'); if (index != std::string::npos) { path = path.substr(index + 1); } diff --git a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp index c0be1f16c..e538b1111 100644 --- a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp +++ b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.cpp @@ -80,7 +80,7 @@ void JavaInputStream::rewind(JNIEnv *env) { } -void JavaInputStream::ensureBufferCapacity(JNIEnv *env, size_t maxSize) { +void JavaInputStream::ensureBufferCapacity(JNIEnv *env, std::size_t maxSize) { if (myJavaBuffer != 0 && myJavaBufferSize >= maxSize) { return; } @@ -91,7 +91,7 @@ void JavaInputStream::ensureBufferCapacity(JNIEnv *env, size_t maxSize) { myJavaBufferSize = maxSize; } -size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) { +std::size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, std::size_t maxSize) { ensureBufferCapacity(env, maxSize); jint result = @@ -101,11 +101,11 @@ size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) return 0; } if (result > 0) { - size_t bytesRead = (size_t)result; + std::size_t bytesRead = (std::size_t)result; myOffset += bytesRead; jbyte *data = env->GetByteArrayElements(myJavaBuffer, 0); - memcpy(buffer, data, bytesRead); + std::memcpy(buffer, data, bytesRead); env->ReleaseByteArrayElements(myJavaBuffer, data, JNI_ABORT); return bytesRead; @@ -113,9 +113,9 @@ size_t JavaInputStream::readToBuffer(JNIEnv *env, char *buffer, size_t maxSize) return 0; } -size_t JavaInputStream::skip(JNIEnv *env, size_t offset) { - size_t result = - (size_t)AndroidUtil::Method_java_io_InputStream_skip->call(myJavaInputStream, (jlong)offset); +std::size_t JavaInputStream::skip(JNIEnv *env, std::size_t offset) { + std::size_t result = + (std::size_t)AndroidUtil::Method_java_io_InputStream_skip->call(myJavaInputStream, (jlong)offset); if (env->ExceptionCheck()) { env->ExceptionClear(); return 0; @@ -135,7 +135,7 @@ bool JavaInputStream::open() { return myJavaInputStream != 0; } -size_t JavaInputStream::read(char *buffer, size_t maxSize) { +std::size_t JavaInputStream::read(char *buffer, std::size_t maxSize) { JNIEnv *env = AndroidUtil::getEnv(); if (myNeedRepositionToStart) { rewind(env); @@ -151,11 +151,11 @@ size_t JavaInputStream::read(char *buffer, size_t maxSize) { void JavaInputStream::close() { } -size_t JavaInputStream::sizeOfOpened() { +std::size_t JavaInputStream::sizeOfOpened() { if (myJavaInputStream == 0 || myJavaFile == 0) { return 0; } - return (size_t)AndroidUtil::Method_ZLFile_size->call(myJavaFile); + return (std::size_t)AndroidUtil::Method_ZLFile_size->call(myJavaFile); } void JavaInputStream::seek(int offset, bool absoluteOffset) { @@ -172,6 +172,6 @@ void JavaInputStream::seek(int offset, bool absoluteOffset) { } } -size_t JavaInputStream::offset() const { +std::size_t JavaInputStream::offset() const { return myNeedRepositionToStart ? 0 : myOffset; } diff --git a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.h b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.h index 1859f84a3..91c3c403a 100644 --- a/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.h +++ b/jni/NativeFormats/zlibrary/ui/src/android/filesystem/JavaInputStream.h @@ -30,20 +30,20 @@ public: JavaInputStream(const std::string &name); ~JavaInputStream(); bool open(); - size_t read(char *buffer, size_t maxSize); + std::size_t read(char *buffer, std::size_t maxSize); void close(); void seek(int offset, bool absoluteOffset); - size_t offset() const; - size_t sizeOfOpened(); + std::size_t offset() const; + std::size_t sizeOfOpened(); private: void initStream(JNIEnv *env); void closeStream(JNIEnv *env); void rewind(JNIEnv *env); - void ensureBufferCapacity(JNIEnv *env, size_t maxSize); - size_t readToBuffer(JNIEnv *env, char *buffer, size_t maxSize); - size_t skip(JNIEnv *env, size_t offset); + void ensureBufferCapacity(JNIEnv *env, std::size_t maxSize); + std::size_t readToBuffer(JNIEnv *env, char *buffer, std::size_t maxSize); + std::size_t skip(JNIEnv *env, std::size_t offset); private: std::string myName; @@ -52,10 +52,10 @@ private: jobject myJavaFile; jobject myJavaInputStream; - size_t myOffset; + std::size_t myOffset; jbyteArray myJavaBuffer; - size_t myJavaBufferSize; + std::size_t myJavaBufferSize; }; #endif /* __JAVAINPUTSTREAM_H__ */