From: Francesco Montorsi Date: Fri, 20 Mar 2009 19:25:48 +0000 (+0000) Subject: move parsing helpers, too (part of r59656) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/54e660f85e8525cc0d0cb0ca7a5c01f931e3ed62 move parsing helpers, too (part of r59656) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59658 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/datetime.cpp b/src/common/datetime.cpp index 5781bebe92..927e7390be 100644 --- a/src/common/datetime.cpp +++ b/src/common/datetime.cpp @@ -391,7 +391,8 @@ extern const char *wxDumpDate(const wxDateTime* dt) #endif // Debug // get the number of days in the given month of the given year -static inline +// NOTE: not static because required by datetimefmt.cpp, too +inline wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month) { // the number of days in month in Julian/Gregorian calendar: the first line @@ -571,106 +572,6 @@ static void InitTm(struct tm& tm) tm.tm_isdst = -1; // auto determine } -// parsing helpers -// --------------- - -// return the month if the string is a month name or Inv_Month otherwise -static wxDateTime::Month GetMonthFromName(const wxString& name, int flags) -{ - wxDateTime::Month mon; - for ( mon = wxDateTime::Jan; mon < wxDateTime::Inv_Month; wxNextMonth(mon) ) - { - // case-insensitive comparison either one of or with both abbreviated - // and not versions - if ( flags & wxDateTime::Name_Full ) - { - if ( name.CmpNoCase(wxDateTime:: - GetMonthName(mon, wxDateTime::Name_Full)) == 0 ) - { - break; - } - } - - if ( flags & wxDateTime::Name_Abbr ) - { - if ( name.CmpNoCase(wxDateTime:: - GetMonthName(mon, wxDateTime::Name_Abbr)) == 0 ) - { - break; - } - } - } - - return mon; -} - -// return the weekday if the string is a weekday name or Inv_WeekDay otherwise -static wxDateTime::WeekDay GetWeekDayFromName(const wxString& name, int flags) -{ - wxDateTime::WeekDay wd; - for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) ) - { - // case-insensitive comparison either one of or with both abbreviated - // and not versions - if ( flags & wxDateTime::Name_Full ) - { - if ( name.CmpNoCase(wxDateTime:: - GetWeekDayName(wd, wxDateTime::Name_Full)) == 0 ) - { - break; - } - } - - if ( flags & wxDateTime::Name_Abbr ) - { - if ( name.CmpNoCase(wxDateTime:: - GetWeekDayName(wd, wxDateTime::Name_Abbr)) == 0 ) - { - break; - } - } - } - - return wd; -} - -/* static */ -struct tm *wxDateTime::GetTmNow(struct tm *tmstruct) -{ - time_t t = GetTimeNow(); - return wxLocaltime_r(&t, tmstruct); -} - -// scans all digits (but no more than len) and returns the resulting number -static bool GetNumericToken(size_t len, - const wxStringCharType*& p, - unsigned long *number) -{ - size_t n = 1; - wxString s; - while ( wxIsdigit(*p) ) - { - s += *p++; - - if ( len && ++n > len ) - break; - } - - return !s.empty() && s.ToULong(number); -} - -// scans all alphabetic characters and returns the resulting string -static wxString GetAlphaToken(const wxStringCharType*& p) -{ - wxString s; - while ( wxIsalpha(*p) ) - { - s += *p++; - } - - return s; -} - // ============================================================================ // implementation of wxDateTime // ============================================================================ @@ -1095,6 +996,7 @@ void wxDateTime::GetAmPmStrings(wxString *am, wxString *pm) } } + // ---------------------------------------------------------------------------- // Country stuff: date calculations depend on the country (DST, work days, // ...), so we need to know which rules to follow. diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index f53e183dad..dae6e0f1a8 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -63,6 +63,122 @@ // implementation of wxDateTime // ============================================================================ +// ---------------------------------------------------------------------------- +// constants (see also datetime.cpp) +// ---------------------------------------------------------------------------- + +static const int DAYS_PER_WEEK = 7; + +static const int HOURS_PER_DAY = 24; + +static const int SEC_PER_MIN = 60; + +static const int MIN_PER_HOUR = 60; + +// ---------------------------------------------------------------------------- +// parsing helpers +// ---------------------------------------------------------------------------- + +// see datetime.cpp: +wxDateTime::wxDateTime_t GetNumOfDaysInMonth(int year, wxDateTime::Month month); + +// return the month if the string is a month name or Inv_Month otherwise +static wxDateTime::Month GetMonthFromName(const wxString& name, int flags) +{ + wxDateTime::Month mon; + for ( mon = wxDateTime::Jan; mon < wxDateTime::Inv_Month; wxNextMonth(mon) ) + { + // case-insensitive comparison either one of or with both abbreviated + // and not versions + if ( flags & wxDateTime::Name_Full ) + { + if ( name.CmpNoCase(wxDateTime:: + GetMonthName(mon, wxDateTime::Name_Full)) == 0 ) + { + break; + } + } + + if ( flags & wxDateTime::Name_Abbr ) + { + if ( name.CmpNoCase(wxDateTime:: + GetMonthName(mon, wxDateTime::Name_Abbr)) == 0 ) + { + break; + } + } + } + + return mon; +} + +// return the weekday if the string is a weekday name or Inv_WeekDay otherwise +static wxDateTime::WeekDay GetWeekDayFromName(const wxString& name, int flags) +{ + wxDateTime::WeekDay wd; + for ( wd = wxDateTime::Sun; wd < wxDateTime::Inv_WeekDay; wxNextWDay(wd) ) + { + // case-insensitive comparison either one of or with both abbreviated + // and not versions + if ( flags & wxDateTime::Name_Full ) + { + if ( name.CmpNoCase(wxDateTime:: + GetWeekDayName(wd, wxDateTime::Name_Full)) == 0 ) + { + break; + } + } + + if ( flags & wxDateTime::Name_Abbr ) + { + if ( name.CmpNoCase(wxDateTime:: + GetWeekDayName(wd, wxDateTime::Name_Abbr)) == 0 ) + { + break; + } + } + } + + return wd; +} + +/* static */ +struct tm *wxDateTime::GetTmNow(struct tm *tmstruct) +{ + time_t t = GetTimeNow(); + return wxLocaltime_r(&t, tmstruct); +} + +// scans all digits (but no more than len) and returns the resulting number +static bool GetNumericToken(size_t len, + const wxStringCharType*& p, + unsigned long *number) +{ + size_t n = 1; + wxString s; + while ( wxIsdigit(*p) ) + { + s += *p++; + + if ( len && ++n > len ) + break; + } + + return !s.empty() && s.ToULong(number); +} + +// scans all alphabetic characters and returns the resulting string +static wxString GetAlphaToken(const wxStringCharType*& p) +{ + wxString s; + while ( wxIsalpha(*p) ) + { + s += *p++; + } + + return s; +} + // ---------------------------------------------------------------------------- // wxDateTime to/from text representations // ----------------------------------------------------------------------------