diff options
author | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-04-27 19:27:46 +0200 |
---|---|---|
committer | Philipp Lohmann [pl] <Philipp.Lohmann@Sun.COM> | 2010-04-27 19:27:46 +0200 |
commit | ef8fba320644340ec9500ff633f4bcb73dd4dedb (patch) | |
tree | 4bc1dbdf236c63ce498c477a94838015ad8728ed /sdext | |
parent | f12056dce676eee306d34d06fb4bbbc452d9216c (diff) |
pdfextfix03: #i110871# pdf literal strings may contain nested parantheses
Diffstat (limited to 'sdext')
-rw-r--r-- | sdext/source/pdfimport/pdfparse/pdfparse.cxx | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx b/sdext/source/pdfimport/pdfparse/pdfparse.cxx index b8d0aaca6b74..b3ffa64427dd 100644 --- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx +++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx @@ -108,6 +108,40 @@ public: iteratorT m_aGlobalBegin; public: + struct pdf_string_parser + { + typedef nil_t result_t; + template <typename ScannerT> + std::ptrdiff_t + operator()(ScannerT const& scan, result_t& result) const + { + std::ptrdiff_t len = 0; + + int nBraceLevel = 0; + while( ! scan.at_end() ) + { + char c = *scan; + if( c == ')' ) + { + nBraceLevel--; + if( nBraceLevel < 0 ) + break; + } + else if( c == '(' ) + nBraceLevel++; + else if( c == '\\' ) // ignore escaped braces + { + ++len; + ++scan; + if( scan.at_end() ) + break; + } + ++len; + ++scan; + } + return scan.at_end() ? -1 : len; + } + }; template< typename ScannerT > struct definition @@ -135,7 +169,8 @@ public: //stringtype = ( confix_p("(",*anychar_p, ")") | // confix_p("<",*xdigit_p, ">") ) // [boost::bind(&PDFGrammar::pushString,pSelf, _1, _2)]; - stringtype = ( ( ch_p('(') >> *(str_p("\\)")|(anychar_p - ch_p(')'))) >> ch_p(')') ) | + + stringtype = ( ( ch_p('(') >> functor_parser<pdf_string_parser>() >> ch_p(')') ) | ( ch_p('<') >> *xdigit_p >> ch_p('>') ) ) [boost::bind(&PDFGrammar::pushString,pSelf, _1, _2)]; |