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

writerfilter: turn RTFError into a C++11 scoped enumeration

Change-Id: Ib909ea6f8ed18a008f9e5079b88fc862abe13da2
üst dbbfbbab
......@@ -336,14 +336,14 @@ public:
virtual void resolve(Stream& rHandler) SAL_OVERRIDE;
// RTFListener
virtual int dispatchDestination(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchFlag(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchSymbol(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) SAL_OVERRIDE;
virtual int dispatchValue(RTFKeyword nKeyword, int nParam) SAL_OVERRIDE;
virtual int resolveChars(char ch) SAL_OVERRIDE;
virtual int pushState() SAL_OVERRIDE;
virtual int popState() SAL_OVERRIDE;
virtual RTFError dispatchDestination(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchFlag(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchSymbol(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) SAL_OVERRIDE;
virtual RTFError dispatchValue(RTFKeyword nKeyword, int nParam) SAL_OVERRIDE;
virtual RTFError resolveChars(char ch) SAL_OVERRIDE;
virtual RTFError pushState() SAL_OVERRIDE;
virtual RTFError popState() SAL_OVERRIDE;
virtual RTFDestinationState getDestinationState() SAL_OVERRIDE;
virtual void setDestinationState(RTFDestinationState nDestinationState) SAL_OVERRIDE;
virtual RTFInternalState getInternalState() SAL_OVERRIDE;
......@@ -371,7 +371,7 @@ public:
bool isInBackground();
void setDestinationText(OUString& rString);
/// Resolve a picture: If not inline, then anchored.
int resolvePict(bool bInline, css::uno::Reference<css::drawing::XShape> const& xShape);
RTFError resolvePict(bool bInline, css::uno::Reference<css::drawing::XShape> const& xShape);
/// If this is the first run of the document, starts the initial paragraph.
void checkFirstRun();
......
......@@ -23,14 +23,14 @@ enum RTFInternalState
INTERNAL_HEX
};
enum RTFErrors
enum class RTFError
{
ERROR_OK,
ERROR_GROUP_UNDER,
ERROR_GROUP_OVER,
ERROR_EOF,
ERROR_HEX_INVALID,
ERROR_CHAR_OVER
OK,
GROUP_UNDER,
GROUP_OVER,
UNEXPECTED_EOF,
HEX_INVALID,
CHAR_OVER
};
/**
......@@ -44,16 +44,16 @@ class RTFListener
public:
virtual ~RTFListener() { }
// Dispatching of control words and characters.
virtual int dispatchDestination(RTFKeyword nKeyword) = 0;
virtual int dispatchFlag(RTFKeyword nKeyword) = 0;
virtual int dispatchSymbol(RTFKeyword nKeyword) = 0;
virtual int dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) = 0;
virtual int dispatchValue(RTFKeyword nKeyword, int nParam) = 0;
virtual int resolveChars(char ch) = 0;
virtual RTFError dispatchDestination(RTFKeyword nKeyword) = 0;
virtual RTFError dispatchFlag(RTFKeyword nKeyword) = 0;
virtual RTFError dispatchSymbol(RTFKeyword nKeyword) = 0;
virtual RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) = 0;
virtual RTFError dispatchValue(RTFKeyword nKeyword, int nParam) = 0;
virtual RTFError resolveChars(char ch) = 0;
// State handling.
virtual int pushState() = 0;
virtual int popState() = 0;
virtual RTFError pushState() = 0;
virtual RTFError popState() = 0;
virtual RTFDestinationState getDestinationState() = 0;
virtual void setDestinationState(RTFDestinationState nDestinationState) = 0;
......
......@@ -34,52 +34,52 @@ RTFLookahead::~RTFLookahead()
{
}
int RTFLookahead::dispatchDestination(RTFKeyword /*nKeyword*/)
RTFError RTFLookahead::dispatchDestination(RTFKeyword /*nKeyword*/)
{
return 0;
return RTFError::OK;
}
int RTFLookahead::dispatchFlag(RTFKeyword nKeyword)
RTFError RTFLookahead::dispatchFlag(RTFKeyword nKeyword)
{
if (nKeyword == RTF_INTBL)
m_bHasTable = true;
return 0;
return RTFError::OK;
}
int RTFLookahead::dispatchSymbol(RTFKeyword /*nKeyword*/)
RTFError RTFLookahead::dispatchSymbol(RTFKeyword /*nKeyword*/)
{
return 0;
return RTFError::OK;
}
int RTFLookahead::dispatchToggle(RTFKeyword /*nKeyword*/, bool /*bParam*/, int /*nParam*/)
RTFError RTFLookahead::dispatchToggle(RTFKeyword /*nKeyword*/, bool /*bParam*/, int /*nParam*/)
{
return 0;
return RTFError::OK;
}
int RTFLookahead::dispatchValue(RTFKeyword /*nKeyword*/, int /*nParam*/)
RTFError RTFLookahead::dispatchValue(RTFKeyword /*nKeyword*/, int /*nParam*/)
{
return 0;
return RTFError::OK;
}
int RTFLookahead::resolveChars(char ch)
RTFError RTFLookahead::resolveChars(char ch)
{
while (!m_rStream.IsEof() && (ch != '{' && ch != '}' && ch != '\\'))
m_rStream.ReadChar(ch);
if (!m_rStream.IsEof())
m_rStream.SeekRel(-1);
return 0;
return RTFError::OK;
}
int RTFLookahead::pushState()
RTFError RTFLookahead::pushState()
{
m_pTokenizer->pushGroup();
return 0;
return RTFError::OK;
}
int RTFLookahead::popState()
RTFError RTFLookahead::popState()
{
m_pTokenizer->popGroup();
return 0;
return RTFError::OK;
}
RTFDestinationState RTFLookahead::getDestinationState()
......
......@@ -28,14 +28,14 @@ class RTFLookahead : public RTFListener
public:
RTFLookahead(SvStream& rStream, sal_Size nGroupStart);
virtual ~RTFLookahead();
virtual int dispatchDestination(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchFlag(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchSymbol(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual int dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) SAL_OVERRIDE;
virtual int dispatchValue(RTFKeyword nKeyword, int nParam) SAL_OVERRIDE;
virtual int resolveChars(char ch) SAL_OVERRIDE;
virtual int pushState() SAL_OVERRIDE;
virtual int popState() SAL_OVERRIDE;
virtual RTFError dispatchDestination(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchFlag(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchSymbol(RTFKeyword nKeyword) SAL_OVERRIDE;
virtual RTFError dispatchToggle(RTFKeyword nKeyword, bool bParam, int nParam) SAL_OVERRIDE;
virtual RTFError dispatchValue(RTFKeyword nKeyword, int nParam) SAL_OVERRIDE;
virtual RTFError resolveChars(char ch) SAL_OVERRIDE;
virtual RTFError pushState() SAL_OVERRIDE;
virtual RTFError popState() SAL_OVERRIDE;
virtual RTFDestinationState getDestinationState() SAL_OVERRIDE;
virtual void setDestinationState(RTFDestinationState nDestinationState) SAL_OVERRIDE;
virtual RTFInternalState getInternalState() SAL_OVERRIDE;
......
......@@ -55,11 +55,11 @@ RTFTokenizer::~RTFTokenizer()
}
int RTFTokenizer::resolveParse()
RTFError RTFTokenizer::resolveParse()
{
SAL_INFO("writerfilter", OSL_THIS_FUNC);
char ch;
int ret;
RTFError ret;
// for hex chars
int b = 0, count = 2;
sal_uInt32 nPercentSize = 0;
......@@ -87,11 +87,11 @@ int RTFTokenizer::resolveParse()
m_xStatusIndicator->setValue(nLastPos = nCurrentPos);
if (m_nGroup < 0)
return ERROR_GROUP_UNDER;
return RTFError::GROUP_UNDER;
if (m_nGroup > 0 && m_rImport.getInternalState() == INTERNAL_BIN)
{
ret = m_rImport.resolveChars(ch);
if (ret)
if (ret != RTFError::OK)
return ret;
}
else
......@@ -101,23 +101,23 @@ int RTFTokenizer::resolveParse()
case '{':
m_nGroupStart = Strm().Tell() - 1;
ret = m_rImport.pushState();
if (ret)
if (ret != RTFError::OK)
return ret;
break;
case '}':
ret = m_rImport.popState();
if (ret)
if (ret != RTFError::OK)
return ret;
if (m_nGroup == 0)
{
if (m_rImport.isSubstream())
m_rImport.finishSubstream();
return 0;
return RTFError::OK;
}
break;
case '\\':
ret = resolveKeyword();
if (ret)
if (ret != RTFError::OK)
return ret;
break;
case 0x0d:
......@@ -128,11 +128,11 @@ int RTFTokenizer::resolveParse()
break;
default:
if (m_nGroup == 0)
return ERROR_CHAR_OVER;
return RTFError::CHAR_OVER;
if (m_rImport.getInternalState() == INTERNAL_NORMAL)
{
ret = m_rImport.resolveChars(ch);
if (ret)
if (ret != RTFError::OK)
return ret;
}
else
......@@ -141,13 +141,13 @@ int RTFTokenizer::resolveParse()
b = b << 4;
sal_Int8 parsed = asHex(ch);
if (parsed == -1)
return ERROR_HEX_INVALID;
return RTFError::HEX_INVALID;
b += parsed;
count--;
if (!count)
{
ret = m_rImport.resolveChars(b);
if (ret)
if (ret != RTFError::OK)
return ret;
count = 2;
b = 0;
......@@ -160,10 +160,10 @@ int RTFTokenizer::resolveParse()
}
if (m_nGroup < 0)
return ERROR_GROUP_UNDER;
return RTFError::GROUP_UNDER;
else if (m_nGroup > 0)
return ERROR_GROUP_OVER;
return 0;
return RTFError::GROUP_OVER;
return RTFError::OK;
}
int RTFTokenizer::asHex(char ch)
......@@ -201,7 +201,7 @@ void RTFTokenizer::popGroup()
m_nGroup--;
}
int RTFTokenizer::resolveKeyword()
RTFError RTFTokenizer::resolveKeyword()
{
char ch;
OStringBuffer aBuf;
......@@ -211,7 +211,7 @@ int RTFTokenizer::resolveKeyword()
Strm().ReadChar(ch);
if (Strm().IsEof())
return ERROR_EOF;
return RTFError::UNEXPECTED_EOF;
if (!isalpha(ch))
{
......@@ -242,7 +242,7 @@ int RTFTokenizer::resolveKeyword()
bNeg = true;
Strm().ReadChar(ch);
if (Strm().IsEof())
return ERROR_EOF;
return RTFError::UNEXPECTED_EOF;
}
if (isdigit(ch))
{
......@@ -280,10 +280,10 @@ bool RTFTokenizer::lookupMathKeyword(RTFMathSymbol& rSymbol)
return true;
}
int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
RTFError RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
{
if (m_rImport.getDestinationState() == DESTINATION_SKIP)
return 0;
return RTFError::OK;
SAL_INFO("writerfilter.rtf", OSL_THIS_FUNC << ": keyword '\\" << rKeyword.getStr() <<
"' with param? " << (bParam ? 1 : 0) <<" param val: '" << (bParam ? nParam : 0) << "'");
RTFSymbol aSymbol;
......@@ -295,33 +295,33 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
SAL_INFO("writerfilter", OSL_THIS_FUNC << ": unknown keyword '\\" << rKeyword.getStr() << "'");
RTFSkipDestination aSkip(m_rImport);
aSkip.setParsed(false);
return 0;
return RTFError::OK;
}
int ret;
RTFError 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)
if (ret != RTFError::OK)
return ret;
break;
case CONTROL_DESTINATION:
// same for destinations
ret = m_rImport.dispatchDestination(m_aRTFControlWords[i].nIndex);
if (ret)
if (ret != RTFError::OK)
return ret;
break;
case CONTROL_SYMBOL:
// and symbols
ret = m_rImport.dispatchSymbol(m_aRTFControlWords[i].nIndex);
if (ret)
if (ret != RTFError::OK)
return ret;
break;
case CONTROL_TOGGLE:
ret = m_rImport.dispatchToggle(m_aRTFControlWords[i].nIndex, bParam, nParam);
if (ret)
if (ret != RTFError::OK)
return ret;
break;
case CONTROL_VALUE:
......@@ -329,13 +329,13 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam)
if (bParam)
{
ret = m_rImport.dispatchValue(m_aRTFControlWords[i].nIndex, nParam);
if (ret)
if (ret != RTFError::OK)
return ret;
}
break;
}
return 0;
return RTFError::OK;
}
OUString RTFTokenizer::getPosition()
......
......@@ -26,7 +26,7 @@ public:
RTFTokenizer(RTFListener& rImport, SvStream* pInStream, com::sun::star::uno::Reference<com::sun::star::task::XStatusIndicator> const& xStatusIndicator);
virtual ~RTFTokenizer();
int resolveParse();
RTFError resolveParse();
int asHex(char ch);
/// Number of states on the stack.
int getGroup() const
......@@ -49,8 +49,8 @@ private:
{
return *m_pInStream;
}
int resolveKeyword();
int dispatchKeyword(OString& rKeyword, bool bParam, int nParam);
RTFError resolveKeyword();
RTFError dispatchKeyword(OString& rKeyword, bool bParam, int nParam);
RTFListener& m_rImport;
SvStream* m_pInStream;
......
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