Skip to content
Merged
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
4 changes: 4 additions & 0 deletions src/openvic-dataloader/detail/ConvertGbk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ namespace ovdl::convert::gbk {
#else
#error "GBK conversion not supported on this platform"
#endif
if (in_size > 0 && out_size > 0 && in_buffer != end) {
return lexy::buffer<Encoding, MemoryResource> { resource };
}

return lexy::buffer<Encoding, MemoryResource> { out_builder.data(), static_cast<size_t>(out_buffer - out_builder.data()), resource };
} else {
return lexy::make_buffer_from_raw<Encoding, Endian>(_memory, size, resource);
Expand Down
11 changes: 8 additions & 3 deletions src/openvic-dataloader/detail/ParseHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,22 @@ namespace ovdl::detail {
};

template<detail::IsStateType State>
static constexpr auto generate_gbk_state(State* state, const char* path, auto&& buffer, Encoding encoding) {
static auto generate_gbk_state(State* state, const char* path, auto&& buffer, Encoding encoding) {
size_t size = buffer.size();
lexy::buffer<lexy::utf8_char_encoding, void> utf8_buffer =
convert::gbk::make_buffer_from_raw<lexy::utf8_char_encoding>(encoding, std::move(buffer).release(), size);
if (utf8_buffer.data() == nullptr) {
state->logger().error("conversion from GBK to UTF-8 failed");
}
if (path[0] != '\0') {
*state = {
path,
convert::gbk::make_buffer_from_raw<lexy::utf8_char_encoding>(encoding, std::move(buffer).release(), size),
std::move(utf8_buffer),
encoding
};
return;
}
*state = { convert::gbk::make_buffer_from_raw<lexy::utf8_char_encoding>(encoding, std::move(buffer).release(), size), encoding };
*state = { std::move(utf8_buffer), encoding };
};

template<detail::IsStateType State>
Expand Down