OSDN Git Service

Fix issue #2046: Folder compare omits unique folders from results if they contain...
[winmerge-jp/winmerge-jp.git] / Src / markdown.h
1 #pragma once
2
3 #include <map>
4 #include <string>
5 #include "UnicodeString.h"
6
7 namespace Poco { class SharedMemory; }
8
9 class CMarkdown
10 {
11 //      Core class
12 public:
13         typedef std::map<std::string, std::string> EntityMap;
14         static void Load(EntityMap &entityMap);
15         static std::string Resolve(const EntityMap &, const std::string& v);
16         static std::string Entities(const std::string& v);
17         void Load(EntityMap &entityMap, int dummy = 0);
18         class FileImage;
19         class File;
20         const char *first;      // first char of current markup (valid after Move)
21         const char *lower;      // beginning of enclosed text (valid after Move)
22         const char *upper;      // end of enclosed text (initially beginning of file)
23         const char *ahead;      // last char of file
24         enum : unsigned
25         {
26                 IgnoreCase = 0x10,
27                 HtmlUTags = 0x20,                       // check for unbalanced tags
28                 Html = IgnoreCase|HtmlUTags     // shortcut
29         };
30         CMarkdown(const char *upper, const char *ahead, unsigned flags = 0);
31         operator bool();                                // is node ahead?
32         void Scan();                                    // find closing tag
33         CMarkdown &Move();                              // move to next node
34         CMarkdown &Move(const char *);  // move to next node with given name
35         bool Pull();                                    // pull child nodes into view
36         CMarkdown &Pop();                               // irreversible pull for chained calls
37         bool Push();                                    // reverse pull
38         std::string GetTagName() const; // tag name
39         std::string GetTagText() const; // tag name plus attributes
40         std::string GetInnerText();             // text between enclosing tags
41         std::string GetOuterText();             // text including enclosing tags
42         std::string GetAttribute(const char *, std::string * = 0); // random or enumerate
43 private:
44         int (*const memcmp)(const void *, const void *, size_t);
45         const char *const utags;
46         size_t FindTag(const char *, const char *) const;
47         class Token;
48 };
49
50 class CMarkdown::FileImage
51 {
52 //      Map a file into process memory. Optionally convert UCS2 source to UTF8.
53 public:
54         size_t cbImage;
55         void *pImage;
56         void *pCopy;
57         enum : unsigned
58         {
59                 Octets = 0x02 + 0x04,
60                 Mapping = 0x40
61         };
62         int nByteOrder;
63         Poco::SharedMemory *m_pSharedMemory;
64         explicit FileImage(const tchar_t *, size_t trunc = 0, unsigned flags = 0);
65         FileImage(const FileImage& other) = delete;
66         ~FileImage();
67         static int GuessByteOrder(unsigned);
68 };
69
70 class CMarkdown::File : public CMarkdown::FileImage, public CMarkdown
71 {
72 //      Construct CMarkdown object from file.
73 public:
74         explicit File(const tchar_t * path, size_t trunc = 0, unsigned flags = Octets):
75         CMarkdown::FileImage(path, trunc, flags),
76         CMarkdown((const char *)pImage, (const char *)pImage + cbImage, flags)
77         {
78         }
79 };