more fixes/tests for empty strings
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9083 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c21c26945c
commit
20339de8b4
6 changed files with 80 additions and 3 deletions
|
|
@ -127,3 +127,23 @@ public:
|
||||||
|
|
||||||
};
|
};
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
%inline %{
|
||||||
|
std::string empty() {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
char *c_empty() {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
char *c_null() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *get_null(const char *a) {
|
||||||
|
return a == 0 ? a : "non-null";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
%}
|
||||||
|
|
|
||||||
|
|
@ -118,3 +118,29 @@ if ($gen1->testl(9234567890121111113) ne 9234567890121111114) {
|
||||||
die ("ulonglong");
|
die ("ulonglong");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (li_std_string::empty() ne "") {
|
||||||
|
die ("empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li_std_string::c_empty() ne "") {
|
||||||
|
die ("c_empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (li_std_string::c_null() ne undef) {
|
||||||
|
die ("c_empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (li_std_string::get_null(li_std_string::c_null()) ne undef) {
|
||||||
|
die ("c_empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li_std_string::get_null(li_std_string::c_empty()) ne "non-null") {
|
||||||
|
die ("c_empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (li_std_string::get_null(li_std_string::empty()) ne "non-null") {
|
||||||
|
die ("c_empty");
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,3 +119,14 @@ if li_std_string.test_reference_input("hello") != "hello":
|
||||||
s = li_std_string.test_reference_inout("hello")
|
s = li_std_string.test_reference_inout("hello")
|
||||||
if s != "hellohello":
|
if s != "hellohello":
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
if li_std_string.empty() != "":
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
|
||||||
|
if li_std_string.c_empty() != "":
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if li_std_string.c_null() != None:
|
||||||
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -111,3 +111,23 @@ s = test_reference_inout("hello")
|
||||||
if (s != "hellohello")
|
if (s != "hellohello")
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if (empty() != "")
|
||||||
|
raise RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
|
if (c_empty() != "")
|
||||||
|
raise RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if (c_null() != nil)
|
||||||
|
raise RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
if (get_null(c_null()) != nil)
|
||||||
|
raise RuntimeError
|
||||||
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ SWIGINTERNINLINE SV *
|
||||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||||
{
|
{
|
||||||
SV *obj = sv_newmortal();
|
SV *obj = sv_newmortal();
|
||||||
if (size && carray) {
|
if (carray) {
|
||||||
if (carray[size - 1] == 0) {
|
if (size && (carray[size - 1] == 0)) {
|
||||||
sv_setpv(obj, carray);
|
sv_setpv(obj, carray);
|
||||||
} else {
|
} else {
|
||||||
char *tmp = %new_array(size + 1, char);
|
char *tmp = %new_array(size + 1, char);
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ SWIG_From_dec(String)(const String& s)
|
||||||
if (s.size()) {
|
if (s.size()) {
|
||||||
return SWIG_FromCharPtrAndSize(s.data(), s.size());
|
return SWIG_FromCharPtrAndSize(s.data(), s.size());
|
||||||
} else {
|
} else {
|
||||||
return SWIG_FromCharPtrAndSize(s.c_str(), 1);
|
return SWIG_FromCharPtrAndSize(s.c_str(), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue