Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Use wstring in emscripten binding
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbrunsfeld committed Nov 8, 2017
1 parent a47710a commit 3ea87c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/bindings/em/auto-wrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,31 +162,31 @@ struct em_wrap_type<MarkerIndex::BoundaryQueryResult> : public em_wrap_type_base
};

template <>
struct em_wrap_type<Text> : public em_wrap_type_base<Text, std::string> {
static Text receive(std::string const &str) {
struct em_wrap_type<Text> : public em_wrap_type_base<Text, std::wstring> {
static Text receive(std::wstring const &str) {
return Text(str.begin(), str.end());
}

static std::string transmit(Text const &text) {
return std::string(text.begin(), text.end());
static std::wstring transmit(Text const &text) {
return std::wstring(text.begin(), text.end());
}
};

template <>
struct em_wrap_type<std::u16string> : public em_wrap_type_base<std::u16string, std::string> {
static std::u16string receive(std::string const &str) {
struct em_wrap_type<std::u16string> : public em_wrap_type_base<std::u16string, std::wstring> {
static std::u16string receive(std::wstring const &str) {
return std::u16string(str.begin(), str.end());
}

static std::string transmit(std::u16string const &text) {
return std::string(text.begin(), text.end());
static std::wstring transmit(std::u16string const &text) {
return std::wstring(text.begin(), text.end());
}
};

template <>
struct em_wrap_type<Text *> : public em_wrap_type_base<Text *, emscripten::val> {
static Text * receive(emscripten::val const &value) {
return new Text(em_wrap_type<Text>::receive(value.as<std::string>()));
return new Text(em_wrap_type<Text>::receive(value.as<std::wstring>()));
}

static emscripten::val transmit(Text *text) {
Expand Down
6 changes: 3 additions & 3 deletions src/bindings/em/text-buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
using std::string;
using std::u16string;

static TextBuffer *construct(const std::string &text) {
static TextBuffer *construct(const std::wstring &text) {
return new TextBuffer(u16string(text.begin(), text.end()));
}

static emscripten::val find_sync(TextBuffer &buffer, std::string js_pattern, Range range) {
static emscripten::val find_sync(TextBuffer &buffer, std::wstring js_pattern, Range range) {
u16string pattern(js_pattern.begin(), js_pattern.end());
u16string error_message;
Regex regex(pattern, &error_message);
Expand All @@ -25,7 +25,7 @@ static emscripten::val find_sync(TextBuffer &buffer, std::string js_pattern, Ran
return emscripten::val::null();
}

static emscripten::val find_all_sync(TextBuffer &buffer, std::string js_pattern, Range range) {
static emscripten::val find_all_sync(TextBuffer &buffer, std::wstring js_pattern, Range range) {
u16string pattern(js_pattern.begin(), js_pattern.end());
u16string error_message;
Regex regex(pattern, &error_message);
Expand Down

0 comments on commit 3ea87c5

Please sign in to comment.