swig snipe (was Re: [pyicu-dev] getCollationKey)
Andi Vajda
vajda at osafoundation.org
Wed Nov 30 10:49:48 PST 2005
On Wed, 30 Nov 2005, Jim Fulton wrote:
>>>>> from PyICU import *
>>>>> c=Collator.createInstance()
>>>>> ck=CollationKey()
>>>>> ck1=CollationKey()
>>>>> c.getCollationKey('a string', ck)
>
> This is a swig-onic api. A Pythonic api would, of course be:
>
>>>> ck = c.getCollationKey('a string')
>
> which is much better IMO.
True, it is much better. And look at the attached patch to see how simple it
is to add that overload.
Andi..
-------------- next part --------------
Index: collator.i
===================================================================
--- collator.i (revision 47)
+++ collator.i (working copy)
@@ -84,6 +84,7 @@
CollationKey2 &getCollationKey(UnicodeString &, CollationKey &, UErrorCode);
CollationKey2 &getCollationKey(_PyString, CollationKey &, UErrorCode);
+ CollationKey getCollationKey(_PyString, _CollationKey, UErrorCode);
UBool greater(UnicodeString &, UnicodeString &);
UBool greaterOrEqual(UnicodeString &, UnicodeString &);
Index: common.i
===================================================================
--- common.i (revision 45)
+++ common.i (working copy)
@@ -646,7 +646,11 @@
PyString_AsStringAndSize($input, &$1, &$2);
}
+%typemap(in, numinputs=0) (_CollationKey) {
+}
+
+
%exception
{
try {
Index: common.h
===================================================================
--- common.h (revision 44)
+++ common.h (working copy)
@@ -109,6 +109,7 @@
typedef icu::UnicodeString UnicodeString3;
typedef icu::UnicodeString _PyString;
typedef icu::CollationKey CollationKey2;
+typedef icu::CollationKey _CollationKey;
typedef const UChar *ISO3Code;
typedef icu::Formattable Formattable2;
typedef icu::Formattable *FormattableArray3;
More information about the pyicu-dev
mailing list