summaryrefslogtreecommitdiff
path: root/python/string.cc
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-11-24 10:00:17 +0000
committerArch Librarian <arch@canonical.com>2004-11-24 10:00:17 +0000
commit507d25595a7e989139b9c425b39f02ee48fa033e (patch)
treeb6d9a27db1078d62df8efe68a853165f324bfb60 /python/string.cc
downloadpython-apt-507d25595a7e989139b9c425b39f02ee48fa033e.tar.gz
Initial revision
Author: jgg Date: 2001-02-20 06:32:01 GMT Initial revision
Diffstat (limited to 'python/string.cc')
-rw-r--r--python/string.cc96
1 files changed, 96 insertions, 0 deletions
diff --git a/python/string.cc b/python/string.cc
new file mode 100644
index 00000000..7564899b
--- /dev/null
+++ b/python/string.cc
@@ -0,0 +1,96 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: string.cc,v 1.1 2001/02/20 06:32:01 jgg Exp $
+/* ######################################################################
+
+ string - Mappings for the string functions that are worthwile for
+ Python users
+
+ ##################################################################### */
+ /*}}}*/
+// Include Files /*{{{*/
+#include "apt_pkgmodule.h"
+#include "generic.h"
+
+#include <apt-pkg/strutl.h>
+
+#include <python/Python.h>
+ /*}}}*/
+
+// Templated function /*{{{*/
+/* Macro for the generic string in string out function */
+#define MkStr(Python,CFunc) \
+PyObject *Python(PyObject *Self,PyObject *Args) \
+{ \
+ char *Str = 0; \
+ if (PyArg_ParseTuple(Args,"s",&Str) == 0) \
+ return 0; \
+ return CppPyString(CFunc(Str)); \
+}
+
+#define MkInt(Python,CFunc) \
+PyObject *Python(PyObject *Self,PyObject *Args) \
+{ \
+ int Val = 0; \
+ if (PyArg_ParseTuple(Args,"i",&Val) == 0) \
+ return 0; \
+ return CppPyString(CFunc(Val)); \
+}
+
+MkStr(StrDeQuote,DeQuoteString);
+MkStr(StrBase64Encode,Base64Encode);
+MkStr(StrURItoFileName,URItoFileName);
+
+//MkFloat(StrSizeToStr,SizeToStr);
+MkInt(StrTimeToStr,TimeToStr);
+MkInt(StrTimeRFC1123,TimeRFC1123);
+ /*}}}*/
+
+// Other String functions /*{{{*/
+PyObject *StrSizeToStr(PyObject *Self,PyObject *Args)
+{
+ PyObject *Obj;
+ if (PyArg_ParseTuple(Args,"O",&Obj) == 0)
+ return 0;
+ if (PyInt_Check(Obj))
+ return CppPyString(SizeToStr(PyInt_AS_LONG(Obj)));
+ if (PyFloat_Check(Obj))
+ return CppPyString(SizeToStr(PyFloat_AS_DOUBLE(Obj)));
+
+ PyErr_SetString(PyExc_TypeError,"Only understand integers and floats");
+ return 0;
+}
+
+PyObject *StrQuoteString(PyObject *Self,PyObject *Args)
+{
+ char *Str = 0;
+ char *Bad = 0;
+ if (PyArg_ParseTuple(Args,"ss",&Str,&Bad) == 0)
+ return 0;
+ return CppPyString(QuoteString(Str,Bad));
+}
+
+PyObject *StrStringToBool(PyObject *Self,PyObject *Args)
+{
+ char *Str = 0;
+ if (PyArg_ParseTuple(Args,"s",&Str) == 0)
+ return 0;
+ return Py_BuildValue("i",StringToBool(Str));
+}
+
+PyObject *StrStrToTime(PyObject *Self,PyObject *Args)
+{
+ char *Str = 0;
+ if (PyArg_ParseTuple(Args,"s",&Str) == 0)
+ return 0;
+
+ time_t Result;
+ if (StrToTime(Str,Result) == false)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ return Py_BuildValue("i",Result);
+}
+ /*}}}*/