Skip to content

Commit

Permalink
Merge pull request #11340 from keymanapp/chore/core/8800-cxx17
Browse files Browse the repository at this point in the history
  • Loading branch information
srl295 authored May 14, 2024
2 parents 72a1901 + d3c9fbb commit 571e1fe
Show file tree
Hide file tree
Showing 11 changed files with 22,047 additions and 10,272 deletions.
2 changes: 1 addition & 1 deletion core/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ project('keyman_core', 'cpp', 'c',
version: run_command(find_program('getversion.bat', 'getversion.sh'), check:true).stdout().strip(),
license: 'MIT',
default_options : ['buildtype=release',
'cpp_std=c++14',
'cpp_std=c++17',
'b_vscrt=static_from_buildtype',
'warning_level=2',
'debug=true'],
Expand Down
11 changes: 10 additions & 1 deletion core/src/jsonpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <limits>

#include "jsonpp.hpp"

#include "utfcodec.hpp"

#if defined(_MSC_VER)
#define FORMAT_INTMAX "%lli"
Expand Down Expand Up @@ -105,6 +105,15 @@ json & json::operator << (json::string s) throw()
return *this;
}

json & json::operator <<(const char16_t* s) throw()
{
std::u16string str16(s);
std::string str = convert<char16_t, char>(str16);

(*this) << str;
return *this;
}

json & json::operator << (json::number f) throw()
{
context(seq);
Expand Down
21 changes: 13 additions & 8 deletions core/src/jsonpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
class json
{
// Prevent copying
json(const json &);
json & operator = (const json &);
json(const json &) = delete;
json & operator = (const json &) = delete;

typedef void (*_context_t)(json &);

Expand Down Expand Up @@ -62,6 +62,7 @@ class json

auto & stream() const throw();

json & operator << (const char16_t*) throw();
json & operator << (string) throw();
json & operator << (number) throw();
json & operator << (integer) throw();
Expand All @@ -78,8 +79,8 @@ class json
class json::closer
{
// Prevent copying.
closer(const closer &);
closer & operator = (const closer &);
closer(const closer &) = delete;
closer & operator = (const closer &) = delete;

json * const _j;
public:
Expand Down Expand Up @@ -113,13 +114,17 @@ json & json::operator << (json::_context_t ctxt) throw()
return *this;
}

template<typename C>
inline
json & operator << (json & j, std::basic_string<C> const & s) throw() { return j << json::string(convert<C,char>(s).c_str()); }
json & operator << (json & j, std::string const & s) throw() { return j << json::string(s.c_str()); }

template<typename C>
inline
json & operator << (json & j, C const * s) throw() { return j << json::string(convert<C,char>(s).c_str()); }
json & operator << (json & j, std::string const * s) throw() { return j << json::string(s->c_str()); }

inline
json & operator << (json & j, std::u16string const & s) throw() { return j << json::string(convert<char16_t,char>(s).c_str()); }

inline
json & operator << (json & j, std::u16string const * s) throw() { return j << json::string(convert<char16_t,char>(*s).c_str()); }

inline
json & operator << (json & j, signed char d) throw() { return j << json::integer(d); }
Expand Down
4 changes: 2 additions & 2 deletions core/src/km_core_state_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <sstream>
#include <memory>
#include <iomanip>
#include <codecvt>

#include "keyman_core.h"
#include "jsonpp.hpp"
Expand All @@ -22,6 +21,7 @@
#include "state.hpp"
#include "vkey_to_contextreset.hpp"
#include "kmx_file.h"
#include "utfcodec.hpp"

using namespace km::core;

Expand Down Expand Up @@ -357,7 +357,7 @@ km_core_cu * km_core_state_context_debug(

km_core_context_items_dispose(context_items);

std::u16string s = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(buffer.str());
std::u16string s = convert<char, char16_t>(buffer.str());

km_core_cu* result = new km_core_cu[s.size() + 1];
s.copy(result, s.size());
Expand Down
1 change: 0 additions & 1 deletion core/src/kmx/kmx_xstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/
#include <vector>
#include <iterator>
#include <codecvt>
#include <locale>
#include "kmx_processevent.h"
#include "utfcodec.hpp"
Expand Down
1 change: 0 additions & 1 deletion core/tests/unit/kmx/kmx_external_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include <map>
#include <iostream>
#include <sstream>

/**
* This test will test the infrastructure around the external event processing
Expand Down
14 changes: 8 additions & 6 deletions core/tests/unit/kmx/kmx_imx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include <test_assert.h>
#include <test_color.h>
#include "../emscripten_filesystem.h"
#include "utfcodec.hpp"

#include <map>
#include <iostream>
#include <sstream>

/** This test will test the infrastructure around IMX third party librays
* and callback. The functions tested are:
Expand Down Expand Up @@ -172,13 +172,15 @@ void test_imx_list(const km::core::path &source_file){

// This keyboard has 4 function names from 2 different libraries in the stores
km_core_keyboard_imx *imx_rule_it = kb_imx_list;
std::stringstream extracted_library_function;
auto x = 0;
for (; imx_rule_it->library_name; ++imx_rule_it) {
extracted_library_function << imx_rule_it->library_name << ":" << imx_rule_it->function_name;
assert(extracted_library_function.str() == expected_imx_map[imx_rule_it->imx_id] );
g_extract_imx_map[imx_rule_it->imx_id] = extracted_library_function.str();
extracted_library_function.str("");
std::u16string str;
str.append(imx_rule_it->library_name);
str.append(u":");
str.append(imx_rule_it->function_name);
auto extracted_library_function = convert<km_core_cu,char>(str);
assert(extracted_library_function == expected_imx_map[imx_rule_it->imx_id] );
g_extract_imx_map[imx_rule_it->imx_id] = extracted_library_function;
++x;
}

Expand Down
5 changes: 2 additions & 3 deletions core/tests/unit/ldml/ldml_test_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <sstream>
#include <string>
#include <type_traits>
#include <codecvt>

#if 0
// TODO-LDML If we need to avoid exceptions in JSON
Expand Down Expand Up @@ -200,7 +199,7 @@ LdmlTestSource::parse_source_string(std::string const &s) {
std::u16string
LdmlTestSource::parse_u8_source_string(std::string const &u8s) {
// convert from utf-8 to utf-16 first
std::u16string s = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.from_bytes(u8s);
std::u16string s = convert<char, char16_t>(u8s);
std::u16string t;
for (auto p = s.begin(); p != s.end(); p++) {
if (*p == '\\') {
Expand All @@ -219,7 +218,7 @@ LdmlTestSource::parse_u8_source_string(std::string const &u8s) {
size_t n;
std::u16string s1 = s.substr(p - s.begin(), 8);
// TODO-LDML: convert back first?
std::string s1b = std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(s1);
std::string s1b = convert<char16_t, char>(s1);
v = std::stoul(s1b, &n, 16);
// Allow deadkey_number (U+0001) characters and onward
assert(v >= 0x0001 && v <= 0x10FFFF);
Expand Down
4 changes: 2 additions & 2 deletions developer/src/ext/json/LICENSE.MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License
MIT License

Copyright (c) 2013-2017 Niels Lohmann
Copyright (c) 2013-2022 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit 571e1fe

Please sign in to comment.