Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #14: Fixing issue with encoding, data only #29

Merged
merged 1 commit into from
Feb 7, 2018
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
Fixes #14
  • Loading branch information
msturdikova committed Feb 7, 2018
commit fb4f85f052cf5d73166ce5561412492c7aabb36e
10 changes: 8 additions & 2 deletions packages/perspective/src/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <emscripten/bind.h>
#include <emscripten/val.h>
#include <perspective/sym_table.h>
#include <codecvt>

using namespace perspective;
using namespace emscripten;
Expand Down Expand Up @@ -347,7 +348,10 @@ _fill_col<std::string>(val dcol, t_col_sptr col, t_bool is_arrow)
} else {
for (auto i = 0; i < nrows; ++i)
{
auto elem = dcol[i].as<std::string>();
std::wstring welem = dcol[i].as<std::wstring>();
typedef std::codecvt_utf8_utf16<wchar_t> utf16convert_type;
std::wstring_convert<utf16convert_type, wchar_t> converter;
std::string elem = converter.to_bytes(welem);
col->set_nth(i, elem);
}
}
Expand Down Expand Up @@ -742,7 +746,9 @@ scalar_to_val(const t_tscalvec& scalars, t_uint32 idx)
case DTYPE_STR:
default:
{
return val(scalar.to_string());
typedef std::codecvt_utf8<wchar_t> utf8convert_type;
std::wstring_convert<utf8convert_type, wchar_t> converter;
return val(converter.from_bytes(scalar.to_string()));
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions packages/perspective/test/js/constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ var meta_4 = {'v' : 'date'};

var csv = "x,y,z\n1,a,true\n2,b,false\n3,c,true\n4,d,false";

var data_6 = [
{'x':'š'}
]

module.exports = (perspective) => {

describe("Execute", function () {
Expand Down Expand Up @@ -183,6 +187,11 @@ module.exports = (perspective) => {
expect([{'v': +(moment(data_5[0]['v'], "MM-DD-YYYY"))}]).toEqual(result2);
});

it("Handles utf16", async function () {
var table = perspective.table(data_6);
let result = await table.view({}).to_json();
expect(data_6).toEqual(result);
});

});

Expand Down