From: <cg...@us...> - 2006-07-20 00:50:06
|
Revision: 2848 Author: cgroves Date: 2006-07-19 17:49:59 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/jython/?rev=2848&view=rev Log Message: ----------- added implemtation of translate for unicode separate from string from patch 1515650. Left the patch open since this should probably be applied to trunk too Modified Paths: -------------- branches/2.3/src/org/python/core/PyUnicode.java branches/2.3/src/templates/unicode.expose Modified: branches/2.3/src/org/python/core/PyUnicode.java =================================================================== --- branches/2.3/src/org/python/core/PyUnicode.java 2006-07-20 00:28:11 UTC (rev 2847) +++ branches/2.3/src/org/python/core/PyUnicode.java 2006-07-20 00:49:59 UTC (rev 2848) @@ -1,5 +1,7 @@ package org.python.core; +import org.python.modules._codecs; + /** * a builtin python unicode string. */ @@ -2583,76 +2585,17 @@ return new exposed_translate((PyUnicode)self,info); } - public PyObject __call__(PyObject arg0,PyObject arg1) { - try { - return new PyUnicode(self.unicode_translate(arg0.asString(0),arg1.asString(1))); - } catch (PyObject.ConversionException e) { - String msg; - switch (e.index) { - case 0: - case 1: - msg="expected a string"; - break; - default: - msg="xxx"; - } - throw Py.TypeError(msg); - } - } - - public PyObject inst_call(PyObject gself,PyObject arg0,PyObject arg1) { - PyUnicode self=(PyUnicode)gself; - try { - return new PyUnicode(self.unicode_translate(arg0.asString(0),arg1.asString(1))); - } catch (PyObject.ConversionException e) { - String msg; - switch (e.index) { - case 0: - case 1: - msg="expected a string"; - break; - default: - msg="xxx"; - } - throw Py.TypeError(msg); - } - } - public PyObject __call__(PyObject arg0) { - try { - return new PyUnicode(self.unicode_translate(arg0.asString(0))); - } catch (PyObject.ConversionException e) { - String msg; - switch (e.index) { - case 0: - msg="expected a string"; - break; - default: - msg="xxx"; - } - throw Py.TypeError(msg); - } + return new PyUnicode(self.unicode_translate(arg0)); } public PyObject inst_call(PyObject gself,PyObject arg0) { PyUnicode self=(PyUnicode)gself; - try { - return new PyUnicode(self.unicode_translate(arg0.asString(0))); - } catch (PyObject.ConversionException e) { - String msg; - switch (e.index) { - case 0: - msg="expected a string"; - break; - default: - msg="xxx"; - } - throw Py.TypeError(msg); - } + return new PyUnicode(self.unicode_translate(arg0)); } } - dict.__setitem__("translate",new PyMethodDescr("translate",PyUnicode.class,1,2,new exposed_translate(null,null))); + dict.__setitem__("translate",new PyMethodDescr("translate",PyUnicode.class,1,1,new exposed_translate(null,null))); class exposed_upper extends PyBuiltinFunctionNarrow { private PyUnicode self; @@ -2846,8 +2789,7 @@ } protected PyObject pyget(int i) { - //FIXME: should pass unicode back. - return super.pyget(i); + return Py.makeCharacter(string.charAt(i), true); } final boolean unicode___contains__(PyObject o) { @@ -3056,14 +2998,10 @@ return str_endswith(suffix, start, end); } - final String unicode_translate(String table) { - return str_translate(table); + final String unicode_translate(PyObject table) { + return _codecs.charmap_decode(string, "ignore", table, true).__getitem__(0).toString(); } - final String unicode_translate(String table, String deletechars) { - return str_translate(table, deletechars); - } - final boolean unicode_islower() { return str_islower(); } Modified: branches/2.3/src/templates/unicode.expose =================================================================== --- branches/2.3/src/templates/unicode.expose 2006-07-20 00:28:11 UTC (rev 2847) +++ branches/2.3/src/templates/unicode.expose 2006-07-20 00:49:59 UTC (rev 2848) @@ -50,7 +50,7 @@ expose_meth: :u strip S? expose_meth: :u swapcase expose_meth: :u title -expose_meth: :u translate s s? +expose_meth: :u translate o expose_meth: :u upper expose_meth: :u zfill i expose_new_immutable: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |