Skip to content

Commit d6e1b6e

Browse files
committed
Submodule utfcpp, to replace <codecvt> utf8 conversion (deprecated in C++ 17, removed in C++ 20)
1 parent fdf17bf commit d6e1b6e

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "third_party/xxHash"]
22
path = third_party/xxHash
33
url = [email protected]:Cyan4973/xxHash.git
4+
[submodule "third_party/utfcpp"]
5+
path = third_party/utfcpp
6+
url = [email protected]:nemtrif/utfcpp.git

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,8 @@ ecbuild_add_option( FEATURE EXTRA_TESTS
317317

318318
### UNICODE support
319319

320-
check_include_file_cxx("codecvt" HAVE_CXX_CODECVT)
321-
322320
ecbuild_add_option( FEATURE UNICODE
323321
DEFAULT ON
324-
CONDITION HAVE_CXX_CODECVT
325322
DESCRIPTION "Add support for Unicode characters in Yaml/JSON parsers" )
326323

327324
### async io support

src/eckit/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,11 @@ if(eckit_HAVE_XXHASH)
763763
endif()
764764
endif()
765765

766+
if(eckit_HAVE_UNICODE)
767+
set_source_files_properties( parser/ObjectParser.cc PROPERTIES
768+
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/third_party/utfcpp/source
769+
)
770+
endif()
766771

767772
list( APPEND eckit_memory_srcs
768773
memory/Builder.h

src/eckit/parser/ObjectParser.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
/// @author Tiago Quintino
1414
/// @date Jun 2012
1515

16+
#include "eckit/parser/ObjectParser.h"
17+
1618
#include "eckit/eckit_config.h"
1719

1820
#if eckit_HAVE_UNICODE
19-
#include <codecvt>
21+
#include <iterator>
22+
#include <string>
23+
24+
#include "utf8.h"
2025
#endif /* eckit_HAVE_UNICODE */
2126

2227
#include <locale>
2328

24-
#include "eckit/parser/ObjectParser.h"
2529
#include "eckit/utils/Translator.h"
2630
#include "eckit/value/Value.h"
2731

@@ -125,9 +129,10 @@ Value ObjectParser::parseNumber() {
125129
}
126130

127131
#if eckit_HAVE_UNICODE
128-
static std::string utf8(uint32_t code) {
129-
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
130-
return conv.to_bytes(char32_t(code));
132+
static std::string utf8_to_string(uint32_t code) {
133+
std::string result;
134+
utf8::append(code, std::back_inserter(result));
135+
return result;
131136
}
132137

133138

@@ -151,9 +156,9 @@ std::string ObjectParser::unicode() {
151156
uint32_t code;
152157
iss >> std::hex >> code;
153158

154-
// std::cout << " [" << code << ", " << utf8(code) << "]" << std::endl;
159+
// std::cout << " [" << code << ", " << utf8_to_string(code) << "]" << std::endl;
155160

156-
return utf8(code);
161+
return utf8_to_string(code);
157162
}
158163
#endif /* eckit_HAVE_UNICODE */
159164

third_party/utfcpp

Submodule utfcpp added at b26a5f7

0 commit comments

Comments
 (0)