~zorba-coders/zorba/2.8-release-prep

« back to all changes in this revision

Viewing changes to src/zorbautils/locale.h

  • Committer: chillery+launchpad at lambda
  • Date: 2013-01-11 09:59:39 UTC
  • mfrom: (11176.1.4 zorba)
  • Revision ID: chillery+launchpad@lambda.nu-20130111095939-u1h3qp2yfc0fxwq3
MergeĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <zorba/locale.h>
23
23
 
24
24
#include "util/string_util.h"
 
25
#include "zorbatypes/zstring.h"
 
26
 
25
27
namespace zorba {
26
28
  namespace locale {
27
29
 
536
538
    }
537
539
 
538
540
    /**
 
541
     * Gets the date format for the current locale.  The format is that used by
 
542
     * strptime(3).
 
543
     *
 
544
     * @param lang The language to use.  Defaults to host language.
 
545
     * @param country The country to use.  Defaults to host country.
 
546
     * @return Returns said date format.
 
547
     */
 
548
    zstring get_date_format( iso639_1::type lang = iso639_1::unknown,
 
549
                             iso3166_1::type country = iso3166_1::unknown );
 
550
 
 
551
    /**
 
552
     * Gets the date and time format for the current locale.  The format is
 
553
     * that used by strptime(3).
 
554
     *
 
555
     * @param lang The language to use.  Defaults to host language.
 
556
     * @param country The country to use.  Defaults to host country.
 
557
     * @return Returns said date format.
 
558
     */
 
559
    zstring get_date_time_format( iso639_1::type lang = iso639_1::unknown,
 
560
                                  iso3166_1::type country = iso3166_1::unknown);
 
561
 
 
562
    /**
539
563
     * Gets the ISO 3166-1 country code enumeration for the host system.
540
564
     *
541
565
     * @return Returns said enumeration or \c unknown.
549
573
     */
550
574
    iso639_1::type get_host_lang();
551
575
 
 
576
    /**
 
577
     * Gets a month's abbreviation in the current locale.
 
578
     *
 
579
     * @param month_index The index of the month to get in the range 0-11.
 
580
     * @param lang The language to use.  Defaults to host language.
 
581
     * @param country The country to use.  Defaults to host country.
 
582
     * @return Returns said abbreviation.
 
583
     */
 
584
    zstring get_month_abbr( unsigned month_index,
 
585
                            iso639_1::type lang = iso639_1::unknown,
 
586
                            iso3166_1::type country = iso3166_1::unknown );
 
587
 
 
588
    /**
 
589
     * Gets a month's full name in the current locale.
 
590
     *
 
591
     * @param month_index The index of the month to get in the range 0-11.
 
592
     * @param lang The language to use.  Defaults to host language.
 
593
     * @param country The country to use.  Defaults to host country.
 
594
     * @return Returns said full name.
 
595
     */
 
596
    zstring get_month_name( unsigned month_index,
 
597
                            iso639_1::type lang = iso639_1::unknown,
 
598
                            iso3166_1::type country = iso3166_1::unknown );
 
599
 
 
600
    /**
 
601
     * Gets the time AM or PM string in the current locale.
 
602
     *
 
603
     * @param pm If \c true, gets the PM string; else the AM string.
 
604
     * @param lang The language to use.  Defaults to host language.
 
605
     * @param country The country to use.  Defaults to host country.
 
606
     * @return Returns said string.
 
607
     */
 
608
    zstring get_time_ampm( bool pm, iso639_1::type lang = iso639_1::unknown,
 
609
                           iso3166_1::type country = iso3166_1::unknown );
 
610
 
 
611
    /**
 
612
     * Gets the time format for the current locale.  The format is that used by
 
613
     * strptime(3).
 
614
     *
 
615
     * @param lang The language to use.  Defaults to host language.
 
616
     * @param country The country to use.  Defaults to host country.
 
617
     * @return Returns said time format.
 
618
     */
 
619
    zstring get_time_format( iso639_1::type lang = iso639_1::unknown,
 
620
                             iso3166_1::type country = iso3166_1::unknown );
 
621
 
 
622
    /**
 
623
     * Gets a weekday's abbreviation in the current locale.
 
624
     *
 
625
     * @param day_index The index of the weekday to get in the range 0-6.
 
626
     * @param lang The language to use.  Defaults to host language.
 
627
     * @param country The country to use.  Defaults to host country.
 
628
     * @return Returns said abbreviation.
 
629
     */
 
630
    zstring get_weekday_abbr( unsigned day_index,
 
631
                              iso639_1::type lang = iso639_1::unknown,
 
632
                              iso3166_1::type country = iso3166_1::unknown );
 
633
 
 
634
    /**
 
635
     * Gets a weekday's full name in the current locale.
 
636
     *
 
637
     * @param day_index The index of the month to get in the range 0-6.
 
638
     * @param lang The language to use.  Defaults to host language.
 
639
     * @param country The country to use.  Defaults to host country.
 
640
     * @return Returns said full name.
 
641
     */
 
642
    zstring get_weekday_name( unsigned day_index,
 
643
                              iso639_1::type lang = iso639_1::unknown,
 
644
                              iso3166_1::type country = iso3166_1::unknown );
 
645
 
 
646
    /**
 
647
     * Checks if the given locale is supported by the OS.
 
648
     *
 
649
     * @param lang The language to use.
 
650
     * @param country The country to use.  Defaults to none.
 
651
     * @return Returns \a true only if the given locale is supported by the OS.
 
652
     */
 
653
    bool is_supported( iso639_1::type lang,
 
654
                       iso3166_1::type country = iso3166_1::unknown );
 
655
 
 
656
    /**
 
657
     * Parses a locale string.
 
658
     *
 
659
     * @param locale_str A locale string of the form \c ll{-_}CC[.enc] where
 
660
     * \c ll is a 2 letter ISO 639-1 (or 3 letter 639-2) language code, \c CC
 
661
     * is a 2 letter ISO 3166-1 country code, and \c enc is an optional
 
662
     * encoding (which is ignored).
 
663
     * @param lang A pointer to receive the language, if any.
 
664
     * @param country A pointer to receive the country, if any.
 
665
     * @return Returns \c true if at least a language is parsed.
 
666
     */
 
667
    bool parse( char const *locale_str, iso639_1::type *lang = nullptr,
 
668
                iso3166_1::type *country = nullptr );
 
669
 
 
670
    //
 
671
    // Template version of parse().
 
672
    //
 
673
    template<class StringType> inline
 
674
    typename std::enable_if<
 
675
      ztd::has_c_str<StringType,char const* (StringType::*)() const>::value,
 
676
      bool
 
677
    >::type
 
678
    parse( StringType const &locale_str, iso639_1::type *lang = nullptr,
 
679
           iso3166_1::type *country = nullptr ) {
 
680
      return parse( locale_str.c_str(), lang, country );
 
681
    }
 
682
 
552
683
    ///////////////////////////////////////////////////////////////////////////
553
684
 
554
685
  } // namespace locale