This example shows how to collect character collating weights from Unicode strings using the specified locale object.

#include <stdio.h>
#include <unidef.h>

int main(void) {

LocaleObject locale_object = NULL;

UniChar      *pucs1;
UniChar      *pucs2 = L"computer";
int          num_elems = 8;
int          num_elems_trx = 0;
int          result = 0;
int          rc = ULS_SUCCESS;

         /*****************************************************************/
         /* Assumes LANG environment variable set to a valid locale name, */
         /* such as fr_FR                                                 */
         /*****************************************************************/

         rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                                   (UniChar *)L"", &locale_object);

         if (rc != ULS_SUCCESS) {
           printf("UniCreateLocaleObject error: return code = %u\n", rc);
           return 1;
         }

         /********************************************************************/
         /* Calculate the space needed for the collating weights             */
         /********************************************************************/

         num_elems = UniStrxfrm (locale_object, NULL, pucs2, 0);


         pucs1 = (UniChar *) malloc((num_elems + 1) * sizeof(UniChar));

         if(!pucs1)
            return 1;

         /********************************************************************/
         /* Obtain the collating weights for the Unicode string.             */
         /* num_elems_trx should be less than num_elems                      */
         /********************************************************************/

         num_elems_trx = UniStrxfrm (locale_object, pucs1,
                                     pucs2, num_elems + 1);

         if(num_elems_trx >= (num_elems + 1)) {
           printf("UniStrxfrm error:\n");
           return 1;
         }

         return (ULS_SUCCESS);


}


[Back: UniStrxfrm - Related Functions]
[Next: UniStrxfrm - Topics]