zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #18780
[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:
Added locale to dynamic context. (This is needed to implement format-date() correctly.)
Requested reviews:
Paul J. Lucas (paul-lucas)
For more details, see:
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/152319
Added locale to dynamic context. (This is needed to implement format-date() correctly.)
--
https://code.launchpad.net/~paul-lucas/zorba/pjl-misc/+merge/152319
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/dynamic_context.h'
--- include/zorba/dynamic_context.h 2013-02-07 17:24:36 +0000
+++ include/zorba/dynamic_context.h 2013-03-08 04:27:22 +0000
@@ -21,6 +21,7 @@
#include <memory>
#include <zorba/config.h>
+#include <zorba/locale.h>
#include <zorba/api_shared_types.h>
#include <zorba/static_context_consts.h>
#include <zorba/xmldatamanager.h>
@@ -247,6 +248,26 @@
virtual Item
getDefaultCollection() const = 0;
+ /** \brief Sets the locale.
+ *
+ * @param aLang The language to set.
+ * @param aCountry The country to set.
+ */
+ virtual void
+ setLocale( locale::iso639_1::type aLang,
+ locale::iso3166_1::type aCountry ) = 0;
+
+ /** \brief Gets the locale.
+ *
+ * @param aLang A pointer to a \c iso639_1::type to receive the language.
+ * If \c null, this is not set.
+ * @param aCountry A pointer to a \c iso3166_1::type to receive the country.
+ * If \c null, this is not set.
+ */
+ virtual void
+ getLocale( locale::iso639_1::type *aLang,
+ locale::iso3166_1::type *aCountry ) const = 0;
+
/** \brief Add a name-value pair to this context.
* The value can be accessed in the evaluate method
* of external functions (see ContextualExternalFunction).
=== modified file 'include/zorba/locale.h'
--- include/zorba/locale.h 2013-02-07 17:24:36 +0000
+++ include/zorba/locale.h 2013-03-08 04:27:22 +0000
@@ -218,6 +218,262 @@
};
}
+ /**
+ * Defines constants for all ISO 3166-1 country codes.
+ */
+ namespace iso3166_1 {
+ enum type {
+ unknown,
+ AD, ///< Andorra
+ AE, ///< United Arab Emirates
+ AF, ///< Afghanistan
+ AG, ///< Antigua and Barbuda
+ AI, ///< Anguilla
+ AL, ///< Albania
+ AM, ///< Armenia
+ AN, ///< Netherlands Antilles
+ AO, ///< Angola
+ AQ, ///< Antarctica
+ AR, ///< Argentina
+ AS, ///< American Samoa
+ AT, ///< Austria
+ AU, ///< Australia
+ AW, ///< Aruba
+ AX, ///< Aland Islands
+ AZ, ///< Azerbaijan
+ BA, ///< Bosnia and Herzegovina
+ BB, ///< Barbados
+ BD, ///< Bangladesh
+ BE, ///< Belgium
+ BF, ///< Burkina Faso
+ BG, ///< Bulgaria
+ BH, ///< Bahrain
+ BI, ///< Burundi
+ BJ, ///< Benin
+ BL, ///< Saint Barthelemy
+ BM, ///< Bermuda
+ BN, ///< Brunei Darussalam
+ BO, ///< Bolivia
+ BR, ///< Brazil
+ BS, ///< Bahamas
+ BT, ///< Bhutan
+ BV, ///< Bouvet Island
+ BW, ///< Botswana
+ BY, ///< Belarus
+ BZ, ///< Belize
+ CA, ///< Canada
+ CC, ///< Cocos Islands
+ CD, ///< Congo
+ CF, ///< Central African Republic
+ CG, ///< Congo
+ CH, ///< Switzerland
+ CI, ///< Cote D'Ivoire
+ CK, ///< Cook Islands
+ CL, ///< Chile
+ CM, ///< Cameroon
+ CN, ///< China
+ CO, ///< Colombia
+ CR, ///< Costa Rica
+ CU, ///< Cuba
+ CV, ///< Cape Verde
+ CX, ///< Christmas Island
+ CY, ///< Cyprus
+ CZ, ///< Czech Republic
+ DE, ///< Germany
+ DJ, ///< Djibouti
+ DK, ///< Denmark
+ DM, ///< Dominica
+ DO, ///< Dominican Republic
+ DZ, ///< Algeria
+ EC, ///< Ecuador
+ EE, ///< Estonia
+ EG, ///< Egypt
+ EH, ///< Western Sahara
+ ER, ///< Eritrea
+ ES, ///< Spain
+ ET, ///< Ethiopia
+ FI, ///< Finland
+ FJ, ///< Fiji
+ FK, ///< Falkland Islands
+ FM, ///< Micronesia
+ FO, ///< Faroe Islands
+ FR, ///< France
+ GA, ///< Gabon
+ GB, ///< United Kingdom
+ GD, ///< Grenada
+ GE, ///< Georgia
+ GF, ///< French Guiana
+ GG, ///< Guernsey
+ GH, ///< Ghana
+ GI, ///< Gibraltar
+ GL, ///< Greenland
+ GM, ///< Gambia
+ GN, ///< Guinea
+ GP, ///< Guadeloupe
+ GQ, ///< Equatorial Guinea
+ GR, ///< Greece
+ GS, ///< South Georgia and the South Sandwich Islands
+ GT, ///< Guatemala
+ GU, ///< Guam
+ GW, ///< Guinea-Bissau
+ GY, ///< Guyana
+ HK, ///< Hong Kong
+ HM, ///< Heard Island and Mcdonald Islands
+ HN, ///< Honduras
+ HR, ///< Croatia
+ HT, ///< Haiti
+ HU, ///< Hungary
+ ID, ///< Indonesia
+ IE, ///< Ireland
+ IL, ///< Israel
+ IM, ///< Isle of Man
+ IN_, ///< India [without '_', it clashes with an identifier on Windows]
+ IO, ///< British Indian Ocean Territory
+ IQ, ///< Iraq
+ IR, ///< Iran
+ IS, ///< Iceland
+ IT, ///< Italy
+ JE, ///< Jersey
+ JM, ///< Jamaica
+ JO, ///< Jordan
+ JP, ///< Japan
+ KE, ///< Kenya
+ KG, ///< Kyrgyzstan
+ KH, ///< Cambodia
+ KI, ///< Kiribati
+ KM, ///< Comoros
+ KN, ///< Saint Kitts and Nevis
+ KP, ///< Korea (Democratic People's Republic)
+ KR, ///< Korea
+ KW, ///< Kuwait
+ KY, ///< Cayman Islands
+ KZ, ///< Kazakhstan
+ LA, ///< Lao
+ LB, ///< Lebanon
+ LC, ///< Saint Lucia
+ LI, ///< Liechtenstein
+ LK, ///< Sri Lanka
+ LR, ///< Liberia
+ LS, ///< Lesotho
+ LT, ///< Lithuania
+ LU, ///< Luxembourg
+ LV, ///< Latvia
+ LY, ///< Libyan Arab Jamahiriya
+ MA, ///< Morocco
+ MC, ///< Monaco
+ MD, ///< Moldova
+ ME, ///< Montenegro
+ MF, ///< Saint Martin
+ MG, ///< Madagascar
+ MH, ///< Marshall Islands
+ MK, ///< Macedonia
+ ML, ///< Mali
+ MM, ///< Myanmar
+ MN, ///< Mongolia
+ MO, ///< Macao
+ MP, ///< Northern Mariana Islands
+ MQ, ///< Martinique
+ MR, ///< Mauritania
+ MS, ///< Montserrat
+ MT, ///< Malta
+ MU, ///< Mauritius
+ MV, ///< Maldives
+ MW, ///< Malawi
+ MX, ///< Mexico
+ MY, ///< Malaysia
+ MZ, ///< Mozambique
+ NA, ///< Namibia
+ NC, ///< New Caledonia
+ NE, ///< Niger
+ NF, ///< Norfolk Island
+ NG, ///< Nigeria
+ NI, ///< Nicaragua
+ NL, ///< Netherlands
+ NO, ///< Norway
+ NP, ///< Nepal
+ NR, ///< Nauru
+ NU, ///< Niue
+ NZ, ///< New Zealand
+ OM, ///< Oman
+ PA, ///< Panama
+ PE, ///< Peru
+ PF, ///< French Polynesia
+ PG, ///< Papua New Guinea
+ PH, ///< Philippines
+ PK, ///< Pakistan
+ PL, ///< Poland
+ PM, ///< Saint Pierre and Miquelon
+ PN, ///< Pitcairn
+ PR, ///< Puerto Rico
+ PS, ///< Palestinian Territory
+ PT, ///< Portugal
+ PW, ///< Palau
+ PY, ///< Paraguay
+ QA, ///< Qatar
+ RE, ///< Reunion
+ RO, ///< Romania
+ RS, ///< Serbia
+ RU, ///< Russian Federation
+ RW, ///< Rwanda
+ SA, ///< Saudi Arabia
+ SB, ///< Solomon Islands
+ SC, ///< Seychelles
+ SD, ///< Sudan
+ SE, ///< Sweden
+ SG, ///< Singapore
+ SH, ///< Saint Helena
+ SI, ///< Slovenia
+ SJ, ///< Svalbard and Jan Mayen
+ SK, ///< Slovakia
+ SL, ///< Sierra Leone
+ SM, ///< San Marino
+ SN, ///< Senegal
+ SO, ///< Somalia
+ SR, ///< Suriname
+ ST, ///< Sao Tome and Principe
+ SV, ///< El Salvador
+ SY, ///< Syria
+ SZ, ///< Swaziland
+ TC, ///< Turks and Caicos Islands
+ TD, ///< Chad
+ TF, ///< French Southern Territories
+ TG, ///< Togo
+ TH, ///< Thailand
+ TJ, ///< Tajikistan
+ TK, ///< Tokelau
+ TL, ///< Timor-Leste
+ TM, ///< Turkmenistan
+ TN, ///< Tunisia
+ TO, ///< Tonga
+ TR, ///< Turkey
+ TT, ///< Trinidad and Tobago
+ TV, ///< Tuvalu
+ TW, ///< Taiwan
+ TZ, ///< Tanzania
+ UA, ///< Ukraine
+ UG, ///< Uganda
+ UM, ///< United States Minor Outlying Islands
+ US, ///< United States
+ UY, ///< Uruguay
+ UZ, ///< Uzbekistan
+ VA, ///< Vatican
+ VC, ///< Saint Vincent and the Grenadines
+ VE, ///< Venezuela
+ VG, ///< Virgin Islands (British)
+ VI, ///< Virgin Islands (USA)
+ VN, ///< Viet Nam
+ VU, ///< Vanuatu
+ WF, ///< Wallis and Futuna
+ WS, ///< Samoa
+ YE, ///< Yemen
+ YT, ///< Mayotte
+ ZA, ///< South Africa
+ ZM, ///< Zambia
+ ZW, ///< Zimbabwe
+ NUM_ENTRIES
+ };
+ }
+
///////////////////////////////////////////////////////////////////////////
} // namespace locale
=== modified file 'src/api/dynamiccontextimpl.cpp'
--- src/api/dynamiccontextimpl.cpp 2013-02-07 17:24:36 +0000
+++ src/api/dynamiccontextimpl.cpp 2013-03-08 04:27:22 +0000
@@ -675,6 +675,18 @@
return Item();
}
+/****************************************************************************//**
+
+********************************************************************************/
+void DynamicContextImpl::setLocale( locale::iso639_1::type aLang,
+ locale::iso3166_1::type aCountry ) {
+ theCtx->set_locale( aLang, aCountry );
+}
+
+void DynamicContextImpl::getLocale( locale::iso639_1::type *aLang,
+ locale::iso3166_1::type *aCountry ) const {
+ theCtx->get_locale( aLang, aCountry );
+}
/****************************************************************************//**
=== modified file 'src/api/dynamiccontextimpl.h'
--- src/api/dynamiccontextimpl.h 2013-02-07 17:24:36 +0000
+++ src/api/dynamiccontextimpl.h 2013-03-08 04:27:22 +0000
@@ -144,6 +144,13 @@
virtual Item
getDefaultCollection() const;
+ virtual void
+ setLocale( locale::iso639_1::type aLang, locale::iso3166_1::type aCountry );
+
+ virtual void
+ getLocale( locale::iso639_1::type *aLang,
+ locale::iso3166_1::type *aCountry ) const;
+
virtual bool
addExternalFunctionParam(const String& aName, void* aValue);
=== modified file 'src/context/dynamic_context.cpp'
--- src/context/dynamic_context.cpp 2013-02-26 04:12:43 +0000
+++ src/context/dynamic_context.cpp 2013-03-08 04:27:22 +0000
@@ -135,12 +135,16 @@
if(parent == NULL)
{
reset_current_date_time();
+ theLang = locale::get_host_lang();
+ theCountry = locale::get_host_country();
}
else
{
theCurrentDateTime = parent->theCurrentDateTime;
theTimezone = parent->theTimezone;
theDefaultCollectionUri = parent->theDefaultCollectionUri;
+ theLang = parent->theLang;
+ theCountry = parent->theCountry;
}
}
=== modified file 'src/context/dynamic_context.h'
--- src/context/dynamic_context.h 2013-02-07 17:24:36 +0000
+++ src/context/dynamic_context.h 2013-03-08 04:27:22 +0000
@@ -21,6 +21,7 @@
#include "zorbautils/hashmap_zstring.h"
#include "zorbautils/hashmap_itemp.h"
+#include "zorbautils/locale.h"
#include "common/shared_types.h"
@@ -138,6 +139,9 @@
//MODIFY
EnvVarMap * theEnvironmentVariables;
+ locale::iso639_1::type theLang;
+ locale::iso3166_1::type theCountry;
+
public:
double theDocLoadingUserTime;
double theDocLoadingTime;
@@ -171,6 +175,20 @@
long get_implicit_timezone() const;
+ void set_locale( locale::iso639_1::type lang,
+ locale::iso3166_1::type country ) {
+ theLang = lang;
+ theCountry = country;
+ }
+
+ void get_locale( locale::iso639_1::type *lang,
+ locale::iso3166_1::type *country ) {
+ if ( lang )
+ *lang = theLang;
+ if ( country )
+ *country = theCountry;
+ }
+
const std::vector<VarValue>& get_variables() const { return theVarValues; }
void add_variable(ulong varid, store::Item_t& value);
=== modified file 'src/zorbautils/locale.h'
--- src/zorbautils/locale.h 2013-02-07 17:24:36 +0000
+++ src/zorbautils/locale.h 2013-03-08 04:27:22 +0000
@@ -30,256 +30,6 @@
///////////////////////////////////////////////////////////////////////////
namespace iso3166_1 {
- enum type {
- unknown,
- AD, ///< Andorra
- AE, ///< United Arab Emirates
- AF, ///< Afghanistan
- AG, ///< Antigua and Barbuda
- AI, ///< Anguilla
- AL, ///< Albania
- AM, ///< Armenia
- AN, ///< Netherlands Antilles
- AO, ///< Angola
- AQ, ///< Antarctica
- AR, ///< Argentina
- AS, ///< American Samoa
- AT, ///< Austria
- AU, ///< Australia
- AW, ///< Aruba
- AX, ///< Aland Islands
- AZ, ///< Azerbaijan
- BA, ///< Bosnia and Herzegovina
- BB, ///< Barbados
- BD, ///< Bangladesh
- BE, ///< Belgium
- BF, ///< Burkina Faso
- BG, ///< Bulgaria
- BH, ///< Bahrain
- BI, ///< Burundi
- BJ, ///< Benin
- BL, ///< Saint Barthelemy
- BM, ///< Bermuda
- BN, ///< Brunei Darussalam
- BO, ///< Bolivia
- BR, ///< Brazil
- BS, ///< Bahamas
- BT, ///< Bhutan
- BV, ///< Bouvet Island
- BW, ///< Botswana
- BY, ///< Belarus
- BZ, ///< Belize
- CA, ///< Canada
- CC, ///< Cocos Islands
- CD, ///< Congo
- CF, ///< Central African Republic
- CG, ///< Congo
- CH, ///< Switzerland
- CI, ///< Cote D'Ivoire
- CK, ///< Cook Islands
- CL, ///< Chile
- CM, ///< Cameroon
- CN, ///< China
- CO, ///< Colombia
- CR, ///< Costa Rica
- CU, ///< Cuba
- CV, ///< Cape Verde
- CX, ///< Christmas Island
- CY, ///< Cyprus
- CZ, ///< Czech Republic
- DE, ///< Germany
- DJ, ///< Djibouti
- DK, ///< Denmark
- DM, ///< Dominica
- DO, ///< Dominican Republic
- DZ, ///< Algeria
- EC, ///< Ecuador
- EE, ///< Estonia
- EG, ///< Egypt
- EH, ///< Western Sahara
- ER, ///< Eritrea
- ES, ///< Spain
- ET, ///< Ethiopia
- FI, ///< Finland
- FJ, ///< Fiji
- FK, ///< Falkland Islands
- FM, ///< Micronesia
- FO, ///< Faroe Islands
- FR, ///< France
- GA, ///< Gabon
- GB, ///< United Kingdom
- GD, ///< Grenada
- GE, ///< Georgia
- GF, ///< French Guiana
- GG, ///< Guernsey
- GH, ///< Ghana
- GI, ///< Gibraltar
- GL, ///< Greenland
- GM, ///< Gambia
- GN, ///< Guinea
- GP, ///< Guadeloupe
- GQ, ///< Equatorial Guinea
- GR, ///< Greece
- GS, ///< South Georgia and the South Sandwich Islands
- GT, ///< Guatemala
- GU, ///< Guam
- GW, ///< Guinea-Bissau
- GY, ///< Guyana
- HK, ///< Hong Kong
- HM, ///< Heard Island and Mcdonald Islands
- HN, ///< Honduras
- HR, ///< Croatia
- HT, ///< Haiti
- HU, ///< Hungary
- ID, ///< Indonesia
- IE, ///< Ireland
- IL, ///< Israel
- IM, ///< Isle of Man
- IN_, ///< India [without '_', it clashes with an identifier on Windows]
- IO, ///< British Indian Ocean Territory
- IQ, ///< Iraq
- IR, ///< Iran
- IS, ///< Iceland
- IT, ///< Italy
- JE, ///< Jersey
- JM, ///< Jamaica
- JO, ///< Jordan
- JP, ///< Japan
- KE, ///< Kenya
- KG, ///< Kyrgyzstan
- KH, ///< Cambodia
- KI, ///< Kiribati
- KM, ///< Comoros
- KN, ///< Saint Kitts and Nevis
- KP, ///< Korea (Democratic People's Republic)
- KR, ///< Korea
- KW, ///< Kuwait
- KY, ///< Cayman Islands
- KZ, ///< Kazakhstan
- LA, ///< Lao
- LB, ///< Lebanon
- LC, ///< Saint Lucia
- LI, ///< Liechtenstein
- LK, ///< Sri Lanka
- LR, ///< Liberia
- LS, ///< Lesotho
- LT, ///< Lithuania
- LU, ///< Luxembourg
- LV, ///< Latvia
- LY, ///< Libyan Arab Jamahiriya
- MA, ///< Morocco
- MC, ///< Monaco
- MD, ///< Moldova
- ME, ///< Montenegro
- MF, ///< Saint Martin
- MG, ///< Madagascar
- MH, ///< Marshall Islands
- MK, ///< Macedonia
- ML, ///< Mali
- MM, ///< Myanmar
- MN, ///< Mongolia
- MO, ///< Macao
- MP, ///< Northern Mariana Islands
- MQ, ///< Martinique
- MR, ///< Mauritania
- MS, ///< Montserrat
- MT, ///< Malta
- MU, ///< Mauritius
- MV, ///< Maldives
- MW, ///< Malawi
- MX, ///< Mexico
- MY, ///< Malaysia
- MZ, ///< Mozambique
- NA, ///< Namibia
- NC, ///< New Caledonia
- NE, ///< Niger
- NF, ///< Norfolk Island
- NG, ///< Nigeria
- NI, ///< Nicaragua
- NL, ///< Netherlands
- NO, ///< Norway
- NP, ///< Nepal
- NR, ///< Nauru
- NU, ///< Niue
- NZ, ///< New Zealand
- OM, ///< Oman
- PA, ///< Panama
- PE, ///< Peru
- PF, ///< French Polynesia
- PG, ///< Papua New Guinea
- PH, ///< Philippines
- PK, ///< Pakistan
- PL, ///< Poland
- PM, ///< Saint Pierre and Miquelon
- PN, ///< Pitcairn
- PR, ///< Puerto Rico
- PS, ///< Palestinian Territory
- PT, ///< Portugal
- PW, ///< Palau
- PY, ///< Paraguay
- QA, ///< Qatar
- RE, ///< Reunion
- RO, ///< Romania
- RS, ///< Serbia
- RU, ///< Russian Federation
- RW, ///< Rwanda
- SA, ///< Saudi Arabia
- SB, ///< Solomon Islands
- SC, ///< Seychelles
- SD, ///< Sudan
- SE, ///< Sweden
- SG, ///< Singapore
- SH, ///< Saint Helena
- SI, ///< Slovenia
- SJ, ///< Svalbard and Jan Mayen
- SK, ///< Slovakia
- SL, ///< Sierra Leone
- SM, ///< San Marino
- SN, ///< Senegal
- SO, ///< Somalia
- SR, ///< Suriname
- ST, ///< Sao Tome and Principe
- SV, ///< El Salvador
- SY, ///< Syria
- SZ, ///< Swaziland
- TC, ///< Turks and Caicos Islands
- TD, ///< Chad
- TF, ///< French Southern Territories
- TG, ///< Togo
- TH, ///< Thailand
- TJ, ///< Tajikistan
- TK, ///< Tokelau
- TL, ///< Timor-Leste
- TM, ///< Turkmenistan
- TN, ///< Tunisia
- TO, ///< Tonga
- TR, ///< Turkey
- TT, ///< Trinidad and Tobago
- TV, ///< Tuvalu
- TW, ///< Taiwan
- TZ, ///< Tanzania
- UA, ///< Ukraine
- UG, ///< Uganda
- UM, ///< United States Minor Outlying Islands
- US, ///< United States
- UY, ///< Uruguay
- UZ, ///< Uzbekistan
- VA, ///< Vatican
- VC, ///< Saint Vincent and the Grenadines
- VE, ///< Venezuela
- VG, ///< Virgin Islands (British)
- VI, ///< Virgin Islands (USA)
- VN, ///< Viet Nam
- VU, ///< Vanuatu
- WF, ///< Wallis and Futuna
- WS, ///< Samoa
- YE, ///< Yemen
- YT, ///< Mayotte
- ZA, ///< South Africa
- ZM, ///< Zambia
- ZW, ///< Zimbabwe
- NUM_ENTRIES
- };
extern char const *const string_of[];
/**
Follow ups