From d6a3401d0935e60c17603597a6174c720fab6779 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Thu, 11 Jul 2002 20:16:53 +0000 Subject: [PATCH] Changed the wxDateTime.Parse* methods to return an int that will be -1 on failure, and the index where parsing stopped otherwise. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16138 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- wxPython/CHANGES.txt | 3 + wxPython/src/msw/utils.cpp | 115 ++++++++++++++++--------------------- wxPython/src/utils.i | 56 ++++++++++++++---- 3 files changed, 99 insertions(+), 75 deletions(-) diff --git a/wxPython/CHANGES.txt b/wxPython/CHANGES.txt index 355c5c2a45..21eb15506d 100644 --- a/wxPython/CHANGES.txt +++ b/wxPython/CHANGES.txt @@ -152,6 +152,9 @@ Added a generic static text control to wxPython.lib.stattext. This is so things like Boa and PythonCard can have a static text that can respond to mouse events and etc. +Changed the wxDateTime.Parse* methods to return an int that will be -1 +on failure, and the index where parsing stopped otherwise. + diff --git a/wxPython/src/msw/utils.cpp b/wxPython/src/msw/utils.cpp index 852d4640f5..872cf09c30 100644 --- a/wxPython/src/msw/utils.cpp +++ b/wxPython/src/msw/utils.cpp @@ -5127,10 +5127,16 @@ static PyObject *_wrap_wxDateTime___cmp__(PyObject *self, PyObject *args, PyObje return _resultobj; } -#define wxDateTime_ParseRfc822Date(_swigobj,_swigarg0) (_swigobj->ParseRfc822Date(_swigarg0)) +static int wxDateTime_ParseRfc822Date(wxDateTime *self,const wxString & date) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseRfc822Date(_date); + if (rv == NULL) return -1; + return rv - _date; + } static PyObject *_wrap_wxDateTime_ParseRfc822Date(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + int _result; wxDateTime * _arg0; wxString * _arg1; PyObject * _argo0 = 0; @@ -5154,31 +5160,28 @@ static PyObject *_wrap_wxDateTime_ParseRfc822Date(PyObject *self, PyObject *args } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = new wxString (wxDateTime_ParseRfc822Date(_arg0,*_arg1)); + _result = (int )wxDateTime_ParseRfc822Date(_arg0,*_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; -}{ -#if wxUSE_UNICODE - _resultobj = PyUnicode_FromUnicode(_result->c_str(), _result->Len()); -#else - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); -#endif -} +} _resultobj = Py_BuildValue("i",_result); { if (_obj1) delete _arg1; -} -{ - delete _result; } return _resultobj; } -#define wxDateTime_ParseFormat(_swigobj,_swigarg0,_swigarg1,_swigarg2) (_swigobj->ParseFormat(_swigarg0,_swigarg1,_swigarg2)) +static int wxDateTime_ParseFormat(wxDateTime *self,const wxString & date,const wxString & format,const wxDateTime & dateDef) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseFormat(_date, format, dateDef); + if (rv == NULL) return -1; + return rv - _date; + } static PyObject *_wrap_wxDateTime_ParseFormat(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + int _result; wxDateTime * _arg0; wxString * _arg1; wxString * _arg2 = (wxString *) &wxPyDateFormatStr; @@ -5219,17 +5222,11 @@ static PyObject *_wrap_wxDateTime_ParseFormat(PyObject *self, PyObject *args, Py } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = new wxString (wxDateTime_ParseFormat(_arg0,*_arg1,*_arg2,*_arg3)); + _result = (int )wxDateTime_ParseFormat(_arg0,*_arg1,*_arg2,*_arg3); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; -}{ -#if wxUSE_UNICODE - _resultobj = PyUnicode_FromUnicode(_result->c_str(), _result->Len()); -#else - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); -#endif -} +} _resultobj = Py_BuildValue("i",_result); { if (_obj1) delete _arg1; @@ -5237,17 +5234,20 @@ static PyObject *_wrap_wxDateTime_ParseFormat(PyObject *self, PyObject *args, Py { if (_obj2) delete _arg2; -} -{ - delete _result; } return _resultobj; } -#define wxDateTime_ParseDateTime(_swigobj,_swigarg0) (_swigobj->ParseDateTime(_swigarg0)) +static int wxDateTime_ParseDateTime(wxDateTime *self,const wxString & datetime) { + const wxChar* rv; + const wxChar* _datetime = datetime; + rv = self->ParseDateTime(_datetime); + if (rv == NULL) return -1; + return rv - _datetime; + } static PyObject *_wrap_wxDateTime_ParseDateTime(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + int _result; wxDateTime * _arg0; wxString * _arg1; PyObject * _argo0 = 0; @@ -5271,31 +5271,28 @@ static PyObject *_wrap_wxDateTime_ParseDateTime(PyObject *self, PyObject *args, } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = new wxString (wxDateTime_ParseDateTime(_arg0,*_arg1)); + _result = (int )wxDateTime_ParseDateTime(_arg0,*_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; -}{ -#if wxUSE_UNICODE - _resultobj = PyUnicode_FromUnicode(_result->c_str(), _result->Len()); -#else - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); -#endif -} +} _resultobj = Py_BuildValue("i",_result); { if (_obj1) delete _arg1; -} -{ - delete _result; } return _resultobj; } -#define wxDateTime_ParseDate(_swigobj,_swigarg0) (_swigobj->ParseDate(_swigarg0)) +static int wxDateTime_ParseDate(wxDateTime *self,const wxString & date) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseDate(_date); + if (rv == NULL) return -1; + return rv - _date; + } static PyObject *_wrap_wxDateTime_ParseDate(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + int _result; wxDateTime * _arg0; wxString * _arg1; PyObject * _argo0 = 0; @@ -5319,31 +5316,28 @@ static PyObject *_wrap_wxDateTime_ParseDate(PyObject *self, PyObject *args, PyOb } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = new wxString (wxDateTime_ParseDate(_arg0,*_arg1)); + _result = (int )wxDateTime_ParseDate(_arg0,*_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; -}{ -#if wxUSE_UNICODE - _resultobj = PyUnicode_FromUnicode(_result->c_str(), _result->Len()); -#else - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); -#endif -} +} _resultobj = Py_BuildValue("i",_result); { if (_obj1) delete _arg1; -} -{ - delete _result; } return _resultobj; } -#define wxDateTime_ParseTime(_swigobj,_swigarg0) (_swigobj->ParseTime(_swigarg0)) +static int wxDateTime_ParseTime(wxDateTime *self,const wxString & time) { + const wxChar* rv; + const wxChar* _time = time; + rv = self->ParseTime(_time); + if (rv == NULL) return -1; + return rv - _time; + } static PyObject *_wrap_wxDateTime_ParseTime(PyObject *self, PyObject *args, PyObject *kwargs) { PyObject * _resultobj; - wxString * _result; + int _result; wxDateTime * _arg0; wxString * _arg1; PyObject * _argo0 = 0; @@ -5367,23 +5361,14 @@ static PyObject *_wrap_wxDateTime_ParseTime(PyObject *self, PyObject *args, PyOb } { PyThreadState* __tstate = wxPyBeginAllowThreads(); - _result = new wxString (wxDateTime_ParseTime(_arg0,*_arg1)); + _result = (int )wxDateTime_ParseTime(_arg0,*_arg1); wxPyEndAllowThreads(__tstate); if (PyErr_Occurred()) return NULL; -}{ -#if wxUSE_UNICODE - _resultobj = PyUnicode_FromUnicode(_result->c_str(), _result->Len()); -#else - _resultobj = PyString_FromStringAndSize(_result->c_str(), _result->Len()); -#endif -} +} _resultobj = Py_BuildValue("i",_result); { if (_obj1) delete _arg1; -} -{ - delete _result; } return _resultobj; } diff --git a/wxPython/src/utils.i b/wxPython/src/utils.i index f90583d8af..c05383ea0b 100644 --- a/wxPython/src/utils.i +++ b/wxPython/src/utils.i @@ -773,32 +773,68 @@ public: " // ------------------------------------------------------------------------ - // conversion to/from text: all conversions from text return the pointer to - // the next character following the date specification (i.e. the one where - // the scan had to stop) or NULL on failure. + // conversion from text: all conversions from text return -1 on failure, + // or the index in the string where the next character following the date + // specification (i.e. the one where the scan had to stop) is located. + + %addmethods { // parse a string in RFC 822 format (found e.g. in mail headers and // having the form "Wed, 10 Feb 1999 19:07:07 +0100") - wxString ParseRfc822Date(const wxString& date); + int ParseRfc822Date(const wxString& date) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseRfc822Date(_date); + if (rv == NULL) return -1; + return rv - _date; + } + // parse a date/time in the given format (see strptime(3)), fill in // the missing (in the string) fields with the values of dateDef (by // default, they will not change if they had valid values or will // default to Today() otherwise) - wxString ParseFormat(const wxString& date, - const wxString& format = wxPyDateFormatStr, - const wxDateTime& dateDef = wxDefaultDateTime); + int ParseFormat(const wxString& date, + const wxString& format = wxPyDateFormatStr, + const wxDateTime& dateDef = wxDefaultDateTime) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseFormat(_date, format, dateDef); + if (rv == NULL) return -1; + return rv - _date; + } // parse a string containing the date/time in "free" format, this // function will try to make an educated guess at the string contents - wxString ParseDateTime(const wxString& datetime); + int ParseDateTime(const wxString& datetime) { + const wxChar* rv; + const wxChar* _datetime = datetime; + rv = self->ParseDateTime(_datetime); + if (rv == NULL) return -1; + return rv - _datetime; + } + // parse a string containing the date only in "free" format (less // flexible than ParseDateTime) - wxString ParseDate(const wxString& date); + int ParseDate(const wxString& date) { + const wxChar* rv; + const wxChar* _date = date; + rv = self->ParseDate(_date); + if (rv == NULL) return -1; + return rv - _date; + } // parse a string containing the time only in "free" format - wxString ParseTime(const wxString& time); + int ParseTime(const wxString& time) { + const wxChar* rv; + const wxChar* _time = time; + rv = self->ParseTime(_time); + if (rv == NULL) return -1; + return rv - _time; + } + } + // this function accepts strftime()-like format string (default // argument corresponds to the preferred date and time representation -- 2.45.2