LCOV - code coverage report
Current view: top level - netwerk/streamconv/converters - nsTXTToHTMLConv.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 1 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /* This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       5             : 
       6             : #ifndef ____nstxttohtmlconv___h___
       7             : #define ____nstxttohtmlconv___h___
       8             : 
       9             : #include "nsITXTToHTMLConv.h"
      10             : #include "nsCOMPtr.h"
      11             : #include "nsTArray.h"
      12             : #include "nsString.h"
      13             : 
      14             : #define NS_NSTXTTOHTMLCONVERTER_CID                         \
      15             : { /* 9ef9fa14-1dd1-11b2-9d65-d72d6d1f025e */ \
      16             :     0x9ef9fa14, \
      17             :     0x1dd1, \
      18             :     0x11b2, \
      19             :     {0x9d, 0x65, 0xd7, 0x2d, 0x6d, 0x1f, 0x02, 0x5e} \
      20             : }
      21             : 
      22             : // Internal representation of a "token"
      23           0 : typedef struct convToken {
      24             :     nsString token;     // the actual string (i.e. "http://")
      25             :     nsString modText;   // replacement text or href prepend text.
      26             :     bool     prepend;   // flag indicating how the modText should be used.
      27             : } convToken;
      28             : 
      29             : template<class T> class nsAutoPtr;
      30             : 
      31             : /**
      32             :  * Convert plain text to HTML.
      33             :  *
      34             :  * OVERVIEW OF HOW THIS CLASS WORKS:
      35             :  *
      36             :  * This class stores an array of tokens that should be replaced by something,
      37             :  * or something that should be prepended.
      38             :  * The "token" member of convToken is the text to search for. This is a
      39             :  * substring of the desired token. Tokens are delimited by TOKEN_DELIMITERS.
      40             :  * That entire token will be replaced by modText (if prepend is false); or it
      41             :  * will be linkified and modText will be prepended to the token if prepend is
      42             :  * true.
      43             :  *
      44             :  * Note that all of the text will be in a preformatted block, so there is no
      45             :  * need to emit line-end tags, or set the font face to monospace.
      46             :  *
      47             :  * This works as a stream converter, so data will arrive by
      48             :  * OnStartRequest/OnDataAvailable/OnStopRequest calls.
      49             :  *
      50             :  * OStopR will possibly process a remaining token.
      51             :  *
      52             :  * If the data of one pass contains a part of a token, that part will be stored
      53             :  * in mBuffer. The rest of the data will be sent to the next listener.
      54             :  *
      55             :  * XXX this seems suboptimal. this means that this design will only work for
      56             :  * links. and it is impossible to append anything to the token. this means that,
      57             :  * for example, making *foo* bold is not possible.
      58             :  */
      59             : class nsTXTToHTMLConv : public nsITXTToHTMLConv {
      60             : public:
      61             :     NS_DECL_ISUPPORTS
      62             :     NS_DECL_NSISTREAMCONVERTER
      63             :     NS_DECL_NSITXTTOHTMLCONV
      64             :     NS_DECL_NSIREQUESTOBSERVER
      65             :     NS_DECL_NSISTREAMLISTENER
      66             : 
      67             :     nsTXTToHTMLConv();
      68             :     nsresult Init();
      69             : 
      70             : protected:
      71             :     virtual ~nsTXTToHTMLConv();
      72             : 
      73             :     // return the token and it's location in the underlying buffer.
      74             :     int32_t FindToken(int32_t cursor, convToken* *_retval);
      75             : 
      76             :     // return the cursor location after munging HTML into the
      77             :     // underlying buffer, according to mToken
      78             :     int32_t CatHTML(int32_t front, int32_t back);
      79             : 
      80             :     nsCOMPtr<nsIStreamListener>     mListener; // final listener (consumer)
      81             :     nsString                        mBuffer;   // any carry over data
      82             :     nsTArray<nsAutoPtr<convToken> > mTokens;   // list of tokens to search for
      83             :     convToken                       *mToken;   // current token (if any)
      84             :     nsString                        mPageTitle; // Page title
      85             :     bool                            mPreFormatHTML; // Whether to use <pre> tags
      86             : };
      87             : 
      88             : #endif // ____nstxttohtmlconv___h___
      89             : 

Generated by: LCOV version 1.13