mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-16 18:25:57 +00:00
const implemented: const UnitPreferences *const
This commit is contained in:
parent
481c2a59e6
commit
3b1d33a543
4 changed files with 13 additions and 4 deletions
|
@ -323,6 +323,11 @@ public:
|
|||
* @return the array pointer
|
||||
*/
|
||||
T *getAlias() const { return ptr; }
|
||||
/**
|
||||
* Access without ownership change.
|
||||
* @return the array pointer
|
||||
*/
|
||||
const T *getConstAlias() const { return ptr; }
|
||||
/**
|
||||
* Returns the array limit. Simple convenience method.
|
||||
* @return getAlias()+getCapacity()
|
||||
|
@ -779,6 +784,10 @@ public:
|
|||
return this->fPool.getAlias();
|
||||
}
|
||||
|
||||
const T *const *getConstAlias() const {
|
||||
return this->fPool.getConstAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Array item access (read-only).
|
||||
* No index bounds check.
|
||||
|
|
|
@ -386,13 +386,13 @@ U_I18N_API UnitPreferences::UnitPreferences(UErrorCode &status) {
|
|||
// of some kind.
|
||||
void U_I18N_API UnitPreferences::getPreferencesFor(const char *category, const char *usage,
|
||||
const char *region,
|
||||
const UnitPreference **&outPreferences,
|
||||
const UnitPreference *const *&outPreferences,
|
||||
int32_t &preferenceCount, UErrorCode &status) const {
|
||||
int32_t idx = getPreferenceMetadataIndex(&metadata_, category, usage, region, status);
|
||||
if (U_FAILURE(status)) { return; }
|
||||
U_ASSERT(idx >= 0); // Failures should have been taken care of by `status`.
|
||||
const UnitPreferenceMetadata *m = metadata_[idx];
|
||||
outPreferences = const_cast<const UnitPreference **>(unitPrefs_.getAlias()) + m->prefsOffset;
|
||||
outPreferences = unitPrefs_.getConstAlias() + m->prefsOffset;
|
||||
preferenceCount = m->prefsCount;
|
||||
}
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ class U_I18N_API UnitPreferences {
|
|||
* TODO: maybe replace `UnitPreference **&outPrefrences` with a slice class?
|
||||
*/
|
||||
void getPreferencesFor(const char *category, const char *usage, const char *region,
|
||||
const UnitPreference **&outPreferences, int32_t &preferenceCount,
|
||||
const UnitPreference *const *&outPreferences, int32_t &preferenceCount,
|
||||
UErrorCode &status) const;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -91,7 +91,7 @@ void UnitsDataTest::testGetPreferences() {
|
|||
|
||||
for (const auto &t : testCases) {
|
||||
logln(t.name);
|
||||
const UnitPreference **prefs;
|
||||
const UnitPreference *const *prefs;
|
||||
int32_t prefsCount;
|
||||
preferences.getPreferencesFor(t.category, t.usage, t.region, prefs, prefsCount, status);
|
||||
if (status.errIfFailureAndReset("getPreferencesFor(\"%s\", \"%s\", \"%s\", ...", t.category,
|
||||
|
|
Loading…
Add table
Reference in a new issue