Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. // std::time_get, std::time_put implementation, generic version -*- C++ -*-
  2.  
  3. // Copyright (C) 2001-2015 Free Software Foundation, Inc.
  4. //
  5. // This file is part of the GNU ISO C++ Library.  This library is free
  6. // software; you can redistribute it and/or modify it under the
  7. // terms of the GNU General Public License as published by the
  8. // Free Software Foundation; either version 3, or (at your option)
  9. // any later version.
  10.  
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. // GNU General Public License for more details.
  15.  
  16. // Under Section 7 of GPL version 3, you are granted additional
  17. // permissions described in the GCC Runtime Library Exception, version
  18. // 3.1, as published by the Free Software Foundation.
  19.  
  20. // You should have received a copy of the GNU General Public License and
  21. // a copy of the GCC Runtime Library Exception along with this program;
  22. // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
  23. // <http://www.gnu.org/licenses/>.
  24.  
  25. //
  26. // ISO C++ 14882: 22.2.5.1.2 - time_get virtual functions
  27. // ISO C++ 14882: 22.2.5.3.2 - time_put virtual functions
  28. //
  29.  
  30. // Written by Benjamin Kosnik <bkoz@redhat.com>
  31.  
  32. #include <locale>
  33. #include <cstdlib>
  34. #include <cstring>
  35.  
  36. namespace std _GLIBCXX_VISIBILITY(default)
  37. {
  38. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  39.  
  40.   template<>
  41.     void
  42.     __timepunct<char>::
  43.     _M_put(char* __s, size_t __maxlen, const char* __format,
  44.            const tm* __tm) const throw()
  45.     {
  46.       char* __old = setlocale(LC_ALL, 0);
  47.       const size_t __llen = strlen(__old) + 1;
  48.       char* __sav = new char[__llen];
  49.       memcpy(__sav, __old, __llen);
  50.       setlocale(LC_ALL, _M_name_timepunct);
  51.       const size_t __len = strftime(__s, __maxlen, __format, __tm);
  52.       setlocale(LC_ALL, __sav);
  53.       delete [] __sav;
  54.       // Make sure __s is null terminated.
  55.       if (__len == 0)
  56.         __s[0] = '\0';
  57.     }
  58.  
  59.   template<>
  60.     void
  61.     __timepunct<char>::_M_initialize_timepunct(__c_locale)
  62.     {
  63.       // "C" locale.
  64.       if (!_M_data)
  65.         _M_data = new __timepunct_cache<char>;
  66.  
  67.       _M_data->_M_date_format = "%m/%d/%y";
  68.       _M_data->_M_date_era_format = "%m/%d/%y";
  69.       _M_data->_M_time_format = "%H:%M:%S";
  70.       _M_data->_M_time_era_format = "%H:%M:%S";
  71.       _M_data->_M_date_time_format = "";
  72.       _M_data->_M_date_time_era_format = "";
  73.       _M_data->_M_am = "AM";
  74.       _M_data->_M_pm = "PM";
  75.       _M_data->_M_am_pm_format = "";
  76.  
  77.       // Day names, starting with "C"'s Sunday.
  78.       _M_data->_M_day1 = "Sunday";
  79.       _M_data->_M_day2 = "Monday";
  80.       _M_data->_M_day3 = "Tuesday";
  81.       _M_data->_M_day4 = "Wednesday";
  82.       _M_data->_M_day5 = "Thursday";
  83.       _M_data->_M_day6 = "Friday";
  84.       _M_data->_M_day7 = "Saturday";
  85.  
  86.       // Abbreviated day names, starting with "C"'s Sun.
  87.       _M_data->_M_aday1 = "Sun";
  88.       _M_data->_M_aday2 = "Mon";
  89.       _M_data->_M_aday3 = "Tue";
  90.       _M_data->_M_aday4 = "Wed";
  91.       _M_data->_M_aday5 = "Thu";
  92.       _M_data->_M_aday6 = "Fri";
  93.       _M_data->_M_aday7 = "Sat";
  94.  
  95.       // Month names, starting with "C"'s January.
  96.       _M_data->_M_month01 = "January";
  97.       _M_data->_M_month02 = "February";
  98.       _M_data->_M_month03 = "March";
  99.       _M_data->_M_month04 = "April";
  100.       _M_data->_M_month05 = "May";
  101.       _M_data->_M_month06 = "June";
  102.       _M_data->_M_month07 = "July";
  103.       _M_data->_M_month08 = "August";
  104.       _M_data->_M_month09 = "September";
  105.       _M_data->_M_month10 = "October";
  106.       _M_data->_M_month11 = "November";
  107.       _M_data->_M_month12 = "December";
  108.  
  109.       // Abbreviated month names, starting with "C"'s Jan.
  110.       _M_data->_M_amonth01 = "Jan";
  111.       _M_data->_M_amonth02 = "Feb";
  112.       _M_data->_M_amonth03 = "Mar";
  113.       _M_data->_M_amonth04 = "Apr";
  114.       _M_data->_M_amonth05 = "May";
  115.       _M_data->_M_amonth06 = "Jun";
  116.       _M_data->_M_amonth07 = "Jul";
  117.       _M_data->_M_amonth08 = "Aug";
  118.       _M_data->_M_amonth09 = "Sep";
  119.       _M_data->_M_amonth10 = "Oct";
  120.       _M_data->_M_amonth11 = "Nov";
  121.       _M_data->_M_amonth12 = "Dec";
  122.     }
  123.  
  124. #ifdef _GLIBCXX_USE_WCHAR_T
  125.   template<>
  126.     void
  127.     __timepunct<wchar_t>::
  128.     _M_put(wchar_t* __s, size_t __maxlen, const wchar_t* __format,
  129.            const tm* __tm) const throw()
  130.     {
  131.       char* __old = setlocale(LC_ALL, 0);
  132.       const size_t __llen = strlen(__old) + 1;
  133.       char* __sav = new char[__llen];
  134.       memcpy(__sav, __old, __llen);
  135.       setlocale(LC_ALL, _M_name_timepunct);
  136.       const size_t __len = wcsftime(__s, __maxlen, __format, __tm);
  137.       setlocale(LC_ALL, __sav);
  138.       delete [] __sav;
  139.       // Make sure __s is null terminated.
  140.       if (__len == 0)
  141.         __s[0] = L'\0';
  142.     }
  143.  
  144.   template<>
  145.     void
  146.     __timepunct<wchar_t>::_M_initialize_timepunct(__c_locale)
  147.     {
  148.       // "C" locale.
  149.       if (!_M_data)
  150.         _M_data = new __timepunct_cache<wchar_t>;
  151.  
  152.       _M_data->_M_date_format = L"%m/%d/%y";
  153.       _M_data->_M_date_era_format = L"%m/%d/%y";
  154.       _M_data->_M_time_format = L"%H:%M:%S";
  155.       _M_data->_M_time_era_format = L"%H:%M:%S";
  156.       _M_data->_M_date_time_format = L"";
  157.       _M_data->_M_date_time_era_format = L"";
  158.       _M_data->_M_am = L"AM";
  159.       _M_data->_M_pm = L"PM";
  160.       _M_data->_M_am_pm_format = L"";
  161.  
  162.       // Day names, starting with "C"'s Sunday.
  163.       _M_data->_M_day1 = L"Sunday";
  164.       _M_data->_M_day2 = L"Monday";
  165.       _M_data->_M_day3 = L"Tuesday";
  166.       _M_data->_M_day4 = L"Wednesday";
  167.       _M_data->_M_day5 = L"Thursday";
  168.       _M_data->_M_day6 = L"Friday";
  169.       _M_data->_M_day7 = L"Saturday";
  170.  
  171.       // Abbreviated day names, starting with "C"'s Sun.
  172.       _M_data->_M_aday1 = L"Sun";
  173.       _M_data->_M_aday2 = L"Mon";
  174.       _M_data->_M_aday3 = L"Tue";
  175.       _M_data->_M_aday4 = L"Wed";
  176.       _M_data->_M_aday5 = L"Thu";
  177.       _M_data->_M_aday6 = L"Fri";
  178.       _M_data->_M_aday7 = L"Sat";
  179.  
  180.       // Month names, starting with "C"'s January.
  181.       _M_data->_M_month01 = L"January";
  182.       _M_data->_M_month02 = L"February";
  183.       _M_data->_M_month03 = L"March";
  184.       _M_data->_M_month04 = L"April";
  185.       _M_data->_M_month05 = L"May";
  186.       _M_data->_M_month06 = L"June";
  187.       _M_data->_M_month07 = L"July";
  188.       _M_data->_M_month08 = L"August";
  189.       _M_data->_M_month09 = L"September";
  190.       _M_data->_M_month10 = L"October";
  191.       _M_data->_M_month11 = L"November";
  192.       _M_data->_M_month12 = L"December";
  193.  
  194.       // Abbreviated month names, starting with "C"'s Jan.
  195.       _M_data->_M_amonth01 = L"Jan";
  196.       _M_data->_M_amonth02 = L"Feb";
  197.       _M_data->_M_amonth03 = L"Mar";
  198.       _M_data->_M_amonth04 = L"Apr";
  199.       _M_data->_M_amonth05 = L"May";
  200.       _M_data->_M_amonth06 = L"Jun";
  201.       _M_data->_M_amonth07 = L"Jul";
  202.       _M_data->_M_amonth08 = L"Aug";
  203.       _M_data->_M_amonth09 = L"Sep";
  204.       _M_data->_M_amonth10 = L"Oct";
  205.       _M_data->_M_amonth11 = L"Nov";
  206.       _M_data->_M_amonth12 = L"Dec";
  207.     }
  208. #endif
  209.  
  210. _GLIBCXX_END_NAMESPACE_VERSION
  211. } // namespace
  212.