zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #19296
[Merge] lp:~paul-lucas/zorba/pjl-misc into lp:zorba
Paul J. Lucas has proposed merging lp:~paul-lucas/zorba/pjl-misc into lp:zorba.
Commit message:
1. Now handling locale inform returning empty string for unsupported locales.
2. Hard-coded English for locale information so English is always supported.
Requested reviews:
Paul J. Lucas (paul-lucas)
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/155084
1. Now handling locale inform returning empty string for unsupported locales.
2. Hard-coded English for locale information so English is always supported.
--
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/155084
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'src/runtime/durations_dates_times/format_dateTime.cpp'
--- src/runtime/durations_dates_times/format_dateTime.cpp 2013-03-22 04:29:06 +0000
+++ src/runtime/durations_dates_times/format_dateTime.cpp 2013-03-22 23:57:22 +0000
@@ -166,6 +166,9 @@
second.at_type = no_second_at;
min_width = max_width = 0;
};
+
+ // default modifier(modifier const&) is fine
+ // default modifier& operator(modifier const&) is fine
};
///////////////////////////////////////////////////////////////////////////////
@@ -479,32 +482,43 @@
}
static void append_month( unsigned mon, modifier const &mod, zstring *dest ) {
+ modifier mod_copy( mod );
switch ( mod.first.type ) {
case modifier::name:
case modifier::Name:
case modifier::NAME: {
zstring name( locale::get_month_name( mon, mod.lang, mod.country ) );
- utf8_string<zstring> u_name( name );
- if ( mod.gt_max_width( u_name.size() ) ) {
- //
- // XQuery 3.0 F&O: 9.8.4.1: If the full representation of the value
- // exceeds the specified maximum width, then the processor should
- // attempt to use an alternative shorter representation that fits
- // within the maximum width. Where the presentation modifier is N, n,
- // or Nn, this is done by abbreviating the name, using either
- // conventional abbreviations if available, or crude right-truncation
- // if not.
- //
- name = locale::get_month_abbr( mon, mod.lang, mod.country );
- if ( mod.gt_max_width( u_name.size() ) )
- u_name = u_name.substr( 0, mod.max_width );
+ if ( !name.empty() ) {
+ utf8_string<zstring> u_name( name );
+ if ( mod.gt_max_width( u_name.size() ) ) {
+ //
+ // XQuery 3.0 F&O: 9.8.4.1: If the full representation of the value
+ // exceeds the specified maximum width, then the processor should
+ // attempt to use an alternative shorter representation that fits
+ // within the maximum width. Where the presentation modifier is N,
+ // n, or Nn, this is done by abbreviating the name, using either
+ // conventional abbreviations if available, or crude right-truncation
+ // if not.
+ //
+ zstring abbr = locale::get_month_abbr( mon, mod.lang, mod.country );
+ if ( !abbr.empty() ) {
+ utf8_string<zstring> u_abbr( abbr );
+ if ( mod.gt_max_width( u_abbr.size() ) )
+ u_abbr = u_abbr.substr( 0, mod.max_width );
+ name = abbr;
+ } else
+ u_name = u_name.substr( 0, mod.max_width );
+ }
+ mod.append_if_fallback_lang( dest );
+ append_string( name, mod, dest );
+ break;
}
- mod.append_if_fallback_lang( dest );
- append_string( name, mod, dest );
- break;
+ mod_copy.first.type = modifier::arabic;
+ mod_copy.first.format.clear();
+ // no break;
}
default:
- append_number( mon + 1, mod, dest );
+ append_number( mon + 1, mod_copy, dest );
}
}
@@ -698,24 +712,35 @@
case modifier::Name:
case modifier::NAME: {
zstring name( locale::get_weekday_name( wday, mod.lang, mod.country ) );
- utf8_string<zstring> u_name( name );
- if ( mod.gt_max_width( u_name.size() ) ) {
- //
- // XQuery 3.0 F&O: 9.8.4.1: If the full representation of the value
- // exceeds the specified maximum width, then the processor should
- // attempt to use an alternative shorter representation that fits
- // within the maximum width. Where the presentation modifier is N, n,
- // or Nn, this is done by abbreviating the name, using either
- // conventional abbreviations if available, or crude right-truncation
- // if not.
- //
- name = locale::get_weekday_abbr( wday, mod.lang, mod.country );
- if ( mod.gt_max_width( u_name.size() ) )
- u_name = u_name.substr( 0, mod.max_width );
+ if ( !name.empty() ) {
+ utf8_string<zstring> u_name( name );
+ if ( mod.gt_max_width( u_name.size() ) ) {
+ //
+ // XQuery 3.0 F&O: 9.8.4.1: If the full representation of the value
+ // exceeds the specified maximum width, then the processor should
+ // attempt to use an alternative shorter representation that fits
+ // within the maximum width. Where the presentation modifier is N,
+ // n, or Nn, this is done by abbreviating the name, using either
+ // conventional abbreviations if available, or crude right-truncation
+ // if not.
+ //
+ zstring abbr =
+ locale::get_weekday_abbr( wday, mod.lang, mod.country );
+ if ( !abbr.empty() ) {
+ utf8_string<zstring> u_abbr( abbr );
+ if ( mod.gt_max_width( u_abbr.size() ) )
+ u_abbr = u_abbr.substr( 0, mod.max_width );
+ name = abbr;
+ } else
+ u_name = u_name.substr( 0, mod.max_width );
+ }
+ mod.append_if_fallback_lang( dest );
+ append_string( name, mod_copy, dest );
+ break;
}
- mod.append_if_fallback_lang( dest );
- append_string( name, mod_copy, dest );
- break;
+ mod_copy.first.type = modifier::arabic;
+ mod_copy.first.format.clear();
+ // no break;
}
default: {
int const new_wday = calendar::convert_wday_to( wday, mod.cal );
=== modified file 'src/zorbautils/locale.cpp'
--- src/zorbautils/locale.cpp 2013-03-21 19:39:11 +0000
+++ src/zorbautils/locale.cpp 2013-03-22 23:57:22 +0000
@@ -597,7 +597,7 @@
PK , // dz: Bhutani => Pakistan
unknown, // ee: Ewe => (maps to multiple countries)
GR , // el: Greek => Greece
- GB , // en: English => United Kingdom
+ US , // en: English => United States
unknown, // eo: Esperanto => (constructed language)
ES , // es: Spanish => Spain
EE , // et: Estonian => Estonia
@@ -1298,7 +1298,10 @@
} // for
return format;
#else
- return get_locale_info( D_FMT, lang, country );
+ zstring fmt( get_locale_info( D_FMT, lang, country ) );
+ if ( fmt.empty() && lang == iso639_1::en )
+ fmt = "%d-%b-%Y"; // dd-Mon-yyyy
+ return fmt;
#endif /* WIN32 */
}
@@ -1311,7 +1314,10 @@
return get_date_format( lang, country ) + ' ' +
get_time_format( lang, country );
#else
- return get_locale_info( D_T_FMT, lang, country );
+ zstring fmt( get_locale_info( D_T_FMT, lang, country ) );
+ if ( fmt.empty() && lang == iso639_1::en )
+ fmt = "%a %b %e %X %Y";
+ return fmt;
#endif /* WIN32 */
}
@@ -1373,7 +1379,15 @@
if ( month_index > 11 )
throw invalid_argument( BUILD_STRING( month_index, " not in range 0-11" ) );
- return get_locale_info( month_abbr[ month_index ], lang, country );
+ zstring abbr( get_locale_info( month_abbr[ month_index ], lang, country ) );
+ if ( abbr.empty() && lang == iso639_1::en ) {
+ static char const *const abbr_str[] = {
+ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+ };
+ abbr = abbr_str[ month_index ];
+ }
+ return abbr;
}
zstring get_month_name( unsigned month_index, iso639_1::type lang,
@@ -1392,7 +1406,15 @@
if ( month_index > 11 )
throw invalid_argument( BUILD_STRING( month_index, " not in range 0-11" ) );
- return get_locale_info( month_name[ month_index ], lang, country );
+ zstring name( get_locale_info( month_name[ month_index ], lang, country ) );
+ if ( name.empty() && lang == iso639_1::en ) {
+ static char const *const name_str[] = {
+ "January", "February", "March", "April", "May", "June",
+ "July", "August", "Sepember", "October", "November", "December"
+ };
+ name = name_str[ month_index ];
+ }
+ return name;
}
zstring get_time_ampm( bool pm, iso639_1::type lang, iso3166_1::type country ) {
@@ -1403,7 +1425,10 @@
AM_STR, PM_STR
#endif /* WIN32 */
};
- return get_locale_info( ampm[ pm ], lang, country );
+ zstring s( get_locale_info( ampm[ pm ], lang, country ) );
+ if ( s.empty() && lang == iso639_1::en )
+ s = pm ? "PM" : "AM";
+ return s;
}
zstring get_time_format( iso639_1::type lang, iso3166_1::type country ) {
@@ -1457,7 +1482,10 @@
} // for
return format;
#else
- return get_locale_info( T_FMT, lang, country );
+ zstring fmt( get_locale_info( T_FMT, lang, country ) );
+ if ( fmt.empty() && lang == iso639_1::en )
+ fmt = "%H:%M:%S";
+ return fmt;
#endif /* WIN32 */
}
@@ -1479,7 +1507,14 @@
if ( day_index > 6 )
throw invalid_argument( BUILD_STRING( day_index, " not in range 0-6" ) );
- return get_locale_info( weekday_abbr[ day_index ], lang, country );
+ zstring abbr( get_locale_info( weekday_abbr[ day_index ], lang, country ) );
+ if ( abbr.empty() && lang == iso639_1::en ) {
+ static char const *const abbr_str[] = {
+ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+ };
+ abbr = abbr_str[ day_index ];
+ }
+ return abbr;
}
zstring get_weekday_name( unsigned day_index, iso639_1::type lang,
@@ -1500,7 +1535,15 @@
if ( day_index > 6 )
throw invalid_argument( BUILD_STRING( day_index, " not in range 0-6" ) );
- return get_locale_info( weekday_name[ day_index ], lang, country );
+ zstring name( get_locale_info( weekday_name[ day_index ], lang, country ) );
+ if ( name.empty() && lang == iso639_1::en ) {
+ static char const *const name_str[] = {
+ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
+ "Saturday"
+ };
+ name = name_str[ day_index ];
+ }
+ return name;
}
bool is_supported( iso639_1::type lang, iso3166_1::type country ) {
@@ -1510,6 +1553,8 @@
unique_ptr<WCHAR[]> const wlocale_name( get_wlocale_name( lang, country ) );
return Zorba_IsValidLocaleName( wlocale_name.get() );
#else
+ if ( lang == iso639_1::en )
+ return true; // Always support English
if ( locale_t const loc = get_unix_locale_t( lang, country ) ) {
::freelocale( loc );
return true;
Follow ups