|
|
@ -12,6 +12,8 @@ |
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
* You should have received a copy of the GNU General Public License |
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <QtGlobal> |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include <iostream> |
|
|
|
#include <iostream> |
|
|
|
#include <vector> |
|
|
|
#include <vector> |
|
|
@ -57,8 +59,8 @@ void Parser::_retrieveAllPages(Object * objectWithKids) |
|
|
|
unsigned int startOfKids = objectContent.find("/Kids"); |
|
|
|
unsigned int startOfKids = objectContent.find("/Kids"); |
|
|
|
unsigned int endOfKids = objectContent.find("]", startOfKids); |
|
|
|
unsigned int endOfKids = objectContent.find("]", startOfKids); |
|
|
|
if( |
|
|
|
if( |
|
|
|
(startOfKids == -1) && |
|
|
|
((int)startOfKids == -1) && |
|
|
|
(objectContent.find("/Page") != -1) |
|
|
|
((int)objectContent.find("/Page") != -1) |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int numberOfPages = _document->_pages.size() + 1; |
|
|
|
unsigned int numberOfPages = _document->_pages.size() + 1; |
|
|
@ -77,11 +79,11 @@ void Parser::_retrieveAllPages(Object * objectWithKids) |
|
|
|
|
|
|
|
|
|
|
|
void Parser::_createDocument(const char * docName) |
|
|
|
void Parser::_createDocument(const char * docName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
Q_UNUSED(docName); |
|
|
|
_document->_root = _root; |
|
|
|
_document->_root = _root; |
|
|
|
Object * objectWithPages = 0; |
|
|
|
|
|
|
|
std::string & rootContent = _root->getObjectContent(); |
|
|
|
std::string & rootContent = _root->getObjectContent(); |
|
|
|
unsigned int startOfPages = rootContent.find("/Pages"); |
|
|
|
unsigned int startOfPages = rootContent.find("/Pages"); |
|
|
|
if(startOfPages == -1) |
|
|
|
if((int)startOfPages == -1) |
|
|
|
throw Exception("Some document is wrong"); |
|
|
|
throw Exception("Some document is wrong"); |
|
|
|
unsigned int endOfPages = rootContent.find("R", startOfPages); |
|
|
|
unsigned int endOfPages = rootContent.find("R", startOfPages); |
|
|
|
std::vector<Object *> objectWithKids = _root->getChildrenByBounds(startOfPages, endOfPages); |
|
|
|
std::vector<Object *> objectWithKids = _root->getChildrenByBounds(startOfPages, endOfPages); |
|
|
@ -187,19 +189,19 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get |
|
|
|
static std::map<unsigned int, std::vector<unsigned int> > searchResult; |
|
|
|
static std::map<unsigned int, std::vector<unsigned int> > searchResult; |
|
|
|
searchResult.clear(); |
|
|
|
searchResult.clear(); |
|
|
|
unsigned int streamStart = objectContent.find("stream"); |
|
|
|
unsigned int streamStart = objectContent.find("stream"); |
|
|
|
if(streamStart == -1) |
|
|
|
if((int)streamStart == -1) |
|
|
|
streamStart = objectContent.size(); |
|
|
|
streamStart = objectContent.size(); |
|
|
|
while(startOfNextSearch < streamStart) |
|
|
|
while(startOfNextSearch < streamStart) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//try to find reference. reference example is 15 0 R
|
|
|
|
//try to find reference. reference example is 15 0 R
|
|
|
|
startOfNextSearch = objectContent.find(" R", startOfNextSearch); |
|
|
|
startOfNextSearch = objectContent.find(" R", startOfNextSearch); |
|
|
|
currentPosition = startOfNextSearch; |
|
|
|
currentPosition = startOfNextSearch; |
|
|
|
if(currentPosition != -1) |
|
|
|
if((int)currentPosition != -1) |
|
|
|
{
|
|
|
|
{
|
|
|
|
//check that next character of " R" is WHITESPACE.
|
|
|
|
//check that next character of " R" is WHITESPACE.
|
|
|
|
|
|
|
|
|
|
|
|
if((WHITESPACES.find(objectContent[currentPosition + 2]) == -1) && |
|
|
|
if(((int)WHITESPACES.find(objectContent[currentPosition + 2]) == -1) && |
|
|
|
(DELIMETERS.find(objectContent[currentPosition + 2]) == -1) |
|
|
|
((int)DELIMETERS.find(objectContent[currentPosition + 2]) == -1) |
|
|
|
) |
|
|
|
) |
|
|
|
{ |
|
|
|
{ |
|
|
|
//this is not reference. this is something looks like "0 0 0 RG"
|
|
|
|
//this is not reference. this is something looks like "0 0 0 RG"
|
|
|
@ -257,7 +259,7 @@ const std::map<unsigned int, Object::ReferencePositionsInContent> & Parser::_get |
|
|
|
unsigned int Parser::_skipNumber(const std::string & str, unsigned int currentPosition) |
|
|
|
unsigned int Parser::_skipNumber(const std::string & str, unsigned int currentPosition) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int numberSearchCounter = currentPosition;
|
|
|
|
unsigned int numberSearchCounter = currentPosition;
|
|
|
|
while((NUMBERS.find(str[numberSearchCounter]) != -1) && --numberSearchCounter) |
|
|
|
while(((int)NUMBERS.find(str[numberSearchCounter]) != -1) && --numberSearchCounter) |
|
|
|
{} |
|
|
|
{} |
|
|
|
|
|
|
|
|
|
|
|
return numberSearchCounter; |
|
|
|
return numberSearchCounter; |
|
|
@ -281,17 +283,16 @@ void Parser::_readXRefAndCreateObjects() |
|
|
|
//now we are reading the xref
|
|
|
|
//now we are reading the xref
|
|
|
|
while(1) |
|
|
|
while(1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int firstObjectNumber = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
unsigned int objectCount = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
unsigned int objectCount = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
for(unsigned int i(0); i < objectCount; i++) |
|
|
|
for(unsigned int i(0); i < objectCount; i++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned long first; |
|
|
|
unsigned long first; |
|
|
|
unsigned long second; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(_countTokens(currentPostion, _getEndOfLineFromContent(currentPostion)) == 3) |
|
|
|
if(_countTokens(currentPostion, _getEndOfLineFromContent(currentPostion)) == 3) |
|
|
|
{ |
|
|
|
{ |
|
|
|
first = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
first = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
second = Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
Utils::stringToInt(_getNextToken(currentPostion)); |
|
|
|
const string & use = _getNextToken(currentPostion); |
|
|
|
const string & use = _getNextToken(currentPostion); |
|
|
|
if(!use.compare("n")) |
|
|
|
if(!use.compare("n")) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -367,10 +368,10 @@ const std::pair<unsigned int, unsigned int> & Parser::_getLineBounds(const std:: |
|
|
|
{ |
|
|
|
{ |
|
|
|
static std::pair<unsigned int, unsigned int> bounds; |
|
|
|
static std::pair<unsigned int, unsigned int> bounds; |
|
|
|
bounds.first = str.rfind('\n', fromPosition); |
|
|
|
bounds.first = str.rfind('\n', fromPosition); |
|
|
|
if(bounds.first == -1) |
|
|
|
if((int)bounds.first == -1) |
|
|
|
bounds.first = 0; |
|
|
|
bounds.first = 0; |
|
|
|
bounds.second = str.find('\n', fromPosition); |
|
|
|
bounds.second = str.find('\n', fromPosition); |
|
|
|
if(bounds.second == -1) |
|
|
|
if((int)bounds.second == -1) |
|
|
|
bounds.second = str.size();
|
|
|
|
bounds.second = str.size();
|
|
|
|
return bounds; |
|
|
|
return bounds; |
|
|
|
} |
|
|
|
} |
|
|
@ -405,7 +406,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun |
|
|
|
while (position < rightBount) |
|
|
|
while (position < rightBount) |
|
|
|
{ |
|
|
|
{ |
|
|
|
position = _fileContent.find_first_of(WHITESPACES, position); |
|
|
|
position = _fileContent.find_first_of(WHITESPACES, position); |
|
|
|
if (position != -1) |
|
|
|
if ((int)position != -1) |
|
|
|
++tokensCount; |
|
|
|
++tokensCount; |
|
|
|
//start search from next symbol
|
|
|
|
//start search from next symbol
|
|
|
|
++position; |
|
|
|
++position; |
|
|
@ -416,7 +417,7 @@ unsigned int Parser::_countTokens(unsigned int leftBound, unsigned int rightBoun |
|
|
|
unsigned int Parser::_skipWhiteSpaces(const std::string & str, unsigned int fromPosition) |
|
|
|
unsigned int Parser::_skipWhiteSpaces(const std::string & str, unsigned int fromPosition) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int position = fromPosition; |
|
|
|
unsigned int position = fromPosition; |
|
|
|
if(WHITESPACES.find(str[0]) != -1) |
|
|
|
if((int)WHITESPACES.find(str[0]) != -1) |
|
|
|
position = str.find_first_not_of(WHITESPACES, position); |
|
|
|
position = str.find_first_not_of(WHITESPACES, position); |
|
|
|
return position; |
|
|
|
return position; |
|
|
|
} |
|
|
|
} |
|
|
@ -424,7 +425,7 @@ unsigned int Parser::_skipWhiteSpaces(const std::string & str, unsigned int from |
|
|
|
unsigned int Parser::_skipWhiteSpacesFromContent(unsigned int fromPosition) |
|
|
|
unsigned int Parser::_skipWhiteSpacesFromContent(unsigned int fromPosition) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int position = fromPosition; |
|
|
|
unsigned int position = fromPosition; |
|
|
|
if(WHITESPACES.find(_fileContent[position]) != -1) |
|
|
|
if((int)WHITESPACES.find(_fileContent[position]) != -1) |
|
|
|
position = _fileContent.find_first_not_of(WHITESPACES, position);// + 1;
|
|
|
|
position = _fileContent.find_first_not_of(WHITESPACES, position);// + 1;
|
|
|
|
|
|
|
|
|
|
|
|
return position; |
|
|
|
return position; |
|
|
@ -453,7 +454,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig |
|
|
|
static std::string objectContent; |
|
|
|
static std::string objectContent; |
|
|
|
|
|
|
|
|
|
|
|
size_t contentStart = _fileContent.find_first_not_of(Parser::WHITESPACES,currentPosition); |
|
|
|
size_t contentStart = _fileContent.find_first_not_of(Parser::WHITESPACES,currentPosition); |
|
|
|
if( contentStart == -1 ) |
|
|
|
if((int) contentStart == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::stringstream strOut; |
|
|
|
std::stringstream strOut; |
|
|
|
strOut<<"Wrong object "<< objectNumber<< "in PDF, cannot find content for it\n"; |
|
|
|
strOut<<"Wrong object "<< objectNumber<< "in PDF, cannot find content for it\n"; |
|
|
@ -461,13 +462,13 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig |
|
|
|
} |
|
|
|
} |
|
|
|
currentPosition = contentStart; |
|
|
|
currentPosition = contentStart; |
|
|
|
unsigned int endOfContent = _fileContent.find("endobj", contentStart); |
|
|
|
unsigned int endOfContent = _fileContent.find("endobj", contentStart); |
|
|
|
if( endOfContent == -1 ) |
|
|
|
if((int) endOfContent == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
stringstream errorMessage("Corrupted PDF file, obj does not have matching endobj"); |
|
|
|
stringstream errorMessage("Corrupted PDF file, obj does not have matching endobj"); |
|
|
|
throw Exception(errorMessage); |
|
|
|
throw Exception(errorMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
unsigned int endOfStream = _fileContent.find("endstream", currentPosition); |
|
|
|
unsigned int endOfStream = _fileContent.find("endstream", currentPosition); |
|
|
|
if((endOfStream != -1) && (endOfStream < endOfContent)) |
|
|
|
if(((int)endOfStream != -1) && (endOfStream < endOfContent)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string stream("stream"); |
|
|
|
std::string stream("stream"); |
|
|
|
unsigned int beginOfStream = _fileContent.find(stream, currentPosition) + stream.size(); |
|
|
|
unsigned int beginOfStream = _fileContent.find(stream, currentPosition) + stream.size(); |
|
|
@ -484,7 +485,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig |
|
|
|
// try to use Length field to determine end of stream.
|
|
|
|
// try to use Length field to determine end of stream.
|
|
|
|
std::string lengthToken = "/Length"; |
|
|
|
std::string lengthToken = "/Length"; |
|
|
|
size_t lengthBegin = Parser::findTokenName(_fileContent,lengthToken,contentStart); |
|
|
|
size_t lengthBegin = Parser::findTokenName(_fileContent,lengthToken,contentStart); |
|
|
|
if ( lengthBegin != -1 ) |
|
|
|
if ((int) lengthBegin != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string lengthStr; |
|
|
|
std::string lengthStr; |
|
|
|
size_t lenPos = lengthBegin + lengthToken.size(); |
|
|
|
size_t lenPos = lengthBegin + lengthToken.size(); |
|
|
@ -512,7 +513,7 @@ const std::string & Parser::_getObjectContent(unsigned int objectPosition, unsig |
|
|
|
strin>>streamEnd; |
|
|
|
strin>>streamEnd; |
|
|
|
streamEnd += beginOfStream; |
|
|
|
streamEnd += beginOfStream; |
|
|
|
unsigned int streamEndBegin = _fileContent.find("endstream",streamEnd); |
|
|
|
unsigned int streamEndBegin = _fileContent.find("endstream",streamEnd); |
|
|
|
if( streamEndBegin != -1 ) |
|
|
|
if((int) streamEndBegin != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
endOfStream = streamEndBegin; |
|
|
|
endOfStream = streamEndBegin; |
|
|
|
} |
|
|
|
} |
|
|
@ -537,18 +538,18 @@ unsigned int Parser::_readTrailerAndReturnRoot() |
|
|
|
unsigned int startOfTrailer = Parser::findToken(_fileContent,"trailer", _getStartOfXrefWithRoot()); |
|
|
|
unsigned int startOfTrailer = Parser::findToken(_fileContent,"trailer", _getStartOfXrefWithRoot()); |
|
|
|
std::string rootStr("/Root"); |
|
|
|
std::string rootStr("/Root"); |
|
|
|
unsigned int startOfRoot = Parser::findToken(_fileContent,rootStr.data(), startOfTrailer); |
|
|
|
unsigned int startOfRoot = Parser::findToken(_fileContent,rootStr.data(), startOfTrailer); |
|
|
|
if( startOfRoot == -1) |
|
|
|
if((int) startOfRoot == -1) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw Exception("Cannot find Root object !"); |
|
|
|
throw Exception("Cannot find Root object !"); |
|
|
|
} |
|
|
|
} |
|
|
|
std::string encryptStr("/Encrypt"); |
|
|
|
std::string encryptStr("/Encrypt"); |
|
|
|
if( Parser::findToken(_fileContent,encryptStr,startOfTrailer) != -1 ) |
|
|
|
if((int) Parser::findToken(_fileContent,encryptStr,startOfTrailer) != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw Exception("Encrypted PDF is not supported!"); |
|
|
|
throw Exception("Encrypted PDF is not supported!"); |
|
|
|
} |
|
|
|
} |
|
|
|
startOfRoot += rootStr.size()+1; //"/Root + ' '
|
|
|
|
startOfRoot += rootStr.size()+1; //"/Root + ' '
|
|
|
|
unsigned int endOfRoot = startOfRoot; |
|
|
|
unsigned int endOfRoot = startOfRoot; |
|
|
|
while(NUMBERS.find(_fileContent[endOfRoot++]) != -1) |
|
|
|
while((int)NUMBERS.find(_fileContent[endOfRoot++]) != -1) |
|
|
|
{} |
|
|
|
{} |
|
|
|
--endOfRoot; |
|
|
|
--endOfRoot; |
|
|
|
return Utils::stringToInt(_fileContent.substr(startOfRoot, endOfRoot - startOfRoot));
|
|
|
|
return Utils::stringToInt(_fileContent.substr(startOfRoot, endOfRoot - startOfRoot));
|
|
|
@ -557,21 +558,21 @@ unsigned int Parser::_readTrailerAndReturnRoot() |
|
|
|
unsigned int Parser::_readTrailerAndRterievePrev(const unsigned int startPositionForSearch, unsigned int & previosXref) |
|
|
|
unsigned int Parser::_readTrailerAndRterievePrev(const unsigned int startPositionForSearch, unsigned int & previosXref) |
|
|
|
{ |
|
|
|
{ |
|
|
|
unsigned int startOfTrailer = Parser::findToken(_fileContent,"trailer", startPositionForSearch); |
|
|
|
unsigned int startOfTrailer = Parser::findToken(_fileContent,"trailer", startPositionForSearch); |
|
|
|
if( startOfTrailer == -1 ) |
|
|
|
if((int) startOfTrailer == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
throw Exception("Cannot find trailer!"); |
|
|
|
throw Exception("Cannot find trailer!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
unsigned int startOfPrev = _fileContent.find("Prev ", startOfTrailer); |
|
|
|
unsigned int startOfPrev = _fileContent.find("Prev ", startOfTrailer); |
|
|
|
unsigned int startxref = _fileContent.find("startxref", startOfTrailer); |
|
|
|
unsigned int startxref = _fileContent.find("startxref", startOfTrailer); |
|
|
|
if(startOfPrev == -1 || (startOfPrev > startxref)) |
|
|
|
if((int)startOfPrev == -1 || (startOfPrev > startxref)) |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
//"Prev "s length = 5
|
|
|
|
//"Prev "s length = 5
|
|
|
|
else |
|
|
|
else |
|
|
|
startOfPrev += 5; |
|
|
|
startOfPrev += 5; |
|
|
|
|
|
|
|
|
|
|
|
unsigned int endOfPrev = startOfPrev; |
|
|
|
unsigned int endOfPrev = startOfPrev; |
|
|
|
while(NUMBERS.find(_fileContent[endOfPrev++]) != -1) |
|
|
|
while((int)NUMBERS.find(_fileContent[endOfPrev++]) != -1) |
|
|
|
{} |
|
|
|
{} |
|
|
|
--endOfPrev; |
|
|
|
--endOfPrev; |
|
|
|
previosXref = Utils::stringToInt(_fileContent.substr(startOfPrev, endOfPrev - startOfPrev));
|
|
|
|
previosXref = Utils::stringToInt(_fileContent.substr(startOfPrev, endOfPrev - startOfPrev));
|
|
|
@ -589,13 +590,13 @@ std::string Parser::getNextToken(const std::string &str, unsigned int &position |
|
|
|
} |
|
|
|
} |
|
|
|
//skip first spaces
|
|
|
|
//skip first spaces
|
|
|
|
size_t beg_pos = str.find_first_not_of(Parser::WHITESPACES,position); |
|
|
|
size_t beg_pos = str.find_first_not_of(Parser::WHITESPACES,position); |
|
|
|
if ( beg_pos == -1 ) |
|
|
|
if ((int) beg_pos == -1 ) |
|
|
|
{
|
|
|
|
{
|
|
|
|
// it is empty string!
|
|
|
|
// it is empty string!
|
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
size_t end_pos = str.find_first_of(Parser::WHITESPACES_AND_DELIMETERS,beg_pos); |
|
|
|
size_t end_pos = str.find_first_of(Parser::WHITESPACES_AND_DELIMETERS,beg_pos); |
|
|
|
if ( end_pos == -1 ) |
|
|
|
if ((int) end_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
end_pos = str.size(); |
|
|
|
end_pos = str.size(); |
|
|
|
} |
|
|
|
} |
|
|
@ -623,7 +624,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP |
|
|
|
} |
|
|
|
} |
|
|
|
//skip first spaces
|
|
|
|
//skip first spaces
|
|
|
|
size_t beg_pos = str.find_first_not_of(Parser::WHITESPACES,nextPosition); |
|
|
|
size_t beg_pos = str.find_first_not_of(Parser::WHITESPACES,nextPosition); |
|
|
|
if ( beg_pos == -1 ) |
|
|
|
if ((int) beg_pos == -1 ) |
|
|
|
{
|
|
|
|
{
|
|
|
|
// it is empty string!
|
|
|
|
// it is empty string!
|
|
|
|
return false; |
|
|
|
return false; |
|
|
@ -634,7 +635,7 @@ bool Parser::getNextWord(std::string &out, const std::string &str, size_t &nextP |
|
|
|
} |
|
|
|
} |
|
|
|
size_t end_pos = str.find_first_of(Parser::WHITESPACES,beg_pos); |
|
|
|
size_t end_pos = str.find_first_of(Parser::WHITESPACES,beg_pos); |
|
|
|
|
|
|
|
|
|
|
|
if ( end_pos == -1 ) |
|
|
|
if ((int) end_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
end_pos = str.size(); |
|
|
|
end_pos = str.size(); |
|
|
|
} |
|
|
|
} |
|
|
@ -656,8 +657,8 @@ void Parser::trim(std::string &str) |
|
|
|
{ |
|
|
|
{ |
|
|
|
std::string::size_type pos1 = str.find_first_not_of(WHITESPACES); |
|
|
|
std::string::size_type pos1 = str.find_first_not_of(WHITESPACES); |
|
|
|
std::string::size_type pos2 = str.find_last_not_of(WHITESPACES); |
|
|
|
std::string::size_type pos2 = str.find_last_not_of(WHITESPACES); |
|
|
|
str = str.substr(pos1 == -1 ? 0 : pos1, |
|
|
|
str = str.substr((int)pos1 == -1 ? 0 : pos1, |
|
|
|
pos2 == -1 ? str.length() - 1 : pos2 - pos1 + 1); |
|
|
|
(int)pos2 == -1 ? str.length() - 1 : pos2 - pos1 + 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Method tries to find the PDF token from the content
|
|
|
|
// Method tries to find the PDF token from the content
|
|
|
@ -665,7 +666,7 @@ void Parser::trim(std::string &str) |
|
|
|
std::string Parser::findTokenStr(const std::string &content, const std::string &pattern, size_t start, size_t &foundStart, size_t &foundEnd) |
|
|
|
std::string Parser::findTokenStr(const std::string &content, const std::string &pattern, size_t start, size_t &foundStart, size_t &foundEnd) |
|
|
|
{ |
|
|
|
{ |
|
|
|
size_t cur_pos = Parser::findToken(content,pattern,start); |
|
|
|
size_t cur_pos = Parser::findToken(content,pattern,start); |
|
|
|
if( cur_pos == -1 ) |
|
|
|
if((int) cur_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
@ -673,7 +674,7 @@ std::string Parser::findTokenStr(const std::string &content, const std::string & |
|
|
|
cur_pos += pattern.size(); |
|
|
|
cur_pos += pattern.size(); |
|
|
|
// then lets parse the content of remaining part
|
|
|
|
// then lets parse the content of remaining part
|
|
|
|
size_t end_pos = content.find_first_of(Parser::DELIMETERS,cur_pos); |
|
|
|
size_t end_pos = content.find_first_of(Parser::DELIMETERS,cur_pos); |
|
|
|
if( end_pos == -1 ) |
|
|
|
if((int) end_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
end_pos = content.size(); |
|
|
|
end_pos = content.size(); |
|
|
|
} |
|
|
|
} |
|
|
@ -697,7 +698,7 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword, |
|
|
|
while( 1 ) |
|
|
|
while( 1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cur_pos = content.find(keyword,cur_pos); |
|
|
|
cur_pos = content.find(keyword,cur_pos); |
|
|
|
if( cur_pos == -1 ) |
|
|
|
if((int) cur_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -705,8 +706,8 @@ size_t Parser::findToken(const std::string &content, const std::string &keyword, |
|
|
|
cur_pos += keyword.size(); |
|
|
|
cur_pos += keyword.size(); |
|
|
|
if( cur_pos < content.size() ) |
|
|
|
if( cur_pos < content.size() ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( Parser::WHITESPACES.find(content[cur_pos]) != -1 || |
|
|
|
if((int) Parser::WHITESPACES.find(content[cur_pos]) != -1 || |
|
|
|
Parser::DELIMETERS.find(content[cur_pos]) != -1 ) |
|
|
|
(int)Parser::DELIMETERS.find(content[cur_pos]) != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foundStart = savedPos; |
|
|
|
foundStart = savedPos; |
|
|
|
break; |
|
|
|
break; |
|
|
@ -736,10 +737,10 @@ bool Parser::tokenIsAName(const std::string &content, size_t start ) |
|
|
|
size_t foundNonWhite = content.find_first_not_of(Parser::WHITESPACES,start); |
|
|
|
size_t foundNonWhite = content.find_first_not_of(Parser::WHITESPACES,start); |
|
|
|
size_t foundDelim = content.find_first_of(Parser::DELIMETERS,start); |
|
|
|
size_t foundDelim = content.find_first_of(Parser::DELIMETERS,start); |
|
|
|
|
|
|
|
|
|
|
|
if( foundNonWhite != -1 && |
|
|
|
if( (int)foundNonWhite != -1 && |
|
|
|
foundDelim != -1 ) |
|
|
|
(int)foundDelim != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( (foundNonWhite < foundDelim ) || ( openBraces.find(content[foundDelim]) != -1) ) |
|
|
|
if( (foundNonWhite < foundDelim ) || ( (int)openBraces.find(content[foundDelim]) != -1) ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( found ) |
|
|
|
if( found ) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -784,7 +785,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw |
|
|
|
while( 1 ) |
|
|
|
while( 1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
cur_pos = content.find(keyword,cur_pos); |
|
|
|
cur_pos = content.find(keyword,cur_pos); |
|
|
|
if( cur_pos == -1 ) |
|
|
|
if((int) cur_pos == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -792,7 +793,7 @@ size_t Parser::findTokenName(const std::string &content, const std::string &keyw |
|
|
|
cur_pos += keyword.size(); |
|
|
|
cur_pos += keyword.size(); |
|
|
|
if( cur_pos < content.size() ) |
|
|
|
if( cur_pos < content.size() ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( Parser::WHITESPACES_AND_DELIMETERS.find(content[cur_pos]) != -1 ) |
|
|
|
if((int) Parser::WHITESPACES_AND_DELIMETERS.find(content[cur_pos]) != -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( tokenIsAName(content,cur_pos ) ) |
|
|
|
if( tokenIsAName(content,cur_pos ) ) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -832,7 +833,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned |
|
|
|
unsigned int foundOpenBrace = content.find("[",curPos); |
|
|
|
unsigned int foundOpenBrace = content.find("[",curPos); |
|
|
|
unsigned int foundOpenDict = content.find("<",curPos); |
|
|
|
unsigned int foundOpenDict = content.find("<",curPos); |
|
|
|
|
|
|
|
|
|
|
|
if( foundDelimeter == -1 && foundOpenBrace == -1 && foundOpenDict == -1 ) |
|
|
|
if((int) foundDelimeter == -1 && (int)foundOpenBrace == -1 && (int)foundOpenDict == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if( !delimStack.empty() ) |
|
|
|
if( !delimStack.empty() ) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -882,7 +883,7 @@ unsigned int Parser::findEndOfElementContent(const std::string &content,unsigned |
|
|
|
if( delimStack.empty() ) |
|
|
|
if( delimStack.empty() ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foundEnd = content.find_first_of(delimeter,curPos); |
|
|
|
foundEnd = content.find_first_of(delimeter,curPos); |
|
|
|
if( foundEnd == -1 ) |
|
|
|
if((int) foundEnd == -1 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foundEnd = curPos; |
|
|
|
foundEnd = curPos; |
|
|
|
} |
|
|
|
} |
|
|
|