OSDN Git Service

MergeLang.vcxproj*: Add *.po files for ShellExtension
[winmerge-jp/winmerge-jp.git] / Src / markdown.cpp
index 39ee61f..608d02f 100644 (file)
@@ -82,6 +82,7 @@ DATE:         BY:                                     DESCRIPTION:
 2008-08-27     Jochen Neubeck          Replace MFC CMap by STL std::map
 */
 
+#include "pch.h"
 #include "markdown.h"
 #include <cstring>
 #include <cstdint>
@@ -91,12 +92,14 @@ DATE:               BY:                                     DESCRIPTION:
 #include "unicoder.h"
 #include "TFile.h"
 
+#ifndef MAKEWORD
 #define MAKEWORD(a, b)      ((unsigned short)(((unsigned char)((unsigned)(a) & 0xff)) | ((unsigned short)((unsigned char)((unsigned)(b) & 0xff))) << 8))
 #define MAKELONG(a, b)      ((unsigned)(((unsigned short)((unsigned)(a) & 0xffff)) | ((unsigned)((unsigned short)((unsigned)(b) & 0xffff))) << 16))
 #define LOWORD(l)           ((unsigned short)((unsigned)(l) & 0xffff))
 #define HIWORD(l)           ((unsigned short)((unsigned)(l) >> 16))
 #define LOBYTE(w)           ((unsigned char)((unsigned)(w) & 0xff))
 #define HIBYTE(w)           ((unsigned char)((unsigned)(w) >> 8))
+#endif
 
 using Poco::ByteOrder;
 using Poco::NumberParser;
@@ -129,7 +132,7 @@ std::string CMarkdown::Resolve(const EntityMap &map, const std::string& v)
 {
        std::string ret(v);
        char *p, *q = &ret[0];
-       while ((p = strchr(q, '&')) != NULL && (q = strchr(p, ';')) != NULL)
+       while ((p = strchr(q, '&')) != nullptr && (q = strchr(p, ';')) != nullptr)
        {
                *q = '\0';
                char *key = p + 1;
@@ -266,9 +269,9 @@ static const char htmlUTags[] =
 );
 
 CMarkdown::CMarkdown(const char *upper, const char *ahead, unsigned flags):
-first(0), lower(0), upper(upper), ahead(ahead),
+first(nullptr), lower(nullptr), upper(upper), ahead(ahead),
 memcmp(flags & IgnoreCase ? ::_memicmp : ::memcmp),
-utags(flags & HtmlUTags ? htmlUTags : NULL)
+utags(flags & HtmlUTags ? htmlUTags : nullptr)
 {
        if (CMarkdown::ahead > CMarkdown::upper)
        {
@@ -394,7 +397,7 @@ CMarkdown &CMarkdown::Move()
                {
                        ++upper;
                }
-               if (utags && upper < ahead && *upper == '<')
+               if (utags != nullptr && upper < ahead && *upper == '<')
                {
                        size_t utlen = FindTag(utags, upper + 2);
                        if (utlen != 0)
@@ -634,7 +637,7 @@ int CMarkdown::Token::IsSpecial(const char *p, const char *ahead)
                                        ++p;
                                } while (p < ahead && *p != c);
                        }
-                       // fall through
+                       [[fallthrough]];
                case '/':
                case '=':
                case '<':
@@ -700,7 +703,7 @@ std::string CMarkdown::GetAttribute(const char *key, std::string *pv)
                p = token.upper;
                if (name && value)
                {
-                       if (key == 0)
+                       if (key == nullptr)
                        {
                                lower = p;
                                *pv = std::string(value, cvalue);
@@ -713,7 +716,7 @@ std::string CMarkdown::GetAttribute(const char *key, std::string *pv)
                        name = value = 0;
                }
        } while (token.upper != token.lower);
-       if (key == 0)
+       if (key == nullptr)
        {
                lower = p;
                return "";
@@ -756,19 +759,19 @@ int CMarkdown::FileImage::GuessByteOrder(unsigned dwBOM)
 }
 
 CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
-: pImage(NULL), cbImage(0), nByteOrder(0), m_pSharedMemory(NULL), pCopy(NULL)
+: pImage(nullptr), cbImage(0), nByteOrder(0), m_pSharedMemory(nullptr), pCopy(nullptr)
 {
        if (flags & Mapping)
        {
                pImage = (void *)(path);
                cbImage = trunc;
        }
-       else
+       else if (path != nullptr)
        {
                try
                {
                        TFile file(path);
-                       m_pSharedMemory = new SharedMemory(file, SharedMemory::AM_READ, 0);
+                       m_pSharedMemory = new SharedMemory(file, SharedMemory::AM_READ);
                        pImage = m_pSharedMemory->begin();
                        cbImage = m_pSharedMemory->end() - m_pSharedMemory->begin();
                }
@@ -776,7 +779,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                {
                }
        }
-       if (pImage == NULL)
+       if (pImage == nullptr)
        {
                cbImage = 0;
        }
@@ -789,7 +792,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                        // big endian: swab first
                        cbImage &= ~1UL;
                        pCopy = new unsigned char[cbImage];
-                       if (pCopy)
+                       if (pCopy != nullptr)
                        {
                                for (size_t i = 0; i < cbImage / 2; ++i)
                                        *((uint16_t *)pCopy + i) = Poco::ByteOrder::flipBytes(*((uint16_t *)pImage + i));
@@ -797,8 +800,9 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
 
                        delete m_pSharedMemory;
                        pImage = pCopy;
-                       if (pImage)
+                       if (pImage != nullptr)
                        {
+                               [[fallthrough]];
                        case 2 + 0:
                        case 2 + 0 + 8:
                                // little endian
@@ -811,7 +815,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                                }
                                cbImage = ucr::Utf8len_of_string(pchImage, cchImage);
                                pCopy = new unsigned char[cbImage];
-                               if (pCopy)
+                               if (pCopy != nullptr)
                                {
                                        uint16_t *pu16;
                                        unsigned char *pu8;
@@ -819,7 +823,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                                                pu8 += ucr::Ucs4_to_Utf8(*pu16, pu8);
                                }
                                delete m_pSharedMemory;
-                               m_pSharedMemory = NULL;
+                               m_pSharedMemory = nullptr;
                                pImage = pCopy;
                        }
                        break;
@@ -830,16 +834,17 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                        // odd word endianness: swab first
                        cbImage &= ~3UL;
                        pCopy = new unsigned char[cbImage];
-                       if (pCopy)
+                       if (pCopy != nullptr)
                        {
                                for (size_t i = 0; i < cbImage / 2; ++i)
                                        *((uint16_t *)pCopy + i) = Poco::ByteOrder::flipBytes(*((uint16_t *)pImage + i));
                        }
                        delete m_pSharedMemory;
-                       m_pSharedMemory = NULL;
+                       m_pSharedMemory = nullptr;
                        pImage = pCopy;
-                       if (pImage)
+                       if (pImage != nullptr)
                        {
+                               [[fallthrough]];
                        case 4 + 0:
                        case 4 + 0 + 8:
                        case 4 + 3:
@@ -863,7 +868,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                                        cbImage += ucr::Utf8len_fromCodepoint(uch);
                                }
                                void *pCopy2 = new unsigned char[cbImage];
-                               if (pCopy2)
+                               if (pCopy2 != nullptr)
                                {
                                        cbImage = 0;
                                        for (size_t i = 0; i < cchImage; i += 4)
@@ -877,7 +882,7 @@ CMarkdown::FileImage::FileImage(const TCHAR *path, size_t trunc, unsigned flags)
                                        }
                                }
                                delete m_pSharedMemory;
-                               m_pSharedMemory = NULL;
+                               m_pSharedMemory = nullptr;
                                pImage = pCopy2;
                                delete [] pCopy;
                                pCopy = pCopy2;