2008-08-27 Jochen Neubeck Replace MFC CMap by STL std::map
*/
+#include "pch.h"
#include "markdown.h"
#include <cstring>
#include <cstdint>
#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;
{
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;
);
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)
{
{
++upper;
}
- if (utags && upper < ahead && *upper == '<')
+ if (utags != nullptr && upper < ahead && *upper == '<')
{
size_t utlen = FindTag(utags, upper + 2);
if (utlen != 0)
++p;
} while (p < ahead && *p != c);
}
- // fall through
+ [[fallthrough]];
case '/':
case '=':
case '<':
p = token.upper;
if (name && value)
{
- if (key == 0)
+ if (key == nullptr)
{
lower = p;
*pv = std::string(value, cvalue);
name = value = 0;
}
} while (token.upper != token.lower);
- if (key == 0)
+ if (key == nullptr)
{
lower = p;
return "";
}
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();
}
{
}
}
- if (pImage == NULL)
+ if (pImage == nullptr)
{
cbImage = 0;
}
// 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));
delete m_pSharedMemory;
pImage = pCopy;
- if (pImage)
+ if (pImage != nullptr)
{
+ [[fallthrough]];
case 2 + 0:
case 2 + 0 + 8:
// little endian
}
cbImage = ucr::Utf8len_of_string(pchImage, cchImage);
pCopy = new unsigned char[cbImage];
- if (pCopy)
+ if (pCopy != nullptr)
{
uint16_t *pu16;
unsigned char *pu8;
pu8 += ucr::Ucs4_to_Utf8(*pu16, pu8);
}
delete m_pSharedMemory;
- m_pSharedMemory = NULL;
+ m_pSharedMemory = nullptr;
pImage = pCopy;
}
break;
// 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:
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)
}
}
delete m_pSharedMemory;
- m_pSharedMemory = NULL;
+ m_pSharedMemory = nullptr;
pImage = pCopy2;
delete [] pCopy;
pCopy = pCopy2;