Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib/coil/common/coil/Properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/

#include <coil/Properties.h>
#include <coil/stringutil.h>

#include <iostream>
#include <map>
Expand Down Expand Up @@ -73,11 +72,13 @@ namespace coil
* @brief Constructor(Give the default value with char*[])
* @endif
*/
/*
Properties::Properties(const char* const defaults[], size_t num)
{
leaf.clear();
setDefaults(defaults, num);
}
*/

/*!
* @if jp
Expand Down Expand Up @@ -306,14 +307,16 @@ namespace coil
* @brief Set a default value together in the property list
* @endif
*/
/*
void Properties::setDefaults(const char* const defaults[], size_t num)
{
for (size_t i = 0; i < num && defaults[i][0] != '\0' ; i += 2)
for (size_t i = 0; i+1 < num && defaults[i] && defaults[i][0] != '\0' ; i += 2)
{
setDefault(eraseBothEndsBlank(defaults[i]),
eraseBothEndsBlank(defaults[i + 1]));
}
}
*/

//============================================================
// load and save functions
Expand Down
25 changes: 21 additions & 4 deletions src/lib/coil/common/coil/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#ifndef COIL_PROPERTIES_H
#define COIL_PROPERTIES_H

#include <coil/stringutil.h>

#include <limits>
#include <string>
#include <vector>
Expand Down Expand Up @@ -205,8 +207,14 @@ namespace coil
*
* @endif
*/
explicit Properties(const char* const defaults[],
size_t num = std::numeric_limits<size_t>::max());
//explicit Properties(const char* const defaults[],
// size_t num = std::numeric_limits<size_t>::max());
template <size_t N>
explicit Properties(const char* const (&defaults)[N], size_t num = N)
{
leaf.clear();
setDefaults(defaults, num);
}

/*!
* @if jp
Expand Down Expand Up @@ -594,8 +602,17 @@ namespace coil
*
* @endif
*/
void setDefaults(const char* const defaults[],
size_t num = std::numeric_limits<size_t>::max());
//void setDefaults(const char* const defaults[],
// size_t num = std::numeric_limits<size_t>::max());
template <size_t N>
void setDefaults(const char* const (&defaults)[N], size_t num = N)
{
for (size_t i = 0; i + 1 < N && i + 1 < num && defaults[i][0] != '\0'; i += 2)
{
setDefault(eraseBothEndsBlank(defaults[i]),
eraseBothEndsBlank(defaults[i + 1]));
}
}

//============================================================
// load and save functions
Expand Down
36 changes: 28 additions & 8 deletions src/lib/coil/common/coil/crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/

#include <coil/crc.h>
#include <array>
#include <cstdint>

namespace coil
{
Expand Down Expand Up @@ -46,8 +48,8 @@ namespace coil
*/
unsigned short crc16(const char* str, size_t len)
{
static const unsigned short crc16tab[256] =
{
static constexpr std::array<uint16_t, 256> crc16tab{ {

0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
Expand Down Expand Up @@ -83,11 +85,20 @@ namespace coil
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0,
};
} };
unsigned short crc16(0xffff);
const unsigned char* p = reinterpret_cast<const unsigned char*>(str);
for (size_t i(0); i < len; ++i)
{
crc16 = crc16tab[(crc16 >> 8) ^ str[i]] ^ (crc16 << 8);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif
crc16 = crc16tab[(crc16 >> 8) ^ p[i]] ^ (crc16 << 8);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
return crc16 ^ 0x0000;
}
Expand Down Expand Up @@ -135,8 +146,8 @@ namespace coil
* crc32table[n] = c;
* }
*/
static const unsigned int crc32tab[256] =
{

static constexpr std::array<uint32_t, 256> crc32tab{ {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
Expand Down Expand Up @@ -180,11 +191,20 @@ namespace coil
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
};
}};
unsigned long c(0xffffffffL);
const unsigned char* p = reinterpret_cast<const unsigned char*>(str);
for (size_t i(0); i < len; ++i)
{
c = crc32tab[(0xff ^ str[i]) & 0xff] ^ (c >> 8);
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif
c = crc32tab[(0xff ^ p[i]) & 0xff] ^ (c >> 8);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
return c ^ 0xffffffffL;
}
Expand Down
21 changes: 12 additions & 9 deletions src/lib/coil/common/coil/stringutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ namespace coil
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
int buff_size = MultiByteToWideChar(CP_UTF7, 0, str.c_str(), -1, (wchar_t*)nullptr, 0);
wchar_t* ret = new wchar_t[buff_size];
MultiByteToWideChar(CP_UTF7, 0, str.c_str(), -1, ret, buff_size);
std::wstring wstr(ret, ret + buff_size - 1);
delete[] ret;
std::wstring wstr(buff_size, 0);

MultiByteToWideChar(CP_UTF7, 0, str.c_str(), -1, &wstr[0], buff_size);
#else
std::wstring wstr(str.length(), L' ');
std::copy(str.begin(), str.end(), wstr.begin());
Expand All @@ -72,10 +71,8 @@ namespace coil
{
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
int buff_size = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, (char*)nullptr, 0, nullptr, nullptr);
CHAR* ret = new CHAR[buff_size];
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, ret, buff_size, nullptr, nullptr);
std::string str(ret, ret + buff_size - 1);
delete[] ret;
std::string str(buff_size, 0);
WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), -1, &str[0], buff_size, nullptr, nullptr);
#else
std::string str(wstr.length(), ' ');
std::copy(wstr.begin(), wstr.end(), str.begin());
Expand Down Expand Up @@ -853,7 +850,13 @@ namespace coil
m_args.reserve(args.size());
for (auto&& arg : args)
{
m_args.emplace_back(arg.c_str(), arg.c_str() + arg.size() + 1);
std::vector<char> buf;
buf.reserve(arg.size() + 1);

buf.insert(buf.end(), arg.begin(), arg.end());
buf.push_back('\0');

m_args.emplace_back(std::move(buf));
}
// make m_argv.
m_argv.reserve(m_args.size() + 1);
Expand Down
8 changes: 8 additions & 0 deletions src/lib/coil/win32/coil/Routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,18 @@ namespace coil

for (int i(0); i < static_cast<int>(ipaddr_table->dwNumEntries); ++i)
{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
#endif
if (bestifindex == ipaddr_table->table[i].dwIndex)
{
IN_ADDR inipaddr;
inipaddr.S_un.S_addr = static_cast<u_long>(ipaddr_table->table[i].dwAddr);
#ifdef __clang__
#pragma clang diagnostic pop
#endif
char str_buffer[INET_ADDRSTRLEN] = { 0 };
if (inet_ntop(AF_INET, &inipaddr.S_un, str_buffer, sizeof(str_buffer)) != nullptr)
{
Expand Down
2 changes: 2 additions & 0 deletions src/lib/hrtm/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ namespace utils
: coil::Properties("", "")
{
}
/*
Properties::Properties(const char* const defaults[], long num)
: coil::Properties(defaults, num)
{
}
*/
Properties::~Properties() = default;
} // namespace utils
} // namespace hrtm
9 changes: 7 additions & 2 deletions src/lib/hrtm/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ namespace utils
{
public:
explicit Properties();
explicit Properties(const char* const defaults[],
long num = std::numeric_limits<size_t>::max());
//explicit Properties(const char* const defaults[],
// long num = std::numeric_limits<size_t>::max());
template <size_t N>
explicit Properties(const char* const (&defaults)[N], size_t num = N)
: coil::Properties(defaults, num)
{
}
~Properties() override;
};
} // namespace utils
Expand Down
Loading