diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2018-02-20 16:03:20 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2018-02-21 08:09:46 +0100 |
commit | ba8a70365ef459c967cd8a71a6d48ca53dd341bd (patch) | |
tree | 397ae034cac2f06ea40ed550a7ce39cf4a42966e /sdext | |
parent | 0adb36835bcbe55bdf2717556a98e51f1873b19f (diff) |
New loplugin:nestedunnamed
Change-Id: Ifb434589ef08428ce609bc7a40b015d4df13224c
Reviewed-on: https://gerrit.libreoffice.org/50048
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sdext')
-rw-r--r-- | sdext/source/pdfimport/wrapper/wrapper.cxx | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index d9cce4a677fc..d79ffc3c99fb 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -203,59 +203,52 @@ public: void parseLine( const OString& rLine ); }; - -namespace +/** Unescapes line-ending characters in input string. These + characters are encoded as pairs of characters: '\\' 'n', resp. + '\\' 'r'. This function converts them back to '\n', resp. '\r'. + */ +OString lcl_unescapeLineFeeds(const OString& i_rStr) { - - /** Unescapes line-ending characters in input string. These - characters are encoded as pairs of characters: '\\' 'n', resp. - '\\' 'r'. This function converts them back to '\n', resp. '\r'. - */ - OString lcl_unescapeLineFeeds(const OString& i_rStr) + const size_t nOrigLen(sal::static_int_cast<size_t>(i_rStr.getLength())); + const sal_Char* const pOrig(i_rStr.getStr()); + std::unique_ptr<sal_Char[]> pBuffer(new sal_Char[nOrigLen + 1]); + + const sal_Char* pRead(pOrig); + sal_Char* pWrite(pBuffer.get()); + const sal_Char* pCur(pOrig); + while ((pCur = strchr(pCur, '\\')) != nullptr) { - const size_t nOrigLen(sal::static_int_cast<size_t>(i_rStr.getLength())); - const sal_Char* const pOrig(i_rStr.getStr()); - std::unique_ptr<sal_Char[]> pBuffer(new sal_Char[nOrigLen + 1]); - - const sal_Char* pRead(pOrig); - sal_Char* pWrite(pBuffer.get()); - const sal_Char* pCur(pOrig); - while ((pCur = strchr(pCur, '\\')) != nullptr) + const sal_Char cNext(pCur[1]); + if (cNext == 'n' || cNext == 'r' || cNext == '\\') { - const sal_Char cNext(pCur[1]); - if (cNext == 'n' || cNext == 'r' || cNext == '\\') - { - const size_t nLen(pCur - pRead); - strncpy(pWrite, pRead, nLen); - pWrite += nLen; - *pWrite = cNext == 'n' ? '\n' : (cNext == 'r' ? '\r' : '\\'); - ++pWrite; - pCur = pRead = pCur + 2; - } - else - { - // Just continue on the next character. The current - // block will be copied the next time it goes through the - // 'if' branch. - ++pCur; - } - } - // maybe there are some data to copy yet - if (sal::static_int_cast<size_t>(pRead - pOrig) < nOrigLen) - { - const size_t nLen(nOrigLen - (pRead - pOrig)); + const size_t nLen(pCur - pRead); strncpy(pWrite, pRead, nLen); pWrite += nLen; + *pWrite = cNext == 'n' ? '\n' : (cNext == 'r' ? '\r' : '\\'); + ++pWrite; + pCur = pRead = pCur + 2; } - *pWrite = '\0'; - - OString aResult(pBuffer.get()); - return aResult; + else + { + // Just continue on the next character. The current + // block will be copied the next time it goes through the + // 'if' branch. + ++pCur; + } + } + // maybe there are some data to copy yet + if (sal::static_int_cast<size_t>(pRead - pOrig) < nOrigLen) + { + const size_t nLen(nOrigLen - (pRead - pOrig)); + strncpy(pWrite, pRead, nLen); + pWrite += nLen; } + *pWrite = '\0'; + OString aResult(pBuffer.get()); + return aResult; } - OString Parser::readNextToken() { OSL_PRECOND(m_nCharIndex!=-1,"insufficient input"); |