Skip to content
Snippets Groups Projects
Commit 368fb5f0 authored by ilor's avatar ilor
Browse files

simple swig icu UnicodeString wrapper with __str__, __unicode__ and length()

parent dc74349c
No related merge requests found
......@@ -4,6 +4,7 @@
%module corpus2
%include "boost_shared_ptr.i"
%include "unicodestring.i"
%include "libcorpus2exception.i"
%include "libcorpusannotatedsentence.i"
%include "libcorpusannotationchannel.i"
......
#ifndef SWIG_UNICODESTRING_I
#define SWIG_UNICODESTRING_I
%module unicodestring
%{
#include <unicode/unistr.h>
%}
%include "std_string.i"
%include "std_except.i"
class UnicodeString {
public:
int length();
UChar* getBuffer();
UChar* getTerminatedBuffer();
%pythoncode %{
def __unicode__(self):
return self.as_utf16().decode('utf16')
def __str__(self):
return self.as_utf8()
%}
};
%extend UnicodeString {
std::string as_utf16() {
return std::string((char*)self->getTerminatedBuffer(), self->length()*2);
}
std::string as_utf8() {
std::string r;
self->toUTF8String(r);
return r;
}
}
#endif /* SWIG_UNICODESTRING_I */
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment