Kaydet (Commit) df0dea0b authored tarafından Miklos Vajna's avatar Miklos Vajna

writerfilter: fix indentation in rtftokenizer

Change-Id: Ia9c609eabc39c3933479eae3d5c4499f11c58528
üst f1f44021
...@@ -20,8 +20,10 @@ ...@@ -20,8 +20,10 @@
using namespace com::sun::star; using namespace com::sun::star;
namespace writerfilter { namespace writerfilter
namespace rtftok { {
namespace rtftok
{
std::vector<RTFSymbol> RTFTokenizer::m_aRTFControlWords; std::vector<RTFSymbol> RTFTokenizer::m_aRTFControlWords;
bool RTFTokenizer::m_bControlWordsSorted; bool RTFTokenizer::m_bControlWordsSorted;
...@@ -30,12 +32,12 @@ bool RTFTokenizer::m_bMathControlWordsSorted; ...@@ -30,12 +32,12 @@ bool RTFTokenizer::m_bMathControlWordsSorted;
RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, uno::Reference<task::XStatusIndicator> const& xStatusIndicator) RTFTokenizer::RTFTokenizer(RTFListener& rImport, SvStream* pInStream, uno::Reference<task::XStatusIndicator> const& xStatusIndicator)
: m_rImport(rImport), : m_rImport(rImport),
m_pInStream(pInStream), m_pInStream(pInStream),
m_xStatusIndicator(xStatusIndicator), m_xStatusIndicator(xStatusIndicator),
m_nGroup(0), m_nGroup(0),
m_nLineNumber(0), m_nLineNumber(0),
m_nLineStartPos(0), m_nLineStartPos(0),
m_nGroupStart(0) m_nGroupStart(0)
{ {
if (!RTFTokenizer::m_bControlWordsSorted) if (!RTFTokenizer::m_bControlWordsSorted)
{ {
...@@ -62,7 +64,7 @@ SvStream& RTFTokenizer::Strm() ...@@ -62,7 +64,7 @@ SvStream& RTFTokenizer::Strm()
int RTFTokenizer::resolveParse() int RTFTokenizer::resolveParse()
{ {
SAL_INFO( "writerfilter", OSL_THIS_FUNC ); SAL_INFO("writerfilter", OSL_THIS_FUNC);
char ch; char ch;
int ret; int ret;
// for hex chars // for hex chars
...@@ -83,7 +85,7 @@ int RTFTokenizer::resolveParse() ...@@ -83,7 +85,7 @@ int RTFTokenizer::resolveParse()
m_xStatusIndicator->setValue(nLastPos = nCurrentPos); 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 << "'"); //SAL_INFO("writerfilter", OSL_THIS_FUNC << ": parsing character '" << ch << "'");
...@@ -103,63 +105,63 @@ int RTFTokenizer::resolveParse() ...@@ -103,63 +105,63 @@ int RTFTokenizer::resolveParse()
{ {
switch (ch) switch (ch)
{ {
case '{': case '{':
m_nGroupStart = Strm().Tell() - 1; m_nGroupStart = Strm().Tell() - 1;
ret = m_rImport.pushState(); ret = m_rImport.pushState();
if (ret) if (ret)
return ret; return ret;
break; break;
case '}': case '}':
ret = m_rImport.popState(); ret = m_rImport.popState();
if (ret) if (ret)
return ret; return ret;
if (m_nGroup == 0) if (m_nGroup == 0)
{ {
if (m_rImport.isSubstream()) if (m_rImport.isSubstream())
m_rImport.finishSubstream(); m_rImport.finishSubstream();
return 0; return 0;
} }
break; break;
case '\\': case '\\':
ret = resolveKeyword(); 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) if (ret)
return ret; return ret;
break; }
case 0x0d: else
break; // ignore this {
case 0x0a: SAL_INFO("writerfilter", OSL_THIS_FUNC << ": hex internal state");
m_nLineNumber++; b = b << 4;
m_nLineStartPos = nCurrentPos; sal_Int8 parsed = asHex(ch);
break; if (parsed == -1)
default: return ERROR_HEX_INVALID;
if (m_nGroup == 0) b += parsed;
return ERROR_CHAR_OVER; count--;
if (m_rImport.getInternalState() == INTERNAL_NORMAL) if (!count)
{ {
ret = m_rImport.resolveChars(ch); ret = m_rImport.resolveChars(b);
if (ret) if (ret)
return ret; return ret;
count = 2;
b = 0;
m_rImport.setInternalState(INTERNAL_NORMAL);
} }
else }
{ break;
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;
} }
} }
} }
...@@ -218,7 +220,7 @@ int RTFTokenizer::resolveKeyword() ...@@ -218,7 +220,7 @@ int RTFTokenizer::resolveKeyword()
bool bParam = false; bool bParam = false;
int nParam = 0; int nParam = 0;
Strm().ReadChar( ch ); Strm().ReadChar(ch);
if (Strm().IsEof()) if (Strm().IsEof())
return ERROR_EOF; return ERROR_EOF;
...@@ -230,10 +232,10 @@ int RTFTokenizer::resolveKeyword() ...@@ -230,10 +232,10 @@ int RTFTokenizer::resolveKeyword()
// without doing any SeekRel() // without doing any SeekRel()
return dispatchKeyword(aKeyword, bParam, nParam); return dispatchKeyword(aKeyword, bParam, nParam);
} }
while(isalpha(ch)) while (isalpha(ch))
{ {
aBuf.append(ch); aBuf.append(ch);
Strm().ReadChar( ch ); Strm().ReadChar(ch);
if (Strm().IsEof()) if (Strm().IsEof())
{ {
ch = ' '; ch = ' ';
...@@ -249,7 +251,7 @@ int RTFTokenizer::resolveKeyword() ...@@ -249,7 +251,7 @@ int RTFTokenizer::resolveKeyword()
{ {
// in case we'll have a parameter, that will be negative // in case we'll have a parameter, that will be negative
bNeg = true; bNeg = true;
Strm().ReadChar( ch ); Strm().ReadChar(ch);
if (Strm().IsEof()) if (Strm().IsEof())
return ERROR_EOF; return ERROR_EOF;
} }
...@@ -259,10 +261,10 @@ int RTFTokenizer::resolveKeyword() ...@@ -259,10 +261,10 @@ int RTFTokenizer::resolveKeyword()
// we have a parameter // we have a parameter
bParam = true; bParam = true;
while(isdigit(ch)) while (isdigit(ch))
{ {
aParameter.append(ch); aParameter.append(ch);
Strm().ReadChar( ch ); Strm().ReadChar(ch);
if (Strm().IsEof()) if (Strm().IsEof())
{ {
ch = ' '; ch = ' ';
...@@ -295,7 +297,7 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) ...@@ -295,7 +297,7 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
return 0; return 0;
#if OSL_DEBUG_LEVEL > 1 #if OSL_DEBUG_LEVEL > 1
SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": keyword '\\" << rKeyword.getStr() << 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 #endif
RTFSymbol aSymbol; RTFSymbol aSymbol;
aSymbol.sKeyword = rKeyword.getStr(); aSymbol.sKeyword = rKeyword.getStr();
...@@ -312,37 +314,38 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) ...@@ -312,37 +314,38 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
int ret; int ret;
switch (m_aRTFControlWords[i].nControlType) switch (m_aRTFControlWords[i].nControlType)
{ {
case CONTROL_FLAG: case CONTROL_FLAG:
// flags ignore any parameter by definition // flags ignore any parameter by definition
ret = m_rImport.dispatchFlag(m_aRTFControlWords[i].nIndex); ret = m_rImport.dispatchFlag(m_aRTFControlWords[i].nIndex);
if (ret) if (ret)
return ret; return ret;
break; break;
case CONTROL_DESTINATION: case CONTROL_DESTINATION:
// same for destinations // same for destinations
ret = m_rImport.dispatchDestination(m_aRTFControlWords[i].nIndex); ret = m_rImport.dispatchDestination(m_aRTFControlWords[i].nIndex);
if (ret) if (ret)
return ret; return ret;
break; break;
case CONTROL_SYMBOL: case CONTROL_SYMBOL:
// and symbols // and symbols
ret = m_rImport.dispatchSymbol(m_aRTFControlWords[i].nIndex); ret = m_rImport.dispatchSymbol(m_aRTFControlWords[i].nIndex);
if (ret) if (ret)
return ret; return ret;
break; break;
case CONTROL_TOGGLE: case CONTROL_TOGGLE:
ret = m_rImport.dispatchToggle(m_aRTFControlWords[i].nIndex, bParam, nParam); 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) if (ret)
return ret; return ret;
break; }
case CONTROL_VALUE: break;
// values require a parameter by definition
if (bParam) {
ret = m_rImport.dispatchValue(m_aRTFControlWords[i].nIndex, nParam);
if (ret)
return ret;
}
break;
} }
return 0; return 0;
......
...@@ -15,48 +15,50 @@ ...@@ -15,48 +15,50 @@
class SvStream; class SvStream;
namespace writerfilter { namespace writerfilter
namespace rtftok { {
/// RTF tokenizer that separates control words from text. namespace rtftok
class RTFTokenizer {
{ /// RTF tokenizer that separates control words from text.
public: class RTFTokenizer
RTFTokenizer(RTFListener& rImport, SvStream* pInStream, com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> const& xStatusIndicator); {
virtual ~RTFTokenizer(); public:
RTFTokenizer(RTFListener& rImport, SvStream* pInStream, com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> const& xStatusIndicator);
virtual ~RTFTokenizer();
int resolveParse(); int resolveParse();
int asHex(char ch); int asHex(char ch);
/// Number of states on the stack. /// Number of states on the stack.
int getGroup() const; int getGroup() const;
/// To be invoked by the pushState() callback to signal when the importer enters a group. /// To be invoked by the pushState() callback to signal when the importer enters a group.
void pushGroup(); void pushGroup();
/// To be invoked by the popState() callback to single when the importer leaves a group. /// To be invoked by the popState() callback to single when the importer leaves a group.
void popGroup(); void popGroup();
OUString getPosition(); OUString getPosition();
sal_Size getGroupStart(); sal_Size getGroupStart();
/// To look up additional properties of a math symbol. /// To look up additional properties of a math symbol.
static bool lookupMathKeyword(RTFMathSymbol& rSymbol); static bool lookupMathKeyword(RTFMathSymbol& rSymbol);
private: private:
SvStream& Strm(); SvStream& Strm();
int resolveKeyword(); int resolveKeyword();
int dispatchKeyword(OString& rKeyword, bool bParam, int nParam); int dispatchKeyword(OString& rKeyword, bool bParam, int nParam);
RTFListener& m_rImport; RTFListener& m_rImport;
SvStream* m_pInStream; SvStream* m_pInStream;
com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> const& m_xStatusIndicator; com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> const& m_xStatusIndicator;
// This is the same as aRTFControlWords, but sorted // This is the same as aRTFControlWords, but sorted
static std::vector<RTFSymbol> m_aRTFControlWords; static std::vector<RTFSymbol> m_aRTFControlWords;
static bool m_bControlWordsSorted; static bool m_bControlWordsSorted;
// This is the same as aRTFMathControlWords, but sorted // This is the same as aRTFMathControlWords, but sorted
static std::vector<RTFMathSymbol> m_aRTFMathControlWords; static std::vector<RTFMathSymbol> m_aRTFMathControlWords;
static bool m_bMathControlWordsSorted; static bool m_bMathControlWordsSorted;
/// Same as the size of the importer's states, except that this can be negative for invalid input. /// Same as the size of the importer's states, except that this can be negative for invalid input.
int m_nGroup; int m_nGroup;
sal_Int32 m_nLineNumber; sal_Int32 m_nLineNumber;
sal_Size m_nLineStartPos; sal_Size m_nLineStartPos;
sal_Size m_nGroupStart; sal_Size m_nGroupStart;
}; };
} // namespace rtftok } // namespace rtftok
} // namespace writerfilter } // namespace writerfilter
#endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX #endif // INCLUDED_WRITERFILTER_SOURCE_RTFTOK_RTFTOKENIZER_HXX
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment