Re: Proposal: add uloc_setKeywordValue and uloc_removeKeyword

"Steven R. Loomis" <[email protected]> Wed, 25 Aug 2004 01:36:06 +0200
Newsgroups gmane.comp.lib.icu.general
Message-ID <[email protected]>
That's already in the proposal, but i think you mean a modification to 
(1) allow 0-length values to be set and (2) remove the removeKeyword 
function

actually i am implementing remove as just calling set with a null

I believe getKeywordValue returns 0 (length 0) for both a missing and a 
0-length value.   I'd rather not allow 0-length values in that case.

>  * @param keywordValue value of the keyword to be set. If 0-length or
>  *  NULL, will result in the keyword being removed.


On 24-Awi-2004, at 9:44 PM, Deborah Goldsmith wrote:

> A possible alternative: use a NULL keywordValue passed to 
> uloc_setKeywordValue to mean "remove". I don't know if empty keyword 
> values are allowed, but even if they are that can be distinguished 
> from the case of the pointer being NULL.
>
> This makes the API a little smaller, if that's important. This is the 
> way I did it in my own implementation.
>
> Deborah
>
> On Aug 24, 2004, at 10:26 AM, Steven R. Loomis wrote:
>
>>
>> Proposal:  add uloc_setKeywordValue and uloc_deleteKeyword
>> Date:    2004 Aug 24
>> Bug: 3651 http://www.jtcsv.com/cgibin/icu-bugs?findid=3651
>>
>>  Quoting from the bug: "Since the UCalendarType argument to ucal_open
>> is deprecated, there isn't a good way to set an explicit calendar to
>> override the locale. By contrast, for a numeric format you can set the
>> currency programmatically.
>>   "Provide functions in uloc.h for setting keywords as well as getting
>> them. Right now, you have to iterate through all the keywords yourself
>> to see if that keyword is already present (you don't want to set two
>> copies of the same keyword). In addition to uloc_getKeywordValue
>> there would be uloc_setKeywordValue and uloc_deleteKeyword."
>>
>> Q: should the keywords be sorted?
>>
>> /**
>>  * Set the value of the specified keyword.
>>  * NOTA BENE: Unlike almost every other ICU function which takes a
>>  * buffer, this function will NOT truncate the output text. If a
>>  * BUFFER_OVERFLOW_ERROR is received, it means that the original
>>  * buffer is untouched. This is done to prevent incorrect or possibly
>>  * even malformed locales from being generated and used.
>>  * Missing keywords on delete won't be marked as an error.
>>  *
>>  * @param keywordName name of the keyword to be set. Case insensitive.
>>  * @param keywordValue value of the keyword to be set. If 0-length or
>>  *  NULL, will result in the keyword being removed.
>>  * @param buffer input buffer containing locale to be modified.
>>  * @param bufferCapacity capacity of receiving buffer
>>  * @param status containing error code - buffer not big enough.
>>  * @return the length needed for the buffer
>>  * @see uloc_removeKeyword
>>  * @draft ICU 3.2
>>  */
>> U_DRAFT int32_t U_EXPORT2
>> uloc_setKeywordValue(const char* keywordName,
>>                      const char* keywordValue,
>>                      char* buffer, int32_t bufferCapacity,
>>                      UErrorCode* status);
>>
>>
>> /**
>>  * Remove a specified keyword.
>>  * Missing keywords on delete won't be marked as an error.
>>  * @param keywordName name of the keyword to be removed. Case 
>> insensitive.
>>  * @param buffer input buffer containing locale to be modified.
>>  * @param bufferCapacity capacity of receiving buffer
>>  * @param status containing error code - buffer not big enough.
>>  * @return the length needed for the buffer
>>  * @see uloc_removeKeyword
>>  * @draft ICU 3.2
>>  */
>> U_DRAFT int32_t U_EXPORT2
>> uloc_removeKeyword(const char* keywordName,
>>                    char* buffer, int32_t bufferCapacity,
>>                    UErrorCode* status);
>>
>> _______________________________________________
>> icu mailing list
>> [email protected]
>> http://oss.software.ibm.com/developerworks/oss/mailman/listinfo/icu
>
> _______________________________________________
> icu mailing list
> [email protected]
> http://oss.software.ibm.com/developerworks/oss/mailman/listinfo/icu