From df0dea0bf055fce59beedadbc8d20a2681c96bd6 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Sun, 27 Apr 2014 21:31:10 +0200 Subject: writerfilter: fix indentation in rtftokenizer Change-Id: Ia9c609eabc39c3933479eae3d5c4499f11c58528 --- writerfilter/source/rtftok/rtftokenizer.cxx | 197 ++++++++++++++-------------- writerfilter/source/rtftok/rtftokenizer.hxx | 82 ++++++------ 2 files changed, 142 insertions(+), 137 deletions(-) diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx index 2ddc71462483..a8587e7c21af 100644 --- a/writerfilter/source/rtftok/rtftokenizer.cxx +++ b/writerfilter/source/rtftok/rtftokenizer.cxx @@ -20,8 +20,10 @@ using namespace com::sun::star; -namespace writerfilter { -namespace rtftok { +namespace writerfilter +{ +namespace rtftok +{ std::vector RTFTokenizer::m_aRTFControlWords; bool RTFTokenizer::m_bControlWordsSorted; @@ -30,12 +32,12 @@ bool RTFTokenizer::m_bMathControlWordsSorted; RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, uno::Reference const& xStatusIndicator) : m_rImport(rImport), - m_pInStream(pInStream), - m_xStatusIndicator(xStatusIndicator), - m_nGroup(0), - m_nLineNumber(0), - m_nLineStartPos(0), - m_nGroupStart(0) + m_pInStream(pInStream), + m_xStatusIndicator(xStatusIndicator), + m_nGroup(0), + m_nLineNumber(0), + m_nLineStartPos(0), + m_nGroupStart(0) { if (!RTFTokenizer::m_bControlWordsSorted) { @@ -62,7 +64,7 @@ SvStream& RTFTokenizer::Strm() int RTFTokenizer::resolveParse() { - SAL_INFO( "writerfilter", OSL_THIS_FUNC ); + SAL_INFO("writerfilter", OSL_THIS_FUNC); char ch; int ret; // for hex chars @@ -83,7 +85,7 @@ int RTFTokenizer::resolveParse() m_xStatusIndicator->setValue(nLastPos = nCurrentPos); } - while ((Strm().ReadChar( ch ), !Strm().IsEof())) + while ((Strm().ReadChar(ch), !Strm().IsEof())) { //SAL_INFO("writerfilter", OSL_THIS_FUNC << ": parsing character '" << ch << "'"); @@ -103,63 +105,63 @@ int RTFTokenizer::resolveParse() { switch (ch) { - case '{': - m_nGroupStart = Strm().Tell() - 1; - ret = m_rImport.pushState(); - if (ret) - return ret; - break; - case '}': - ret = m_rImport.popState(); - if (ret) - return ret; - if (m_nGroup == 0) - { - if (m_rImport.isSubstream()) - m_rImport.finishSubstream(); - return 0; - } - break; - case '\\': - ret = resolveKeyword(); + case '{': + m_nGroupStart = Strm().Tell() - 1; + ret = m_rImport.pushState(); + if (ret) + return ret; + break; + case '}': + ret = m_rImport.popState(); + if (ret) + return ret; + if (m_nGroup == 0) + { + if (m_rImport.isSubstream()) + m_rImport.finishSubstream(); + return 0; + } + break; + case '\\': + ret = resolveKeyword(); + if (ret) + return ret; + break; + case 0x0d: + break; // ignore this + case 0x0a: + m_nLineNumber++; + m_nLineStartPos = nCurrentPos; + break; + default: + if (m_nGroup == 0) + return ERROR_CHAR_OVER; + if (m_rImport.getInternalState() == INTERNAL_NORMAL) + { + ret = m_rImport.resolveChars(ch); if (ret) return ret; - break; - case 0x0d: - break; // ignore this - case 0x0a: - m_nLineNumber++; - m_nLineStartPos = nCurrentPos; - break; - default: - if (m_nGroup == 0) - return ERROR_CHAR_OVER; - if (m_rImport.getInternalState() == INTERNAL_NORMAL) + } + else + { + SAL_INFO("writerfilter", OSL_THIS_FUNC << ": hex internal state"); + b = b << 4; + sal_Int8 parsed = asHex(ch); + if (parsed == -1) + return ERROR_HEX_INVALID; + b += parsed; + count--; + if (!count) { - ret = m_rImport.resolveChars(ch); + ret = m_rImport.resolveChars(b); if (ret) return ret; + count = 2; + b = 0; + m_rImport.setInternalState(INTERNAL_NORMAL); } - else - { - SAL_INFO("writerfilter", OSL_THIS_FUNC << ": hex internal state"); - b = b << 4; - sal_Int8 parsed = asHex(ch); - if (parsed == -1) - return ERROR_HEX_INVALID; - b += parsed; - count--; - if (!count) - { - ret = m_rImport.resolveChars(b); - if (ret) - return ret; - count = 2; - b = 0; - m_rImport.setInternalState(INTERNAL_NORMAL); - } - } - break; + } + break; } } } @@ -218,7 +220,7 @@ int RTFTokenizer::resolveKeyword() bool bParam = false; int nParam = 0; - Strm().ReadChar( ch ); + Strm().ReadChar(ch); if (Strm().IsEof()) return ERROR_EOF; @@ -230,10 +232,10 @@ int RTFTokenizer::resolveKeyword() // without doing any SeekRel() return dispatchKeyword(aKeyword, bParam, nParam); } - while(isalpha(ch)) + while (isalpha(ch)) { aBuf.append(ch); - Strm().ReadChar( ch ); + Strm().ReadChar(ch); if (Strm().IsEof()) { ch = ' '; @@ -249,7 +251,7 @@ int RTFTokenizer::resolveKeyword() { // in case we'll have a parameter, that will be negative bNeg = true; - Strm().ReadChar( ch ); + Strm().ReadChar(ch); if (Strm().IsEof()) return ERROR_EOF; } @@ -259,10 +261,10 @@ int RTFTokenizer::resolveKeyword() // we have a parameter bParam = true; - while(isdigit(ch)) + while (isdigit(ch)) { aParameter.append(ch); - Strm().ReadChar( ch ); + Strm().ReadChar(ch); if (Strm().IsEof()) { ch = ' '; @@ -295,7 +297,7 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) return 0; #if OSL_DEBUG_LEVEL > 1 SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": keyword '\\" << rKeyword.getStr() << - "' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'"); + "' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'"); #endif RTFSymbol aSymbol; aSymbol.sKeyword = rKeyword.getStr(); @@ -312,37 +314,38 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) int ret; switch (m_aRTFControlWords[i].nControlType) { - case CONTROL_FLAG: - // flags ignore any parameter by definition - ret = m_rImport.dispatchFlag(m_aRTFControlWords[i].nIndex); - if (ret) - return ret; - break; - case CONTROL_DESTINATION: - // same for destinations - ret = m_rImport.dispatchDestination(m_aRTFControlWords[i].nIndex); - if (ret) - return ret; - break; - case CONTROL_SYMBOL: - // and symbols - ret = m_rImport.dispatchSymbol(m_aRTFControlWords[i].nIndex); - if (ret) - return ret; - break; - case CONTROL_TOGGLE: - ret = m_rImport.dispatchToggle(m_aRTFControlWords[i].nIndex, bParam, nParam); + case CONTROL_FLAG: + // flags ignore any parameter by definition + ret = m_rImport.dispatchFlag(m_aRTFControlWords[i].nIndex); + if (ret) + return ret; + break; + case CONTROL_DESTINATION: + // same for destinations + ret = m_rImport.dispatchDestination(m_aRTFControlWords[i].nIndex); + if (ret) + return ret; + break; + case CONTROL_SYMBOL: + // and symbols + ret = m_rImport.dispatchSymbol(m_aRTFControlWords[i].nIndex); + if (ret) + return ret; + break; + case CONTROL_TOGGLE: + ret = m_rImport.dispatchToggle(m_aRTFControlWords[i].nIndex, bParam, nParam); + if (ret) + return ret; + break; + case CONTROL_VALUE: + // values require a parameter by definition + if (bParam) + { + ret = m_rImport.dispatchValue(m_aRTFControlWords[i].nIndex, nParam); if (ret) return ret; - break; - case CONTROL_VALUE: - // values require a parameter by definition - if (bParam) { - ret = m_rImport.dispatchValue(m_aRTFControlWords[i].nIndex, nParam); - if (ret) - return ret; - } - break; + } + break; } return 0; diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx index 23602ad8a760..371ec6d1936d 100644 --- a/writerfilter/source/rtftok/rtftokenizer.hxx +++ b/writerfilter/source/rtftok/rtftokenizer.hxx @@ -15,48 +15,50 @@ class SvStream; -namespace writerfilter { - namespace rtftok { - /// RTF tokenizer that separates control words from text. - class RTFTokenizer - { - public: - RTFTokenizer(RTFListener& rImport, SvStream* pInStream, com::sun::star::uno::Reference const& xStatusIndicator); - virtual ~RTFTokenizer(); +namespace writerfilter +{ +namespace rtftok +{ +/// RTF tokenizer that separates control words from text. +class RTFTokenizer +{ +public: + RTFTokenizer(RTFListener& rImport, SvStream* pInStream, com::sun::star::uno::Reference const& xStatusIndicator); + virtual ~RTFTokenizer(); - int resolveParse(); - int asHex(char ch); - /// Number of states on the stack. - int getGroup() const; - /// To be invoked by the pushState() callback to signal when the importer enters a group. - void pushGroup(); - /// To be invoked by the popState() callback to single when the importer leaves a group. - void popGroup(); - OUString getPosition(); - sal_Size getGroupStart(); - /// To look up additional properties of a math symbol. - static bool lookupMathKeyword(RTFMathSymbol& rSymbol); - private: - SvStream& Strm(); - int resolveKeyword(); - int dispatchKeyword(OString& rKeyword, bool bParam, int nParam); + int resolveParse(); + int asHex(char ch); + /// Number of states on the stack. + int getGroup() const; + /// To be invoked by the pushState() callback to signal when the importer enters a group. + void pushGroup(); + /// To be invoked by the popState() callback to single when the importer leaves a group. + void popGroup(); + OUString getPosition(); + sal_Size getGroupStart(); + /// To look up additional properties of a math symbol. + static bool lookupMathKeyword(RTFMathSymbol& rSymbol); +private: + SvStream& Strm(); + int resolveKeyword(); + int dispatchKeyword(OString& rKeyword, bool bParam, int nParam); - RTFListener& m_rImport; - SvStream* m_pInStream; - com::sun::star::uno::Reference const& m_xStatusIndicator; - // This is the same as aRTFControlWords, but sorted - static std::vector m_aRTFControlWords; - static bool m_bControlWordsSorted; - // This is the same as aRTFMathControlWords, but sorted - static std::vector m_aRTFMathControlWords; - static bool m_bMathControlWordsSorted; - /// Same as the size of the importer's states, except that this can be negative for invalid input. - int m_nGroup; - sal_Int32 m_nLineNumber; - sal_Size m_nLineStartPos; - sal_Size m_nGroupStart; - }; - } // namespace rtftok + RTFListener& m_rImport; + SvStream* m_pInStream; + com::sun::star::uno::Reference const& m_xStatusIndicator; + // This is the same as aRTFControlWords, but sorted + static std::vector m_aRTFControlWords; + static bool m_bControlWordsSorted; + // This is the same as aRTFMathControlWords, but sorted + static std::vector m_aRTFMathControlWords; + static bool m_bMathControlWordsSorted; + /// Same as the size of the importer's states, except that this can be negative for invalid input. + int m_nGroup; + sal_Int32 m_nLineNumber; + sal_Size m_nLineStartPos; + sal_Size m_nGroupStart; +}; +} // namespace rtftok } // namespace writerfilter #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX -- cgit