1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-03 09:49:19 +02:00

native code: synchronization with C++ version

This commit is contained in:
Nikolay Pultsin 2012-11-13 01:49:26 +04:00
parent 6fd4e1e98f
commit d93770c0f8
111 changed files with 804 additions and 697 deletions

View file

@ -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);

View file

@ -27,12 +27,12 @@
extern "C"
JNIEXPORT jobjectArray JNICALL Java_org_geometerplus_fbreader_formats_PluginCollection_nativePlugins(JNIEnv* env, jobject thiz) {
const std::vector<shared_ptr<FormatPlugin> > 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);

View file

@ -232,8 +232,8 @@ void BookReader::addImage(const std::string &id, shared_ptr<const ZLImage> 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;

View file

@ -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);

View file

@ -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<ZLLanguageDetector::LanguageInfo> 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<ZLLanguageDetector::LanguageInfo> info =
ZLLanguageDetector().findInfoForEncoding(encoding, buffer, size, -20000);

View file

@ -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 {

View file

@ -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<std::string> result = ZLStringUtil::split(utf8String, SPACE_DELIMETER);
//TODO split function can returns empty string, maybe fix it
std::vector<std::string> 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);
}

View file

@ -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();

View file

@ -17,6 +17,8 @@
* 02110-1301, USA.
*/
#include <ZLLogger.h>
#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<OleStream> stream, shared_ptr<OleStream> 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<FOPTE> &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;
@ -352,19 +361,24 @@ unsigned int DocFloatImageReader::readFOPTE(FOPTE &fopte, shared_ptr<OleStream>
unsigned int DocFloatImageReader::read1Byte(shared_ptr<OleStream> 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<OleStream> 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<OleStream> stream) {
char b[4];
stream->read(b, 4);
if (stream->read(b, 4) != 4) {
return 0;
}
return OleUtil::getU4Bytes(b, 0);
}

View file

@ -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:

View file

@ -53,9 +53,9 @@ bool DocPlugin::readMetaInfo(Book &book) const {
return false;
}
shared_ptr<ZLInputStream> stream = new DocCharStream(book.file(), 50000);
shared_ptr<ZLInputStream> 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);
}

View file

@ -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<DocReader> 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<DocReader> DocAnsiStream::createReader(char *buffer, size_t maxSize) {
shared_ptr<DocReader> 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<DocReader> DocUcs2Stream::createReader(char *buffer, std::size_t maxSize) {
return new DocUcs2Reader(buffer, maxSize);
}

View file

@ -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<DocReader> createReader(char *buffer, size_t maxSize) = 0;
virtual shared_ptr<DocReader> 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<DocReader> 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<DocReader> createReader(char *buffer, size_t maxSize);
shared_ptr<DocReader> createReader(char *buffer, std::size_t maxSize);
};
class DocUcs2Stream : public DocStream {
public:
DocUcs2Stream(const ZLFile& file, std::size_t maxSize);
~DocUcs2Stream();
private:
shared_ptr<DocReader> createReader(char *buffer, std::size_t maxSize);
};
#endif /* __DOCSTREAMS_H__ */

View file

@ -56,12 +56,12 @@ OleMainStream::FloatImageInfo::FloatImageInfo() : ShapeId(0) {
OleMainStream::OleMainStream(shared_ptr<OleStorage> storage, OleEntry oleEntry, shared_ptr<ZLInputStream> 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);
@ -84,6 +84,7 @@ 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
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<int> 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<std::string> 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<std::string> 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<unsigned int> 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<bool> 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<unsigned int> 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<unsigned int> 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<unsigned int> 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<unsigned int> 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<unsigned int> 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 &sectionInfo) {
void OleMainStream::getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo &sectionInfo) {
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<bool> &
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) {

View file

@ -150,7 +150,7 @@ public:
OleMainStream(shared_ptr<OleStorage> storage, OleEntry oleEntry, shared_ptr<ZLInputStream> 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 &sectionInfo);
static void getSectionInfo(const char *grpprlBuffer, std::size_t bytes, SectionInfo &sectionInfo);
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);

View file

@ -24,7 +24,7 @@
#include <cstring>
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<ZLInputStream> stream, size_t streamSize) {
bool OleStorage::init(shared_ptr<ZLInputStream> stream, std::size_t streamSize) {
clear();
myInputStream = stream;
@ -54,13 +54,13 @@ bool OleStorage::init(shared_ptr<ZLInputStream> 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;
}
return res;
result = BBD_BLOCK_SIZE + myEntries.at(myRootEntryIndex).blocks.at(sbdSectorNumber) * mySectorSize + sbdSectorMod * myShortSectorSize;
}
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;
}

View file

@ -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<ZLInputStream>, size_t streamSize);
bool init(shared_ptr<ZLInputStream>, std::size_t streamSize);
void clear();
const std::vector<OleEntry> &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<ZLInputStream> myInputStream;
unsigned int mySectorSize, myShortSectorSize;
size_t myStreamSize;
std::size_t myStreamSize;
std::vector<int> myDIFAT; //double-indirect file allocation table
std::vector<int> myBBD; //Big Block Depot
std::vector<int> mySBD; //Small Block Depot

View file

@ -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;
}

View file

@ -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;

View file

@ -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__ */

View file

@ -26,13 +26,13 @@
OleStreamReader::OleStreamReader() : myNextPieceNumber(0) {
}
bool OleStreamReader::readDocument(shared_ptr<ZLInputStream> inputStream) {
bool OleStreamReader::readDocument(shared_ptr<ZLInputStream> inputStream, bool doReadFormattingData) {
static const std::string WORD_DOCUMENT = "WordDocument";
shared_ptr<OleStorage> 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<ZLInputStream> 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;

View file

@ -28,19 +28,19 @@ class OleStreamReader {
public:
OleStreamReader();
bool readDocument(shared_ptr<ZLInputStream> stream);
bool readDocument(shared_ptr<ZLInputStream> 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__ */

View file

@ -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()) {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -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);
}

View file

@ -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;

View file

@ -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;

View file

@ -43,7 +43,7 @@ public:
struct HtmlTag {
std::string Name;
size_t Offset;
std::size_t Offset;
bool Start;
std::vector<HtmlAttribute> 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);

View file

@ -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<ZLInputStream> base, size_t maxSize) : myBase(base), myBuffer(0), mySize(maxSize) {
HtmlReaderStream::HtmlReaderStream(shared_ptr<ZLInputStream> 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;
}

View file

@ -26,23 +26,23 @@
class HtmlReaderStream : public ZLInputStream {
public:
HtmlReaderStream(shared_ptr<ZLInputStream> base, size_t maxSize);
HtmlReaderStream(shared_ptr<ZLInputStream> 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<ZLInputStream> myBase;
char *myBuffer;
size_t mySize;
size_t myOffset;
std::size_t mySize;
std::size_t myOffset;
};
#endif /* __HTMLREADERSTREAM_H__ */

View file

@ -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<int,NCXReader::NavPoint> &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) {
}

View file

@ -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<std::string> &externalDTDs() const;
private:

View file

@ -229,7 +229,7 @@ void OEBBookReader::generateTOC(const XHTMLReader &xhtmlReader) {
if (ncxReader.readDocument(ZLFile(myFilePrefix + myNCXTOCFileName))) {
const std::map<int,NCXReader::NavPoint> navigationMap = ncxReader.navigationMap();
if (!navigationMap.empty()) {
size_t level = 0;
std::size_t level = 0;
for (std::map<int,NCXReader::NavPoint>::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;

View file

@ -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:

View file

@ -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<std::string> &externalDTDs() const;

View file

@ -37,7 +37,7 @@ private:
private:
std::string myFilePrefix;
std::vector<std::string> myXHTMLFileNames;
size_t myIndex;
std::size_t myIndex;
};
#endif /* __OEBTEXTSTREAM_H__ */

View file

@ -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);

View file

@ -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();

View file

@ -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) {

View file

@ -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();

View file

@ -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);
}

View file

@ -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 {

View file

@ -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;
}

View file

@ -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__ */

View file

@ -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;

View file

@ -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;
}

View file

@ -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<ZLInputStream> myCurrentStream;
size_t myOffset;
std::size_t myOffset;
};
#endif /* __MERGEDSTREAM_H__ */

View file

@ -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;
}

View file

@ -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<ZLInputStream> myBase;
@ -46,7 +46,7 @@ private:
shared_ptr<ZLAsynchronousInputStream> myStream;
std::string myStreamBuffer;
std::string myDataBuffer;
size_t myOffset;
std::size_t myOffset;
};
#endif /* __XMLTEXTSTREAM_H__ */

View file

@ -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 {

View file

@ -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<std::string> &externalDTDs() const;

View file

@ -34,7 +34,7 @@ shared_ptr<Author> 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> 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;
}

View file

@ -217,9 +217,9 @@ bool Book::cloneTag(shared_ptr<Tag> from, shared_ptr<Tag> 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<Tag> from, shared_ptr<Tag> 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);

View file

@ -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();

View file

@ -53,7 +53,7 @@ shared_ptr<Tag> Tag::getTag(const std::string &name, shared_ptr<Tag> parent, int
shared_ptr<Tag> 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 {

View file

@ -69,7 +69,7 @@ public:
bool isAncestorOf(shared_ptr<Tag> 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<Tag> 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> 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__ */

View file

@ -215,7 +215,7 @@ jobject AndroidUtil::createJavaImage(JNIEnv *env, const ZLFileImage &image) {
std::vector<jint> 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<jint> &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<jbyte> &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;

View file

@ -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) {

View file

@ -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) {

View file

@ -57,7 +57,7 @@ public:
~ZLFile();
bool exists() const;
size_t size() const;
std::size_t size() const;
void forceArchiveType(ArchiveType type) const;

View file

@ -23,7 +23,7 @@
struct ZLFileInfo {
bool Exists;
bool IsDirectory;
size_t Size;
std::size_t Size;
ZLFileInfo();
};

View file

@ -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<ZLInputStream> myBaseStream;
size_t myBaseOffset;
std::size_t myBaseOffset;
};
inline ZLInputStream::ZLInputStream() {}

View file

@ -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();
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;

View file

@ -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;

View file

@ -36,9 +36,9 @@ public:
static shared_ptr<ZLZipEntryCache> cache(const std::string &containerName, ZLInputStream &containerStream);
private:
static const size_t ourStorageSize;
static const std::size_t ourStorageSize;
static shared_ptr<ZLZipEntryCache> *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<ZLInputStream> 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<ZLZDecompressor> 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<ZLInputStream> myBaseStream;
size_t myFileSize;
std::size_t myFileSize;
size_t myOffset;
std::size_t myOffset;
shared_ptr<ZLZDecompressor> myDecompressor;

View file

@ -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> *ZLZipEntryCache::ourStoredCaches =
new shared_ptr<ZLZipEntryCache>[ourStorageSize];
size_t ZLZipEntryCache::ourIndex = 0;
std::size_t ZLZipEntryCache::ourIndex = 0;
shared_ptr<ZLZipEntryCache> 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<ZLZipEntryCache> cache = ourStoredCaches[i];
if (!cache.isNull() && cache->myContainerName == containerName) {
return cache;

View file

@ -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;

View file

@ -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;
}

View file

@ -38,7 +38,7 @@ public:
typedef std::vector<Block> 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));
}

View file

@ -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<std::string> 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<ZLInputStream> 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__ */

View file

@ -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;

View file

@ -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;
}

View file

@ -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::LanguageInfo> ZLLanguageDetector::findInfo(const char *buffer, size_t length, int matchingCriterion) {
shared_ptr<ZLLanguageDetector::LanguageInfo> 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::LanguageInfo> ZLLanguageDetector::findInfo(const
return findInfoForEncoding(naive, buffer, length, matchingCriterion);
}
shared_ptr<ZLLanguageDetector::LanguageInfo> ZLLanguageDetector::findInfoForEncoding(const std::string &encoding, const char *buffer, size_t length, int matchingCriterion) {
shared_ptr<ZLLanguageDetector::LanguageInfo> ZLLanguageDetector::findInfoForEncoding(const std::string &encoding, const char *buffer, std::size_t length, int matchingCriterion) {
shared_ptr<LanguageInfo> info;
std::map<int,shared_ptr<ZLMapBasedStatistics> > statisticsMap;
for (SBVector::const_iterator it = myMatchers.begin(); it != myMatchers.end(); ++it) {

View file

@ -40,8 +40,8 @@ public:
ZLLanguageDetector();
~ZLLanguageDetector();
shared_ptr<LanguageInfo> findInfo(const char *buffer, size_t length, int matchingCriterion = 0);
shared_ptr<LanguageInfo> findInfoForEncoding(const std::string &encoding, const char *buffer, size_t length, int matchingCriterion = 0);
shared_ptr<LanguageInfo> findInfo(const char *buffer, std::size_t length, int matchingCriterion = 0);
shared_ptr<LanguageInfo> findInfoForEncoding(const std::string &encoding, const char *buffer, std::size_t length, int matchingCriterion = 0);
private:
typedef std::vector<shared_ptr<ZLStatisticsBasedMatcher> > SBVector;

View file

@ -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<ZLStatisticsItem> endA = candidate.end();
const shared_ptr<ZLStatisticsItem> 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;
}

View file

@ -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<ZLStatisticsItem> 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<std::pair<ZLCharSequence, size_t> > Vector;
typedef std::map<ZLCharSequence, size_t> Dictionary;
typedef std::vector<std::pair<ZLCharSequence, std::size_t> > Vector;
typedef std::map<ZLCharSequence, std::size_t> 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<ZLCharSequence, size_t> a, const std::pair<ZLCharSequence, size_t> b) {
bool operator() (const std::pair<ZLCharSequence, std::size_t> a, const std::pair<ZLCharSequence, std::size_t> 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();
}

View file

@ -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<ZLCharSequence, size_t> dictionary;
size_t locker = charSequenceSize;
std::map<ZLCharSequence, std::size_t> dictionary;
std::size_t locker = charSequenceSize;
for (const char *ptr = start; ptr < end;) {
if (myBreakSymbolsTable[(unsigned char)*(ptr)] == 1) {
locker = charSequenceSize;

View file

@ -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__

View file

@ -19,7 +19,7 @@
#include "ZLStatisticsItem.h"
ZLMapBasedStatisticsItem::ZLMapBasedStatisticsItem(const std::map<ZLCharSequence, size_t>::const_iterator it, size_t index) : ZLStatisticsItem(index),
ZLMapBasedStatisticsItem::ZLMapBasedStatisticsItem(const std::map<ZLCharSequence, std::size_t>::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() {

View file

@ -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<ZLCharSequence, size_t>::const_iterator it, size_t index);
ZLMapBasedStatisticsItem(const std::map<ZLCharSequence, std::size_t>::const_iterator it, std::size_t index);
ZLCharSequence sequence() const;
size_t frequency() const;
std::size_t frequency() const;
void next();
private:
std::map<ZLCharSequence, size_t>::const_iterator myIterator;
std::map<ZLCharSequence, std::size_t>::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;
}

View file

@ -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);

View file

@ -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);
}

View file

@ -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) {

View file

@ -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);
}

View file

@ -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;

View file

@ -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;
}
}

View file

@ -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();

View file

@ -64,7 +64,7 @@ void ZLStringUtil::appendNumber(std::string &str, unsigned int n) {
}
void ZLStringUtil::append(std::string &str, const std::vector<std::string> &text) {
size_t len = str.length();
std::size_t len = str.length();
for (std::vector<std::string>::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<std::string> &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<std::string> ZLStringUtil::split(const std::string &str, const std::string &delimiter) {
std::vector<std::string> 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;
}

View file

@ -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; }

View file

@ -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<ZLInputStream> 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;
}

View file

@ -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<std::string> &externalDTDs() const;
virtual void collectExternalEntities(std::map<std::string,std::string> &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();

Some files were not shown because too many files have changed in this diff Show more