1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 
5 #include "mozilla/Attributes.h"
6 #include <string>
7 #include "rtfDecoder.h"
8 
9 class CRTFMailDecoder : public CRTFDecoder {
10  public:
11   enum Mode { mNone, mText, mHTML };
CRTFMailDecoder()12   CRTFMailDecoder() : m_mode(mNone), m_state(sNormal), m_skipLevel(0) {}
13   void BeginGroup() override;
14   void EndGroup() override;
15   void Keyword(const char* name, const int* Val) override;
16   void PCDATA(const wchar_t* data, size_t cch) override;
17   void BDATA(const char* data, size_t sz) override;
text()18   const wchar_t* text() { return m_text.c_str(); }
textSize()19   std::wstring::size_type textSize() { return m_text.size(); }
mode()20   Mode mode() { return m_mode; }
21 
22  private:
23   enum State {
24     sNormal = 0x0000,
25     sBeginGroup = 0x0001,
26     sAsterisk = 0x0002,
27     sHtmlRtf = 0x0004
28   };
29 
30   std::wstring m_text;
31   Mode m_mode;
32   unsigned int m_state;  // bitmask of State
33                          // bool m_beginGroup; // true just after the {
34                          // bool m_asterisk; // true just after the {\*
35   int m_skipLevel;       // if >0 then we ignore everything
36                          // bool m_htmlrtf;
SetState(unsigned int s)37   inline void SetState(unsigned int s) { m_state |= s; }
ClearState(unsigned int s)38   inline void ClearState(unsigned int s) { m_state &= ~s; }
CheckState(State s)39   inline bool CheckState(State s) { return (m_state & s) != 0; }
IsAsterisk()40   inline bool IsAsterisk() { return CheckState(sAsterisk); }
IsBeginGroup()41   inline bool IsBeginGroup() { return CheckState(sBeginGroup); }
IsHtmlRtf()42   inline bool IsHtmlRtf() { return CheckState(sHtmlRtf); }
43   void AddText(const wchar_t* txt, size_t cch = static_cast<size_t>(-1));
44 };
45