abandon attempts to make wxAnyStrPtr behave as bool: user-defined logical operators don't short circuit silently breaking existing code so it is better to not provide them at all; instead simply return bool from the new versions taking wxString::const_iterator; advise to use the new versions in the new code and so in our own files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59829 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
9c4ae52877
commit
c398434d92
@ -39,6 +39,9 @@ changes:
|
||||
the returned string could be NULL and so a separate helper class is used. If
|
||||
you obtain compilation errors because of this, you can always correct them by
|
||||
explicitly assigning the function return value to a variable of wanted type.
|
||||
A slightly more intrusive but better solution is to use ParseXXX() version
|
||||
with wxString::const_iterator output parameter which simply returns bool to
|
||||
indicate the parsing success.
|
||||
|
||||
- Some structure fields which used to be of type "const wxChar *" (such as
|
||||
wxCmdLineEntryDesc::shortName, longName and description fields) are now of
|
||||
|
@ -136,13 +136,5 @@ private:
|
||||
wxDECLARE_NO_ASSIGN_CLASS(wxAnyStrPtr);
|
||||
};
|
||||
|
||||
// at least for VC6 and VC7 these operators are needed too, otherwise boolean
|
||||
// expressions involving wxAnyStrPtr don't compile because of ambiguity between
|
||||
// built-in overloads of these operators for (bool, bool/char*/wchar_t*)
|
||||
inline bool operator||(const wxAnyStrPtr& p, bool v) { return (bool)p || v; }
|
||||
inline bool operator||(bool v, const wxAnyStrPtr& p) { return v || (bool)p; }
|
||||
inline bool operator&&(const wxAnyStrPtr& p, bool v) { return (bool)p && v; }
|
||||
inline bool operator&&(bool v, const wxAnyStrPtr& p) { return v && (bool)p; }
|
||||
|
||||
#endif // _WX_ANYSTR_H_
|
||||
|
||||
|
@ -1099,36 +1099,41 @@ public:
|
||||
inline wxTimeSpan Subtract(const wxDateTime& dt) const;
|
||||
inline wxTimeSpan operator-(const wxDateTime& dt2) const;
|
||||
|
||||
// conversion to/from text: all conversions from text return an object
|
||||
// representing the next character following the date specification (i.e.
|
||||
// the one where the scan had to stop) or a special NULL-like object
|
||||
// on failure -- this object is necessary to preserve compatibility with
|
||||
// the existing code assigning the return value of these functions to
|
||||
// either char* or wxChar* (new code should treat the return value as bool
|
||||
// and use end parameter to retrieve the end of the scan)
|
||||
// conversion to/from text
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// all conversions functions return true to indicate whether parsing
|
||||
// succeeded or failed and fill in the provided end iterator, which must
|
||||
// not be NULL, with the location of the character where the parsing
|
||||
// stopped (this will be end() of the passed string if everything was
|
||||
// parsed)
|
||||
|
||||
// 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")
|
||||
wxAnyStrPtr ParseRfc822Date(const wxString& date,
|
||||
wxString::const_iterator *end = NULL);
|
||||
bool ParseRfc822Date(const wxString& date,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
// 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)
|
||||
wxAnyStrPtr ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
const wxDateTime& dateDef = wxDefaultDateTime,
|
||||
wxString::const_iterator *end = NULL);
|
||||
bool ParseFormat(const wxString& date,
|
||||
const wxString& format,
|
||||
const wxDateTime& dateDef,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
wxAnyStrPtr ParseFormat(const wxString& date,
|
||||
const wxString& format,
|
||||
wxString::const_iterator *end)
|
||||
bool ParseFormat(const wxString& date,
|
||||
const wxString& format,
|
||||
wxString::const_iterator *end)
|
||||
{
|
||||
return ParseFormat(date, format, wxDefaultDateTime, end);
|
||||
}
|
||||
|
||||
bool ParseFormat(const wxString& date,
|
||||
wxString::const_iterator *end)
|
||||
{
|
||||
return ParseFormat(date, wxDefaultDateTimeFormat, wxDefaultDateTime, end);
|
||||
}
|
||||
|
||||
// parse a string containing date, time or both in ISO 8601 format
|
||||
//
|
||||
@ -1136,49 +1141,36 @@ public:
|
||||
// provide compatibility overloads for them
|
||||
bool ParseISODate(const wxString& date)
|
||||
{
|
||||
// FIXME-VC6: notice that writing "return ParseFormat() && ..." crashes
|
||||
// VC6 with internal compiler error so don't attempt to
|
||||
// simplify this code like this
|
||||
|
||||
wxString::const_iterator end;
|
||||
if ( !ParseFormat(date, wxS("%Y-%m-%d"), &end) )
|
||||
return false;
|
||||
|
||||
return end == date.end();
|
||||
return ParseFormat(date, wxS("%Y-%m-%d"), &end) && end == date.end();
|
||||
}
|
||||
|
||||
bool ParseISOTime(const wxString& time)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
if ( !ParseFormat(time, wxS("%H:%M:%S"), &end) )
|
||||
return false;
|
||||
|
||||
return end == time.end();
|
||||
return ParseFormat(time, wxS("%H:%M:%S"), &end) && end == time.end();
|
||||
}
|
||||
|
||||
bool ParseISOCombined(const wxString& datetime, char sep = 'T')
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
const wxString fmt = wxS("%Y-%m-%d") + wxString(sep) + wxS("%H:%M:%S");
|
||||
if ( !ParseFormat(datetime, fmt, &end) )
|
||||
return false;
|
||||
|
||||
return end == datetime.end();
|
||||
return ParseFormat(datetime, fmt, &end) && end == datetime.end();
|
||||
}
|
||||
|
||||
// parse a string containing the date/time in "free" format, this
|
||||
// function will try to make an educated guess at the string contents
|
||||
wxAnyStrPtr ParseDateTime(const wxString& datetime,
|
||||
wxString::const_iterator *end = NULL);
|
||||
bool ParseDateTime(const wxString& datetime,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
// parse a string containing the date only in "free" format (less
|
||||
// flexible than ParseDateTime)
|
||||
wxAnyStrPtr ParseDate(const wxString& date,
|
||||
wxString::const_iterator *end = NULL);
|
||||
bool ParseDate(const wxString& date,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
// parse a string containing the time only in "free" format
|
||||
wxAnyStrPtr ParseTime(const wxString& time,
|
||||
wxString::const_iterator *end = NULL);
|
||||
bool ParseTime(const wxString& time,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
|
||||
// this function accepts strftime()-like format string (default
|
||||
@ -1203,6 +1195,52 @@ public:
|
||||
wxString FormatISOCombined(char sep = 'T') const
|
||||
{ return FormatISODate() + sep + FormatISOTime(); }
|
||||
|
||||
|
||||
// backwards compatible versions of the parsing functions: they return an
|
||||
// object representing the next character following the date specification
|
||||
// (i.e. the one where the scan had to stop) or a special NULL-like object
|
||||
// on failure
|
||||
//
|
||||
// they're not deprecated because a lot of existing code uses them and
|
||||
// there is no particular harm in keeping them but you should still prefer
|
||||
// the versions above in the new code
|
||||
wxAnyStrPtr ParseRfc822Date(const wxString& date)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
return ParseRfc822Date(date, &end) ? wxAnyStrPtr(date, end)
|
||||
: wxAnyStrPtr();
|
||||
}
|
||||
|
||||
wxAnyStrPtr ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
const wxDateTime& dateDef = wxDefaultDateTime)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
return ParseFormat(date, format, dateDef, &end) ? wxAnyStrPtr(date, end)
|
||||
: wxAnyStrPtr();
|
||||
}
|
||||
|
||||
wxAnyStrPtr ParseDateTime(const wxString& datetime)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
return ParseDateTime(datetime, &end) ? wxAnyStrPtr(datetime, end)
|
||||
: wxAnyStrPtr();
|
||||
}
|
||||
|
||||
wxAnyStrPtr ParseDate(const wxString& date)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
return ParseDate(date, &end) ? wxAnyStrPtr(date, end)
|
||||
: wxAnyStrPtr();
|
||||
}
|
||||
|
||||
wxAnyStrPtr ParseTime(const wxString& time)
|
||||
{
|
||||
wxString::const_iterator end;
|
||||
return ParseTime(time, &end) ? wxAnyStrPtr(time, end)
|
||||
: wxAnyStrPtr();
|
||||
}
|
||||
|
||||
// implementation
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
@ -812,8 +812,7 @@ public:
|
||||
|
||||
@see Format()
|
||||
*/
|
||||
const char* ParseDate(const wxString& date,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseDate(const wxString& date, wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
Parses the string @a datetime containing the date and time in free
|
||||
@ -827,8 +826,7 @@ public:
|
||||
See ParseFormat() for the description of function parameters and return
|
||||
value.
|
||||
*/
|
||||
const char* ParseDateTime(const wxString& datetime,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseDateTime(const wxString& datetime, wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
This function parses the string @a date according to the given
|
||||
@ -849,12 +847,7 @@ public:
|
||||
@a dateDef. If it is not specified, Today() is used as the default
|
||||
date.
|
||||
|
||||
Notice that the return value of this method is not actually a pointer
|
||||
but rather an object of a special proxy class which is convertible to
|
||||
either @c char* or @c wchar_t* pointer. This is needed for
|
||||
compatibility with the existing code but the new code should use @a end
|
||||
parameter instead and just test whether the return value is @NULL or
|
||||
not, e.g.:
|
||||
Example of using this function:
|
||||
@code
|
||||
wxDateTime dt;
|
||||
wxString str = "...";
|
||||
@ -875,26 +868,32 @@ public:
|
||||
Used to fill in the date components not specified in the @a date
|
||||
string.
|
||||
@param end
|
||||
If non-@NULL, will be filled with the iterator pointing to the
|
||||
location where the parsing stopped. If the entire string was
|
||||
consumed, it is set to @c date.end().
|
||||
Will be filled with the iterator pointing to the location where the
|
||||
parsing stopped if the function returns @true. If the entire string
|
||||
was consumed, it is set to @c date.end(). Notice that this argument
|
||||
must be non-@NULL.
|
||||
@return
|
||||
Pointer-like object indicating the location where the scan stopped
|
||||
if parsing was successful or @NULL-like otherwise.
|
||||
@true if at least part of the string was parsed successfully,
|
||||
@false otherwise.
|
||||
|
||||
@see Format()
|
||||
*/
|
||||
const char* ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
const wxDateTime& dateDef = wxDefaultDateTime,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
const wxDateTime& dateDef = wxDefaultDateTime,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
@overload
|
||||
*/
|
||||
const char* ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseFormat(const wxString& date,
|
||||
const wxString& format = wxDefaultDateTimeFormat,
|
||||
wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
@overload
|
||||
*/
|
||||
bool ParseFormat(const wxString& date, wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
This function parses the string containing the date and time in ISO
|
||||
@ -944,8 +943,7 @@ public:
|
||||
See ParseFormat() for the description of function parameters and return
|
||||
value.
|
||||
*/
|
||||
const char* ParseRfc822Date(const wxString& date,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseRfc822Date(const wxString& date, wxString::const_iterator *end);
|
||||
|
||||
/**
|
||||
This functions is like ParseDateTime(), but only allows the time to be
|
||||
@ -954,8 +952,7 @@ public:
|
||||
See ParseFormat() for the description of function parameters and return
|
||||
value.
|
||||
*/
|
||||
const char* ParseTime(const wxString& time,
|
||||
wxString::const_iterator* end = NULL);
|
||||
bool ParseTime(const wxString& time, wxString::const_iterator *end);
|
||||
|
||||
//@}
|
||||
|
||||
|
@ -869,8 +869,8 @@ int wxCmdLineParser::Parse(bool showUsage)
|
||||
case wxCMD_LINE_VAL_DATE:
|
||||
{
|
||||
wxDateTime dt;
|
||||
const char *res = dt.ParseDate(value);
|
||||
if ( !res || *res )
|
||||
wxString::const_iterator end;
|
||||
if ( !dt.ParseDate(value) || end != value.end() )
|
||||
{
|
||||
errorMsg << wxString::Format(_("Option '%s': '%s' cannot be converted to a date."),
|
||||
name.c_str(), value.c_str())
|
||||
|
@ -682,7 +682,7 @@ wxString wxDateTime::Format(const wxString& format, const TimeZone& tz) const
|
||||
//
|
||||
// this function is "strict" by design - it must reject anything except true
|
||||
// RFC822 time specs.
|
||||
wxAnyStrPtr
|
||||
bool
|
||||
wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
wxString::const_iterator p = date.begin();
|
||||
@ -692,7 +692,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
const wxString::const_iterator endWday = p + WDAY_LEN;
|
||||
const wxString wday(p, endWday);
|
||||
if ( GetWeekDayFromName(wday, Name_Abbr, DateLang_English) == Inv_WeekDay )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
//else: ignore week day for now, we could also check that it really
|
||||
// corresponds to the specified date
|
||||
|
||||
@ -700,11 +700,11 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
|
||||
// 2. separating comma
|
||||
if ( *p++ != ',' || *p++ != ' ' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// 3. day number
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
wxDateTime_t day = (wxDateTime_t)(*p++ - '0');
|
||||
if ( wxIsdigit(*p) )
|
||||
@ -714,7 +714,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
}
|
||||
|
||||
if ( *p++ != ' ' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// 4. month name
|
||||
static const int MONTH_LEN = 3;
|
||||
@ -722,20 +722,20 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
const wxString monName(p, endMonth);
|
||||
Month mon = GetMonthFromName(monName, Name_Abbr, DateLang_English);
|
||||
if ( mon == Inv_Month )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
p = endMonth;
|
||||
|
||||
if ( *p++ != ' ' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// 5. year
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
int year = *p++ - '0';
|
||||
if ( !wxIsdigit(*p) ) // should have at least 2 digits in the year
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
year *= 10;
|
||||
year += *p++ - '0';
|
||||
@ -749,7 +749,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
if ( !wxIsdigit(*p) )
|
||||
{
|
||||
// no 3 digit years please
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
year *= 10;
|
||||
@ -757,30 +757,30 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
}
|
||||
|
||||
if ( *p++ != ' ' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// 6. time in hh:mm:ss format with seconds being optional
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
wxDateTime_t hour = (wxDateTime_t)(*p++ - '0');
|
||||
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
hour *= 10;
|
||||
hour = (wxDateTime_t)(hour + (*p++ - '0'));
|
||||
|
||||
if ( *p++ != ':' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
wxDateTime_t min = (wxDateTime_t)(*p++ - '0');
|
||||
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
min *= 10;
|
||||
min += (wxDateTime_t)(*p++ - '0');
|
||||
@ -790,19 +790,19 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
p++;
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
sec = (wxDateTime_t)(*p++ - '0');
|
||||
|
||||
if ( !wxIsdigit(*p) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
sec *= 10;
|
||||
sec += (wxDateTime_t)(*p++ - '0');
|
||||
}
|
||||
|
||||
if ( *p++ != ' ' )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// 7. now the interesting part: the timezone
|
||||
int offset wxDUMMY_INITIALIZE(0);
|
||||
@ -812,7 +812,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
bool plus = *p++ == '+';
|
||||
|
||||
if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
|
||||
// hours
|
||||
@ -821,7 +821,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
p += 2;
|
||||
|
||||
if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
// minutes
|
||||
offset += 10*(*p - '0') + (*(p + 1) - '0');
|
||||
@ -847,7 +847,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
};
|
||||
|
||||
if ( *p < _T('A') || *p > _T('Z') || *p == _T('J') )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
offset = offsets[*p++ - 'A'];
|
||||
}
|
||||
@ -878,7 +878,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
else if ( tz == _T("PDT") )
|
||||
offset = PDT - GMT0;
|
||||
else
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
p += tz.length();
|
||||
}
|
||||
@ -895,7 +895,7 @@ wxDateTime::ParseRfc822Date(const wxString& date, wxString::const_iterator *end)
|
||||
if ( end )
|
||||
*end = p;
|
||||
|
||||
return wxAnyStrPtr(date, p);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
@ -1058,13 +1058,14 @@ static wxString GetLocaleDateFormat()
|
||||
|
||||
#endif // __WINDOWS__
|
||||
|
||||
wxAnyStrPtr
|
||||
bool
|
||||
wxDateTime::ParseFormat(const wxString& date,
|
||||
const wxString& format,
|
||||
const wxDateTime& dateDef,
|
||||
wxString::const_iterator *end)
|
||||
{
|
||||
wxCHECK_MSG( !format.empty(), wxAnyStrPtr(), "format can't be empty" );
|
||||
wxCHECK_MSG( !format.empty(), false, "format can't be empty" );
|
||||
wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
|
||||
|
||||
wxString str;
|
||||
unsigned long num;
|
||||
@ -1115,7 +1116,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( *input++ != *fmt )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1172,7 +1173,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( wday == Inv_WeekDay )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
haveWDay = true;
|
||||
@ -1190,7 +1191,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( mon == Inv_Month )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
haveMon = true;
|
||||
@ -1229,7 +1230,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
wxS("%X %x")
|
||||
);
|
||||
if ( !dt.IsValid() )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
Tm tm = dt.GetTm();
|
||||
|
||||
@ -1252,7 +1253,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
(num > 31) || (num < 1) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
// we can't check whether the day range is correct yet, will
|
||||
@ -1265,7 +1266,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || (num > 23) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveHour = true;
|
||||
@ -1276,7 +1277,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || !num || (num > 12) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveHour = true;
|
||||
@ -1288,7 +1289,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || !num || (num > 366) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveYDay = true;
|
||||
@ -1297,7 +1298,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
|
||||
case _T('l'): // milliseconds (0-999)
|
||||
if ( !GetNumericToken(width, input, &num) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveMsec = true;
|
||||
msec = (wxDateTime_t)num;
|
||||
@ -1307,7 +1308,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || !num || (num > 12) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveMon = true;
|
||||
@ -1318,7 +1319,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || (num > 59) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveMin = true;
|
||||
@ -1338,7 +1339,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
|
||||
GetAmPmStrings(&am, &pm);
|
||||
if (am.empty() && pm.empty())
|
||||
return wxAnyStrPtr(); // no am/pm strings defined
|
||||
return false; // no am/pm strings defined
|
||||
if ( token.CmpNoCase(pm) == 0 )
|
||||
{
|
||||
isPM = true;
|
||||
@ -1346,7 +1347,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
else if ( token.CmpNoCase(am) != 0 )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1356,7 +1357,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
wxDateTime dt;
|
||||
if ( !dt.ParseFormat(wxString(input, date.end()),
|
||||
wxS("%I:%M:%S %p"), &input) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveHour = haveMin = haveSec = true;
|
||||
|
||||
@ -1372,7 +1373,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
const wxDateTime
|
||||
dt = ParseFormatAt(input, date.end(), wxS("%H:%M"));
|
||||
if ( !dt.IsValid() )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveHour =
|
||||
haveMin = true;
|
||||
@ -1387,7 +1388,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || (num > 61) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveSec = true;
|
||||
@ -1399,7 +1400,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
const wxDateTime
|
||||
dt = ParseFormatAt(input, date.end(), wxS("%H:%M:%S"));
|
||||
if ( !dt.IsValid() )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveHour =
|
||||
haveMin =
|
||||
@ -1416,7 +1417,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || (wday > 6) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveWDay = true;
|
||||
@ -1472,7 +1473,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
dt = ParseFormatAt(input, date.end(),
|
||||
fmtDate, fmtDateAlt);
|
||||
if ( !dt.IsValid() )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
Tm tm = dt.GetTm();
|
||||
|
||||
@ -1493,7 +1494,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
// use strptime() to do it for us (FIXME !Unicode friendly)
|
||||
struct tm tm;
|
||||
if ( !CallStrptime(date, input, "%X", &tm) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveHour = haveMin = haveSec = true;
|
||||
|
||||
@ -1512,7 +1513,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
const wxDateTime
|
||||
dt = ParseFormatAt(input, date.end(), "%T", "%r");
|
||||
if ( !dt.IsValid() )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
haveHour =
|
||||
haveMin =
|
||||
@ -1530,7 +1531,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) || (num > 99) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveYear = true;
|
||||
@ -1544,7 +1545,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( !GetNumericToken(width, input, &num) )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
haveYear = true;
|
||||
@ -1559,7 +1560,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( *input++ != _T('%') )
|
||||
{
|
||||
// no match
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -1569,7 +1570,7 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
// fall through
|
||||
|
||||
default: // not a known format spec
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1610,14 +1611,14 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
if ( haveDay )
|
||||
{
|
||||
if ( mday > GetNumberOfDays(tm.mon, tm.year) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
tm.mday = mday;
|
||||
}
|
||||
else if ( haveYDay )
|
||||
{
|
||||
if ( yday > GetNumberOfDays(tm.year) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
Tm tm2 = wxDateTime(1, Jan, tm.year).SetToYearDay(yday).GetTm();
|
||||
|
||||
@ -1656,17 +1657,18 @@ wxDateTime::ParseFormat(const wxString& date,
|
||||
|
||||
// finally check that the week day is consistent -- if we had it
|
||||
if ( haveWDay && GetWeekDay() != wday )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
if ( end )
|
||||
*end = input;
|
||||
*end = input;
|
||||
|
||||
return wxAnyStrPtr(date, input);
|
||||
return true;
|
||||
}
|
||||
|
||||
wxAnyStrPtr
|
||||
bool
|
||||
wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
|
||||
|
||||
// Set to current day and hour, so strings like '14:00' becomes today at
|
||||
// 14, not some other random date
|
||||
wxDateTime dtDate = wxDateTime::Today();
|
||||
@ -1687,7 +1689,7 @@ wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
|
||||
|
||||
const wxString timestr(endDate, date.end());
|
||||
if ( !dtTime.ParseTime(timestr, &endTime) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
endBoth = endDate + (endTime - timestr.begin());
|
||||
}
|
||||
@ -1695,14 +1697,14 @@ wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
// check if we have a time followed by a date
|
||||
if ( !dtTime.ParseTime(date, &endTime) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
while ( endTime != date.end() && wxIsspace(*endTime) )
|
||||
++endTime;
|
||||
|
||||
const wxString datestr(endTime, date.end());
|
||||
if ( !dtDate.ParseDate(datestr, &endDate) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
endBoth = endTime + (endDate - datestr.begin());
|
||||
}
|
||||
@ -1711,16 +1713,16 @@ wxDateTime::ParseDateTime(const wxString& date, wxString::const_iterator *end)
|
||||
dtTime.GetHour(), dtTime.GetMinute(), dtTime.GetSecond(),
|
||||
dtTime.GetMillisecond());
|
||||
|
||||
// Return endpoint of scan
|
||||
if ( end )
|
||||
*end = endBoth;
|
||||
*end = endBoth;
|
||||
|
||||
return wxAnyStrPtr(date, endBoth);
|
||||
return true;
|
||||
}
|
||||
|
||||
wxAnyStrPtr
|
||||
bool
|
||||
wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
|
||||
|
||||
// this is a simplified version of ParseDateTime() which understands only
|
||||
// "today" (for wxDate compatibility) and digits only otherwise (and not
|
||||
// all esoteric constructions ParseDateTime() knows about)
|
||||
@ -1762,10 +1764,9 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
*this += wxDateSpan::Days(dayDiffFromToday);
|
||||
}
|
||||
|
||||
if ( end )
|
||||
*end = pEnd;
|
||||
*end = pEnd;
|
||||
|
||||
return wxAnyStrPtr(date, pEnd);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1986,7 +1987,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
// either no more tokens or the scan was stopped by something we couldn't
|
||||
// parse - in any case, see if we can construct a date from what we have
|
||||
if ( !haveDay && !haveWDay )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
if ( haveWDay && (haveMon || haveYear || haveDay) &&
|
||||
!(haveDay && haveMon && haveYear) )
|
||||
@ -1994,7 +1995,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
// without adjectives (which we don't support here) the week day only
|
||||
// makes sense completely separately or with the full date
|
||||
// specification (what would "Wed 1999" mean?)
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !haveWDay && haveYear && !(haveDay && haveMon) )
|
||||
@ -2020,7 +2021,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
}
|
||||
|
||||
if ( !haveMon )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !haveMon )
|
||||
@ -2038,7 +2039,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
// normally we check the day above but the check is optimistic in case
|
||||
// we find the day before its month/year so we have to redo it now
|
||||
if ( day > GetNumberOfDays(mon, year) )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
|
||||
Set(day, mon, year);
|
||||
|
||||
@ -2046,7 +2047,7 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
{
|
||||
// check that it is really the same
|
||||
if ( GetWeekDay() != wday )
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // haveWDay
|
||||
@ -2065,15 +2066,16 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end)
|
||||
p--;
|
||||
}
|
||||
|
||||
if ( end )
|
||||
*end = p;
|
||||
*end = p;
|
||||
|
||||
return wxAnyStrPtr(date, p);
|
||||
return true;
|
||||
}
|
||||
|
||||
wxAnyStrPtr
|
||||
bool
|
||||
wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
|
||||
{
|
||||
wxCHECK_MSG( end, false, "end iterator pointer must be specified" );
|
||||
|
||||
// first try some extra things
|
||||
static const struct
|
||||
{
|
||||
@ -2098,7 +2100,7 @@ wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
|
||||
if ( end )
|
||||
*end = p;
|
||||
|
||||
return wxAnyStrPtr(time, p);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2118,12 +2120,11 @@ wxDateTime::ParseTime(const wxString& time, wxString::const_iterator *end)
|
||||
|
||||
for ( size_t nFmt = 0; nFmt < WXSIZEOF(timeFormats); nFmt++ )
|
||||
{
|
||||
const wxAnyStrPtr result = ParseFormat(time, timeFormats[nFmt], end);
|
||||
if ( result )
|
||||
return result;
|
||||
if ( ParseFormat(time, timeFormats[nFmt], end) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return wxAnyStrPtr();
|
||||
return false;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -1271,9 +1271,8 @@ bool wxVariantDataDateTime::Read(wxString& str)
|
||||
return true;
|
||||
}
|
||||
|
||||
if(! m_value.ParseDateTime(str.c_str()/*FIXME-UTF8*/))
|
||||
return false;
|
||||
return true;
|
||||
wxString::const_iterator end;
|
||||
return m_value.ParseDateTime(str, &end) && end == str.end();
|
||||
}
|
||||
|
||||
// wxVariant
|
||||
|
Loading…
Reference in New Issue
Block a user