Skip to content

Commit a598abe

Browse files
committed
Java wstring throws typemap improvements
Unicode still not working, but works now for ASCII charset.
1 parent fd846be commit a598abe

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Lib/java/std_wstring.i

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,12 @@ class wstring;
8888
//%typemap(typecheck) wstring = wchar_t *;
8989

9090
%typemap(throws) wstring
91-
%{ std::string message($1.begin(), $1.end());
92-
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
93-
return $null; %}
91+
%{std::string message($1.size(), '\0');
92+
for (size_t i = 0; i < $1.size(); ++i) {
93+
message[i] = (char)$1[i];
94+
}
95+
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
96+
return $null; %}
9497

9598
// const wstring &
9699
%typemap(jni) const wstring & "jstring"
@@ -166,9 +169,12 @@ class wstring;
166169
//%typemap(typecheck) const wstring & = wchar_t *;
167170

168171
%typemap(throws) const wstring &
169-
%{ std::string message($1.begin(), $1.end());
170-
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
171-
return $null; %}
172+
%{std::string message($1.size(), '\0');
173+
for (size_t i = 0; i < $1.size(); ++i) {
174+
message[i] = (char)$1[i];
175+
}
176+
SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, message.c_str());
177+
return $null; %}
172178

173179
}
174180

0 commit comments

Comments
 (0)