| | 32 | namespace std { |
| | 33 | %typemap(in) string |
| | 34 | %{ if(!$input) { |
| | 35 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); |
| | 36 | return $null; |
| | 37 | } |
| | 38 | size_t $1_jlen = jenv->GetStringLength($input); |
| | 39 | const jchar * $1_jstr = jenv->GetStringCritical($input, 0); |
| | 40 | if (!$1_jstr) return $null; |
| | 41 | $1.resize(0); |
| | 42 | for (size_t i = 0; i != $1_jlen; ++i) { |
| | 43 | unsigned ch = $1_jstr[i]; |
| | 44 | if ((ch & 0xfc00) == 0xd800 && ++i != $1_jlen) { |
| | 45 | ch = (ch << 10) + $1_jstr[i] - 0x035fdc00; |
| | 46 | } |
| | 47 | Xapian::Unicode::append_utf8($1, ch); |
| | 48 | } |
| | 49 | jenv->ReleaseStringCritical($input, $1_jstr); %} |
| | 50 | |
| | 51 | %typemap(out) string |
| | 52 | %{ jchar * $1_ustr = new jchar[$1.size()]; |
| | 53 | size_t $1_ulen = 0; |
| | 54 | for (Xapian::Utf8Iterator $1_uit($1); $1_uit != Xapian::Utf8Iterator(); ++$1_uit) { |
| | 55 | unsigned ch = *$1_uit; |
| | 56 | if (ch >= 0x10000) { |
| | 57 | $1_ustr[$1_ulen++] = 0xdbc0 + (ch >> 10); |
| | 58 | ch = 0xdc00 | (ch & 0x3ff); |
| | 59 | } |
| | 60 | $1_ustr[$1_ulen++] = ch; |
| | 61 | } |
| | 62 | $result = jenv->NewString($1_ustr, $1_ulen); |
| | 63 | delete[] $1_ustr; %} |
| | 64 | |
| | 65 | %typemap(in) const string & |
| | 66 | %{ if(!$input) { |
| | 67 | SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null std::string"); |
| | 68 | return $null; |
| | 69 | } |
| | 70 | size_t $1_jlen = jenv->GetStringLength($input); |
| | 71 | const jchar * $1_jstr = jenv->GetStringCritical($input, 0); |
| | 72 | if (!$1_jstr) return $null; |
| | 73 | std::string $1_str; |
| | 74 | for (size_t i = 0; i != $1_jlen; ++i) { |
| | 75 | unsigned ch = $1_jstr[i]; |
| | 76 | if ((ch & 0xfc00) == 0xd800 && ++i != $1_jlen) { |
| | 77 | ch = (ch << 10) + $1_jstr[i] - 0x035fdc00; |
| | 78 | } |
| | 79 | Xapian::Unicode::append_utf8($1_str, ch); |
| | 80 | } |
| | 81 | $1 = &$1_str; |
| | 82 | jenv->ReleaseStringCritical($input, $1_jstr); %} |
| | 83 | } |
| | 84 | |