Skip to content

Commit

Permalink
chore(core): update core to C++17 fixes
Browse files Browse the repository at this point in the history
- remove some tangled templates in jsonpp
- remove one unneeded include of sstream, and rewrite another as a string conversion.

Fixes: #8800
  • Loading branch information
srl295 committed May 13, 2024
1 parent 52c65c2 commit d3c9fbb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
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
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

0 comments on commit d3c9fbb

Please sign in to comment.