Unicode Functions
(OS/2 Warp)
Second Edition (October 1997)

This document describes the OS/2 Warp Universal Language Support (ULS) functions. These functions provide APIs and data types to support internationalization of applications.

This document is broken up into four major sections:


Table of Contents

Locale and Character Classification Functions

Codepage Conversion Functions

ULS Data Types


Universal Language Support Functions

Internationalized applications are required to operate in a variety of environments based on some territory, language, and/or cultural definition. These environments are identified by a locale, an object which encapsulates culturally specific information. The locale identifies the culture, language, and territory that it supports.

UniCompleteUserLocale

UniCompleteUserLocale is used to finish a locale modification. This API is called after one or more UniSetLocaleItem calls to cause the new user defined locale file to be saved.

Format


#include <unidef.h>

int UniCompleteUserLocale
(void)


Parameters

None required.

Returns  

return value  (int)  -  returns 
UniCompleteUserLocale returns one of the following values:
ULS_SUCCESS  
Successful completion; overridden items have been written to a file.
ERROR_OPEN_FAILED  
DosOpen failed to open the locale file.
ERROR_ACCESS_DENIED  
DosWrite failed due to denied access.
ULS_NOMEMORY
  Insufficient memory to create a buffer for writing the new locale.

Remarks

UniCompleteUserLocale is used to complete the process of defining a new locale or modifying an existing locale. An application will use the UniQueryLocale API's and UniSetUserLocaleItem API to take an existing locale definition and customize that definition to form a new locale. When the customization process is complete, the UniCompleteUserLocale API is invoked to save the results as a new locale.

The result of calling this API is that the locale is saved to disk as a new user locale or changes to an existing locale are saved to disk to represent the newly created locale.

Related Functions

Example


This example shows how to complete a user locale after modifying
one or more locale items.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

/* Array containing user locales */
UniChar     *uniUsrLocales;
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;
         }

         /* allocate space for the user defined locales */
         uniUsrLocales = (UniChar *) malloc(4096);

         /* Query the list of user defined locales available to modify */
         rc = UniQueryLocaleList(UNI_USER_LOCALES, uniUsrLocales, 2048);

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

         .
         .
         .
         /* Change locale definition by calling UniSetUserLocaleItem to make
            locale item changes.
         */
         .
         .
         .


         /* Write the current set of user locales to disk */
         rc = UniCompleteUserLocale();
         if (rc != ULS_SUCCESS) {
           printf("UniCompleteUserLocale error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}

UniCreateAttrObject

UniCreateAttrObject creates an attribute object that is used to determine character classifications.

Format


#include <unidef.h>

int UniCreateAttrObject
(const LocaleObject locale_object, const UniChar *AttrName, AttrObject *attr_object)


Parameters  

locale_object  (const LocaleObject) 
Locale object created by a call to UniCreateLocaleObject() or NULL.  
 
AttrName  (const UniChar *) 
A UniChar string that specifies the attribute names for which an attribute object should be created. Multiple attribute names are specified as a string of separate names.  
 
attr_object  (AttrObject *) 
An address that will receive a pointer to an attribute object upon successful completion of UniCreateAttrObject.

Returns  

return value  (int)  -  returns 
UniCreateLocaleObject returns one of the following values:
ULS_SUCCESS  
Successful completion; attr_object points to a valid attribute object.
ULS_UNSUPPORTED  
The attribute name specified in AttrName is not supported by the locale_object.
ULS_NOMEMORY  
Insufficient memory to create the attribute object.

Remarks

UniCreateAttrObject allocates resources associated with an attribute defined in the LC_CTYPE category of the locale indicated by the locale_object argument.

The locale_object argument specifies a locale object handle returned by UniCreateLocaleObject. It should not be a NULL pointer.

The AttrName argument specifies the attribute names for which an attribute object handle should be created. Multiple attribute names are specified as a string of space-separated names.

When UniCreateAttrObject completes without errors, the attr_object argument specifies a valid pointer to an attribute object.

The attribute object pointer should be used in all subsequent calls to the UniQueryCharAttr. If the function result is other than ULS_SUCCESS, the contents of the area pointed to by attr_object are undefined.

The following attribute names are the base POSIX attributes. All attribute names which can be specified in UniQueryCharAttr are allowed. Those attributes which start with underscore (_) or hash (#) may not be combined with other attributes.

alnum
True when alpha or digit is true.
alpha
True when upper or lower is true, or when none of cntrl, digit, punct, or space is true.
blank
True for the characters space and horizontal tab.
cntrl
True for any control character; the following attributes must be false: upper, lower, alpha, digit, xdigit, graph, print, and punct.
digit
True for the digits 0, 1, 2 3, 4, 5, 6, 7, 8, and 9.
graph
True for any character with the print attribute, except the space
character
(Code element 0x0020).
lower
True for any character that is a lowercase letter and none of cntrl, digit, punct, or space is true.
print
True for upper, lower, alpha, digit, xdigit, punct, or any printing character including the space character (code element 0x0020).
punct
True for any printing character that is neither the space character (code element 0x0020) nor a character for which alnum is true.
space
True for any character that corresponds to a standard white-space character or is one of the set of white-space characters in the locale as indicated by the locale_object argument for which alnum is false. The standard white-space characters are the following: space, form feed, newline, carriage return, horizontal tab, and vertical tab.
upper
True for any character that is an uppercase letter and none of cntrl, digit, punct, or space is true.
xdigit
true for 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E F, a, b, c, d, e, and f.

Related Functions

Example


This example shows how to create and use a character attribute object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

AttrObject   attr_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'a';    /* Unicode lowercase Latin letter a */
         /*****************************************************************/
         /* 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;
         }
         /* Create an alphabetic attribute object */
         rc = UniCreateAttrObject(locale_object,
                                 (UniChar *)L"alpha", &attr_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateAttrObject error: return code = %u\n", rc);
           return 1;
         }
         /* Make call to determine if character is alphabetic */
         result = UniQueryCharAttr(attr_object, uni_char);
         if (result)
           printf("UniChar character %04X is alphabetic\n", uni_char);
         else
           printf("UniChar character %04X is not alphabetic\n", uni_char);
         return ULS_SUCCESS;

}


UniCreateLocaleObject

UniCreateLocaleObject creates a locale object.

Format


#include <unidef.h>

int UniCreateLocaleObject
(int LocaleSpecType, const void *LocaleSpec, LocaleObject *locale_object)


Parameters  

LocaleSpecType  (int) 
Identifies the type of value in the LocaleSpec argument.

The constant names of the values of LocaleSpecType are defined in the header unidef.h:

UNI_TOKEN_POINTER
LocaleSpec points to a locale token.
UNI_MBS_STRING_POINTER
LocaleSpec points to a multibyte character string.
UNI_UCS_STRING_POINTER
LocaleSpec points to a UCS character string.

 

LocaleSpec  (const void *) 
The LocaleSpec argument points to either a character string or a locale token, as indicated by the value of the LocaleSpecType argument.  
 
locale_object  (LocaleObject *) 
An address that will receive a pointer to a locale object upon successful completion of UniCreateLocaleObject.

Returns  

return value  (int)  -  returns 
UniCreateLocaleObject returns one of the following values:
ULS_SUCCESS
The specified locale is supported and a valid locale object was created.
ULS_UNSUPPORTED
The specified locale is not supported; the locale object pointer points to undefined data.
ULS_NOMEMORY
There is insufficient memory to create the requested locale or the default locale; the locale object pointer points to undefined data.
ULS_INVALID
An invalid locale specification string or token was passed; the locale object pointer points to undefined data.

Remarks

UniCreateLocaleObject creates a locale object for the locale specified by LocaleSpec. The object created is an opaque object containing all the data and methods necessary to perform the language-sensitive operations or functions that accept an argument of type LocaleObject. If the function is successful, all categories of the locale object are created and initialized.

When the LocaleSpec argument is a pointer to a character string (UCS character string or multibyte character string), it identifies the name of the locale to be initialized. The locale name is used to locate physical resources associated with this locale. The locale name UNIV is reserved and refers to the definitions that provide default behavior for functions.

When the LocaleSpec argument is a NULL pointer (without regard to the value of the LocaleSpecType argument), UniCreateLocaleObject creates a locale object for the UNIV locale.

When the LocaleSpec argument points to a locale token value as indicated by the value of the LocaleSpecType argument, the token identifies the locale to be initialized.

When the LocaleSpec argument is an empty multibyte or UCS character string, UniCreateLocaleObject creates a locale object based upon the settings of the locale environment variables.

 

Locale Environment Variables by Precedence and Usage

Catgeory

Precedence

Usage

LC_ALL

Highest

Setting LC_ALL takes precedence over any other locale environment variable.

LC_COLLATE

Equal precedence

Specifies collation (sorting) rules.

LC_CTYPE

Equal precedence

Specifies character classification and case conversion.

LC_MESSAGES

Equal precedence

Specifies the values for affirmative and negative answers, and the language for displayed messages.

LC_MONETARY

Equal precedence

Specifies monetary formats and currency symbol.

LC_NUMERIC

Equal precedence

Specifies decimal formats.

LC_TIME

Equal precedence

Specifies date and time formats.

LANG

Lowest

Setting LANG takes precedence over any undefined locale environment variable. This may be used in conjunction with LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, and LC_TIME.

If the specified locale is valid and supported, UniCreateLocaleObject allocates memory for the new object and returns the address of the created locale object in the area pointed to by locale_object. It is the application's responsibility to free this memory with a call to UniFreeLocaleObject when the object is no longer needed. If the function fails for any reason, the contents of the area pointed to by locale_object are undefined.

The locale token provides a shorthand notation for specifying a locale. The format of the locale token is as returned by a call to UniLocaleStrToToken. The format is defined as an unsigned integer of four octets.

Examples of typical usage:

The locale environment variables are set as follows:

LANG=de_DE
LC_MONETARY=en_US

The LocaleSpec argument is an empty multibyte or UCS character string.

This example creates a locale object with all categories set to de_DE except for
LC_MONETARY which has the value of en_US.

The locale environment variables are set as follows:

LANG=fr_FR

The LocaleSpec argument is an empty multibyte or UCS character string.

This example creates a locale object with all categories set to fr_FR.

The locale environment variables are set as follows:

LC_ALL=it_IT
LANG=fr_FR

The LocaleSpec argument is an empty multibyte or UCS character string.

This example creates a locale object with all categories set to it_IT.

Related Functions

Example


This example shows how to create a locale object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

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;
         }
         return ULS_SUCCESS;

}


UniCreateTransformObject

UniCreateTransformObject creates a string transform object.

Format


#include <unidef.h>

int UniCreateTransformObject
(const LocaleObject locale_object, const UniChar *xtype, XformObject *xform_object)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
xtype  (const UniChar *) 
A UniChar string identifying the transform type.  
 
xform_object  (XformObject *) 
An address that will receive a pointer to an Xform Object upon successful completion of UniCreateTransformObject.

Returns

return value  (int)  -  returns 
UniCreateTransformObject returns one of the following:
ULS_SUCCESS
No errors; the xform_object argument points to a valid transformation object.
ULS_UNSUPPORTED
The transformation name type specified by the xtype argument is not supported for locale_object.

Remarks

UniCreateTransformObject obtains a transformation object for a transformation type as defined in the locale indicated by the locale_object argument. The function returns a transformation object that can be used as an argument in UniTransformStr.

The following transformation types are defined in all locales:

lower
Transform to lowercase characters. A character that does not have a lowercase form is returned as itself.
upper
Transform to uppercase characters. A character that does not have an uppercase form is returned as itself.
compose
Transform to fully composed form for combined characters.
decompose
Transform to a string of decomposed characters where multiple characters are used to represent base and diacritics.
hiragana
Transform so that Japanese phonetic characters are in hiragana
katakana
Transform so that Japanese phonetic characters are in full size katakana
kana
Transform so that Japanese phonetic characters are in half size katakana

In addition to the above transformation-type names, other transformation-type names in the locale (including user-defined transformation-type names) may be passed to UniCreateTransformObject through the xtype argument. To obtain a successful return, the transformation-type name must be defined in locale_object.

When UniCreateTransformObject completes without errors, the xform_object argument value specifies a valid pointer to a transformation object. The transformation object should be used in all subsequent calls to UniTransformStr. If the function result is other than ULS_SUCCESS, the contents of the area pointed to by xform_object are undefined.

Related Functions

Example


This example shows how to create and use a transform object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

XformObject  xform_object = NULL;
int          rc = ULS_SUCCESS;
int          in_unistr_elem = 0;
int          out_unistr_elem = 10;
UniChar      *pin_unistr = (UniChar *)L"os2";
UniChar      out_unistr[10];
         /*****************************************************************/
         /* 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;
         }
         /* Create an upper case transform object */
         rc = UniCreateTransformObject(locale_object,
                                      (UniChar *)L"upper", &xform_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateTransformObject error: return code = %u\n", rc);
           return 1;
         }
         /* Calculate the number of elements to transform */
         in_unistr_elem = UniStrlen (pin_unistr) + 1;
         /* Make call to transform input string to uppercase */
         rc = UniTransformStr(xform_object, pin_unistr,
                             &in_unistr_elem, out_unistr,
                             &out_unistr_elem);
         if (rc != ULS_SUCCESS) {
           printf("UniTransformStr error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniDeleteUserLocale

UniDeleteUserLocale is used to delete a locale created by a user.

Format


#include <unidef.h>

int UniDeleteUserLocale
(UniChar * locale)


Parameters

locale  (UniChar *) 
A pointer to a UniChar string which defines the name of the locale.

Returns  

return value  (int)  -  returns 
UniDeleteUserLocale returns on of the following:
ULS_SUCCESS  
Successful completion; user locale deleted from disk.
ULS_NOMATCH  
The requested locale cannot be found.
ULS_INVALID  
The locale being deleted is not a user defined locale.

Remarks

UniCompleteDeleteLocale is used to remove a previously defined user locale. The locale must have been previously created as a user locale. This is accomplished by using the UniCompleteUserLocale API.

Related Functions

Example


This example shows how to delete a user locale once it is no longer
needed by the user.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

/* Array containing user locales */
UniChar      *uniUsrLocales;
UniChar      uniLocaleName[MAX_LOCALE_NAME_LENGTH];
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;
         }

         .
         .
         .
         /*
             Identify the locale to be deleted - making sure the name is in
             Unicode.
         */
         .
         .
         .


         /* Delete a user locale from the disk */
         rc = UniDeleteUserLocale(uniLocaleName);
         if (rc != ULS_SUCCESS) {
           printf("UniDeleteUserLocale error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}

UniFreeAttrObject

UniFreeAttrObject frees the character attribute object.

Format


#include <unidef.h>

int UniFreeAttrObject
(AttrObject attr_object)


Parameters  

attr_object  (AttrObject) 
An attribute object to be freed. The attribute object must have been created by a call to UniCreateAttrObject.

Returns

return value  (int)  -  returns 

UniFreeAttrObject returns one of the following values:

ULS_SUCCESS
All resources associated with the attribute object specified by the attr_object argument have been successfully deallocated.
ULS_BADOBJ
The attribute object specified by attr_object is not a valid attribute object.

Remarks

UniFreeAttrObject releases all resources associated with the character attribute object allocated by UniCreateAttrObject.

The attr_object argument specifies a previously allocated attribute object.

Related Functions

Example


This example shows how to create and free a character attribute object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

AttrObject   attr_object = NULL;

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;
         }
         /* Create an alphabetic attribute object */
         rc = UniCreateAttrObject(locale_object,
                                 (UniChar *)L"alpha", &attr_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateAttrObject error: return code = %u\n", rc);
           return 1;
         }
         /* Free the character attribute object */
         rc = UniFreeAttrObject(attr_object);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeAttrObject error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniFreeLocaleInfo

UniFreeLocaleInfo frees a locale information structure created by UniQueryLocaleInfo.

Format


#include <unidef.h>

int UniFreeLocaleInfo
(struct UniLconv *UniLconv_addr)


Parameters  

UniLconv_addr  (struct UniLconv *) 
A locale information structure created by a call to UniQueryLocaleInfo.

Returns

return value  (int)  -  returns 
UniFreeLocaleInfo returns one of the following values:
ULS_SUCCESS
The UniLconv structure and associated memory were successfully freed.
ULS_BADOBJ
The UniLconv_addr is not a valid structure.

Related Functions

Example


This example shows how to create and free a locale information structure.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject      locale_object = NULL;
struct UniLconv   *puni_lconv = NULL;

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;
         }
         /* Retrieve locale information */
         rc = UniQueryLocaleInfo(locale_object, &puni_lconv);
         if (rc != ULS_SUCCESS) {
           printf("UniQueryLocaleInfo error: return code = %u\n", rc);
           return 1;
         }
         printf("Monetary decimal point is %ls\n", puni_lconv->mon_decimal_point);
         /* Free the locale information structure */
         rc = UniFreeLocaleInfo(puni_lconv);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeLocaleInfo error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniFreeLocaleObject

UniFreeLocaleObject frees a locale object that was created by UniCreateLocaleObject.

Format


#include <unidef.h>

int UniFreeLocaleObject
(LocaleObject locale_object)


Parameters  

locale_object  (LocaleObject) 
The Locale Object to be freed. locale_object must have been created by a call to UniCreateLocaleObject.

Returns

return value  (int)  -  returns 
UniQueryLocaleObject returns one of the following values:
ULS_SUCCESS
A valid locale specification for the supplied locale object is returned.
ULS_BADOBJ
Invalid locale object specified.

Remarks

The UniFreeLocaleObject function destroys the locale object identified by locale_object and frees any memory associated with it.

Related Functions

Example


This example shows how to create and free a locale object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject      locale_object = NULL;
int               rc = ULS_SUCCESS;
         /* Create a locale object for French in Canada */
         rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                                   (UniChar *)L"fr_CA", &locale_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateLocaleObject error: return code = %u\n", rc);
           return 1;
         }
         /* Free the locale object that was just created */
         rc = UniFreeLocaleObject(locale_object);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeLocaleObject error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniFreeMem

UniFreeMem frees memory allocated by UniQueryLocaleObject.

Format


#include <unidef.h>

int UniFreeMem
(void *memory)


Parameters  

memory  (void *)  -  in/out 
A pointer to the memory to be freed.

Returns

Returns  (int)  -  returns 
UniFreeMem returns one of the following values:
ULS_SUCCESS  
Indicates success.
ULS_BADOBJ  
Invalid pointer in memory.

Remarks

UniFreeMem frees memory allocated by ULS functions. For example, the memory allocated for the locale_name parameter of UniQueryLocaleObject should be freed using UniFreeMem.

Example


This example shows how to free memory allocated by a ULS function.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject      locale_object = NULL;
int               rc = ULS_SUCCESS;
char              *locale_name;
         /* Create a locale object for French in Canada */
         rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                                   (UniChar *)L"fr_CA", &locale_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateLocaleObject error: return code = %u\n", rc);
           return 1;
         }
         /* Determine the locale name for the LC_MESSAGES category */
         rc = UniQueryLocaleObject(locale_object, LC_MESSAGES,
                                   UNI_MBS_STRING_POINTER,
                                   (void **)&locale_name);
         if (rc != ULS_SUCCESS) {
           printf("UniQueryLocaleObject error: return code = %u\n", rc);
           return 1;
         }
         /* Free the memory allocated by UniQueryLocaleObject */
         rc = UniFreeMem((void **)locale_name);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeMemObject error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniFreeTransformObject

UniFreeTransformObject frees a string transformation object.

Format


#include <unidef.h>

int UniFreeTransformObject
(XformObject xform_object)


Parameters  

xform_object  (XformObject) 
The transform object to be freed. The transform object must have been created by a call to UniCreateTransformObject.

Returns

return value  (int)  -  returns 
 
UniFreeTransformObject returns one of the following:
ULS_SUCCESS
Specifies that all resources associated with the transformation object specified by the xform_object argument have been successfully deallocated.

Remarks

UniFreeTransformObject releases all resources associated with a transformation object previously obtained by UniCreateTransformObject.

Related Functions

Example


This example shows how to create and free a transform object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

XformObject  xform_object = NULL;

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;
         }
         /* Create an upper case transform object */
         rc = UniCreateTransformObject(locale_object,
                                      (UniChar *)L"lower", &xform_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateTransformObject error: return code = %u\n", rc);
           return 1;
         }
         /* Free the transform object created by UniCreateTransformObject */
         rc = UniFreeTransformObject(xform_object);
         if (rc != ULS_SUCCESS) {
           printf("UniFreeTransformObject error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniLocaleStrToToken

UniLocaleStrToToken converts a locale specification string to a token.

Format


#include <unidef.h>

int UniLocaleStrToToken
(int LocaleStringType, const void *locale_string, LocaleToken *locale_token)


Parameters  

LocaleStringType  (int) 
Informs UniLocaleStrToToken of the type of string being passed in the locale_string variable.

The LocaleStringType argument can take any of the following values, which are constants defined in the header unidef.h:

UNI_MBS_STRING_POINTER
Requests that a multibyte string pointer is held in locale_string.
UNI_UCS_STRING_POINTER
Requests that a UCS string pointer is held in locale_string.

 

locale_string  (const void *) 
The locale specification string.  
 
locale_token  (LocaleToken *) 
An address that will receive a pointer to the newly created token corresponding to locale_string.

Returns

return value  (int)  -  returns 
UniLocaleStrToToken returns one of the following values:
ULS_SUCCESS
A valid locale token for the supplied locale object is returned.
ULS_OTHER
The C locale is because LOCALE.DLL cound not be found.
ULS_UNSUPPORTED
The locale name is valid but the locale cound not be found.

Remarks

UniLocaleStrToToken accepts, as an argument, a locale string qualified by the value of the LocaleStringType argument. It returns a locale token pointed to by locale_token if such a token exists for that locale string. UniLocaleStrToToken allocates memory to hold the locale token value. If no locale token exists for the supplied locale string, the value returned in locale_token is undefined.

Related Functions

Example


This example shows how to convert a locale specification string to a token.
#include <stdio.h>

#include <unidef.h>
int main(void) {
UniChar       *locale_string = L"de_DE";  /*German in Germany locale string */
LocaleToken   locale_token;

int           rc = ULS_SUCCESS;
         rc = UniLocaleStrToToken(UNI_UCS_STRING_POINTER,
                                 (void *)locale_string,
                                 &locale_token);
         if (rc != ULS_SUCCESS) {
           printf("UniLocaleStrToToken error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniLocaleTokenToStr

UniLocaleTokenToStr converts a locale token to a locale specification string.

Format


#include <unidef.h>

int UniLocaleTokenToStr
(const LocaleToken locale_token, int LocaleStringType, void **locale_string)


Parameters  

locale_token  (const LocaleToken) 
A token identifying a locale.  
 
LocaleStringType  (int) 
The LocaleStringType argument can take any of the following values, which are constants defined in the header unidef.h:
UNI_MBS_STRING_POINTER
Requests that a multibyte string pointer be returned.
UNI_UCS_STRING_POINTER
Requests that a UCS string pointer be returned.

 

locale_string  (void **) 

An address of a pointer variable locale_string that will contain the locale specification string corresponding to locale_token.

Returns  

return value  (int)  -  returns 
The UniLocaleTokenToStr function returns one of the following values:
ULS_SUCCESS
A valid locale specification for the supplied locale object is returned.
ULS_INVALID
The locale token supplied could not be matched to a locale string.
ULS_NOMEMORY
There is insufficient memory to store the locale string.

Remarks

The UniLocaleTokenToStr() function accepts as an argument a locale token in locale_token and returns a pointer to a locale string in locale_string qualified by the LocaleStringType argument. The UniLocaleTokenToStr() function allocates memory to hold the locale string value. It is the application's responsibility to free the memory using UniFreeMem() when the locale string value is no longer needed. If no locale string can be generated for the supplied locale token, the value returned in locale_string is undefined.

Related Functions

Example


This example shows how to convert a locale token to a locale specification string.
#include <stdio.h>

#include <unidef.h>
int main(void) {
UniChar       *locale_string1 = L"de_DE";  /*German in Germany locale string */
UniChar       *locale_string2;

LocaleToken   locale_token;

int           rc = ULS_SUCCESS;
         rc = UniLocaleStrToToken(UNI_UCS_STRING_POINTER,
                                 (void *)locale_string1,
                                 &locale_token);
         if (rc != ULS_SUCCESS) {
           printf("UniLocaleStrToToken error: return code = %u\n", rc);
           return 1;
         }

/* Convert the token to a locale string */

         rc = UniLocaleTokenToStr(locale_token,
                                 UNI_UCS_STRING_POINTER,
                                 (void **)&locale_string2);
         if (rc != ULS_SUCCESS) {
           printf("UniLocaleTokenToStr error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniMakeUserLocale

UniMakeUserLocale creates a user locale from a base system locale.

Format


#include <unidef.h>

int UniMakeUserLocale
(UniChar * newName, UniChar * baseName)


Parameters  

newName (UniChar * )
The name of the new locale.  
 
baseName (UniChar * )
The name of the locale to base the new locale after.

Returns

return value  (int)  -  returns 
UniMakeUserLocale returns one of the following values:
ULS_SUCCESS
The user locale has been created.
ULS_NOMATCH
The base system locale does not exist.
ULS_INVALID
The name supplied contains an illegal character, is too long or redefines a base system locale.
ULS_NOOP
The name supplied currently exists as a locale name.
ULS_NOMEMORY
Cannot allocate memory for the new locale.

Remarks

The names for the new locale and the base system locale must be ASCII-7 chars and at most eight characters, in length. An existing locale name must be given as the base locale name.

If the user locale already exists, a ULS_NOOP return code will be given, therefore, this API can always be called before making an update to ensure that the user locale exists.

Related Functions

Example


This example shows how to make a user locale.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject   locale_object = NULL;

int            rc = ULS_SUCCESS;
UniChar        *plocaleName;
UniChar        *puniSysLocale;
    /* Create current default locale object for this process */
    rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                         (UniChar *)L"",
                         &locale_object);
    if(rc) {
      printf("UniCreateLocaleObject error: return code = %u\n", rc);
      return 1;
    }
    /* Query the name of the default locale object */
    rc = UniQueryLocaleObject(locale_object,
                         LC_ALL,
                         UNI_UCS_STRING_POINTER,
                         (void**)&plocaleName);
    if(rc) {
      printf("UniQueryLocaleObject error: return code = %u\n", rc);
      return 1;
    }
    /* Get the locale name from the locale object string */
    puniSysLocale = UniStrtok(plocaleName, (UniChar *)L" ");
    /* Make a new locale */
    rc = UniMakeUserLocale(puniSysLocale, puniSysLocale);
    if (rc) {
      printf("UniMakeUserLocale error: return code = %u\n", rc);
      return 1;
    }
    /* free the space used by the locale object string */
    UniFreeMem(plocaleName);
    if(locale_object)
        UniFreeLocaleObject(locale_object);
    return ULS_SUCCESS;

}


UniMapCtryToLocale

UniMapCtryToLocale converts an unsigned long country code into a locale name represented as a UniChar string that is acceptable as input to other Unicode APIs.

Format


#include <unidef.h>

int UniMapCtryToLocale
(unsigned long ulCountryCode, UniChar *ucsLocaleName, size_t n)


Parameters  

ulCountryCode  (unsigned long)  -  input 
An OS/2 country code.  
 
ucsLocaleName  (UniChar *)  -  output 
A buffer for placing the Unicode string.  
 
n  (size_t)  -  input 
Size, in characters, of the ucsLocaleName buffer. This should be at least 8 Unicode characters.

Returns

return value  (int)  -  returns 
Error code.

UniMapCtryToLocale returns one of the following values:

ULS_SUCCESS
A valid locale name for the supplied country code is returned.
ULS_BUFFERFULL
The buffer is not large enough to hold the locale name.
ULS_INVALID
An invalid country code or buffer was specified.

Related Functions

Example


This example shows how to map a country code to a locale name.
#include <stdio.h>

#include <unidef.h>
int main(void) {
UniChar        ucs_locale_name[8];
size_t         num_elems = 8;

unsigned long country_num = 1;
LocaleObject locale_object = NULL;
int rc = ULS_SUCCESS;

         /*****************************************************************/
         /* Convert country number to a locale name                       */
         /*****************************************************************/
         rc = UniMapCtryToLocale(country_num, ucs_locale_name, num_elems);
         if (rc != ULS_SUCCESS) {
           printf("UniMapCtryToLocale error: return code = %u\n", rc);
           return 1;
         }
         rc = UniCreateLocaleObject(UNI_UCS_STRING_POINTER,
                                   ucs_locale_name, &locale_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateLocaleObject error: return code = %u\n", rc);
           return 1;
         }
         return ULS_SUCCESS;

}


UniQueryAlnum

UniQueryAlnum queries character attributes.

Format


#include <unidef.h>

int UniQueryAlnum
(const LocaleObject locale_object, UniChar uc)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL. 
 
uc  (UniChar) 
The UniChar character to query.

Returns

return value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

This function provides the functionality of UniCreateAttrObject, UniQueryCharAttr, and UniFreeAttrObject as an atomic operation for the invariant attributes.

The locale may be specified as NULL to indicate default Unicode character attributes

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'a';    /* Unicode lowercase Latin letter a */
         /*****************************************************************/
         /* 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;
         }
         /* Query character attribute */
         result = UniQueryAlnum(locale_object, uni_char);
         if (result)
           printf("UniChar character %04X is alphanumeric\n", uni_char);
         else
           printf("UniChar character %04X is not alphanumeric\n", uni_char);

return ULS_SUCCESS;
}


UniQueryAlpha

UniQueryAlpha queries character attributes.

Format


#include <unidef.h>

int UniQueryAlpha
(const LocaleObject locale_object, UniChar uc)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
uc  (UniChar) 
The UniChar character to query.

Returns

Return Value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

This function provides the functionality of UniCreateAttrObject, UniQueryCharAttr, and UniFreeAttrObject as an atomic operation for the invariant attributes.

The locale may be specified as NULL to indicate default Unicode character attributes

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'a';    /* Unicode lowercase Latin letter a */
         /* Query character attribute */
         result = UniQueryAlpha(NULL, uni_char);
         if (result)
           printf("UniChar character %04X is alphabetic\n", uni_char);
         else
           printf("UniChar character %04X is not alphabetic\n", uni_char);

return ULS_SUCCESS;
}


UniQueryAttr

UniQueryAttr returns the value associated with attribute name supplied by the user.

Format


#include <unidef.h>

ulong UniQueryAttr
(UniChar * attrName)


Parameters  

attrName  (UniChar  *) 
The name of a character attribute.

Returns

Return Value  (ulong)  -  returns 
If the attribute name is known, the function returns the attribute value. Otherwise, 0 is returned.

Remarks

This function provides the numeric value for the standard attributes such as alpha, graph, and number. In addition, this function provides the numeric value for other attributes such as Hiragana, diacritic, halfwidth etc. The table below contains the valid attribute names. Valid names are all in lower case.

Attribute names that begin with a lower case letter may be ORed together.

Attribute Name and Description Table
Attr Name
Attribute Define
Description of Attribute
alnum
CT_ALNUM
Alphabetic and numeric characters
alpha
CT_ALPHA
Letters and linguistic marks
ascii
CT_ASCII
Standard ASCII character
blank
CT_BLANK
Space and Tab
cntrl
CT_CNTRL
Control and format characters
diacritic
C3_DIACRITIC
Diacritic
digit
CT_DIGIT
Digits 0 through 9
fullwidth
C3_FULLWIDTH
Full width variant
graph
CT_GRAPH
All except controls and space
halfwidth
C3_HALFWIDTH
Half width variant
hiragana
C3_HIRAGANA
Hiragana character
ideograph
C3_IDEOGRAPH
Kanji/Han character
kashida
C3_KASHIDA
Arabic tatweel (used to stretch characters)
katakana
C3_KATAKANA
Katakana character
lower
CT_LOWER
Lower case alphabetic character
nonspacing
C3_NONSPACING
Non-spacing mark
nsdiacritic
C3_NSDIACRITIC
Non-spacing diacritic
nsvowel
C3_NSVOWEL
Non-spacing vowel
number
CT_NUMBER
Integers between 0 and 9
print
CT_PRINT
Everything except control characters
punct
CT_PUNCT
Punctuation marks
space
CT_SPACE
Whitespace and line ends
symbol
CT_SYMBOL
Symbol
upper
CT_UPPER
Upper case alphabetic character
vowelmark
C3_VOWELMARK
Vowel mark
xdigit
CT_XDIGIT
Hexadecimal digits (0-9, a-f or A-F)
_apl
CHS_APL
APL character
_arabic
CHS_ARABIC
Arabic character
_arrow
CHS_ARROW
Arrow character
_bengali
CHS_BENGALI
Bengali character
_bopomofo
CHS_BOPOMOFO
Bopomofo character
_box
CHS_BOX
Box or line drawing character
_currency
CHS_CURRENCY
Currency Symbol
_cyrillic
CHS_CYRILLIC
Cyrillic character
_dash
CHS_DASH
Dash character
_dingbat
CHS_DINGBAT
Dingbat
_fraction
CHS_FRACTION
Fraction value
_greek
CHS_GREEK
Greek character
_gujarati
CHS_GUJARATI
Gujarati character
_gurmukhi
CHS_GURMUKHI
Gurmukhi character
_hanguel
CHS_HANGUEL
Hanguel character
_hebrew
CHS_HEBREW
Hebrew character
_hiragana
CHS_HIRAGANA
Hiragana character set
_katakana
CHS_KATAKANA
Katakana character set
_lao
CHS_LAO
Laotian character
_latin
CHS_LATIN
Latin character
_linesep
CHS_LINESEP
Line separator
_math
CHS_MATH
Math symbol
_punctstart
CHS_PUNCTSTART
Punctuation start
_punctend
CHS_PUNCTEND
Punctuation end
_tamil
CHS_TAMIL
Tamil character
_telegu
CHS_TELEGU
Telegu character
_thai
CHS_THAI
Thai character
_userdef
CHS_USERDEF
User defined character
#arabicnum
C2_ARABICNUMBER
Arabic numbers
#blocksep
C2_BLOCKSEPARATOR
Block separator
#commonsep
C2_COMMONSEPARATOR
Common separator
#euronum
C2_EUROPENUMBER
European number
#eurosep
C2_EUROPESEPARATOR
European separator
#euroterm
C2_EUROPETERMINATOR
European terminator
#left
C2_LEFTTORIGHT
Left to right text orientation
#mirrored
C2_MIRRORED
Symmetrical text orientation
#neutral
C2_OTHERNEUTRAL
Other neutral
#right
CT_RIGHTTOLEFT
Right to left text orientation
#whitespace
C2_WHITESPACE
Whitespace

Related Functions

Example


This example shows how to query character attribute values using the
character attributes.
#include <stdio.h>
#include <unidef.h>
int main(void) {
    char    name[33];
    UniChar uname[33];
    UniChar * up;
    char    * cp;
    ulong   rc;
    /*
     * Ask the user for an attribute name
     */
    printf("Enter attribute name:");
    scanf("%s", &name);
    if (strlen(name) > 32)
      return 1;
    /*
     * Convert name to unicode
     */
    cp = name;
    up = uname;
    while (*cp) {
      *up++ = (UniChar)(*cp++);
    }
    *up = 0;
    /*
     * Query the attribute and print the value
     */

    rc = UniQueryAttr(tolower(uname));
    if (rc == 0) {
       printf("UniQueryAttr error: return code = %u\n", rc);
       return 1;
    } else
       printf("%s attribute = %x\n", name, rc);
       return ULS_SUCCESS;
}


UniQueryBlank

UniQueryBlank queries character attributes.

Format


#include <unidef.h>

int UniQueryBlank
(const LocaleObject locale_object, UniChar uc)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
uc  (UniChar) 
The UniChar character to query.

Returns

Return Value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

This function provides the functionality of UniCreateAttrObject, UniQueryCharAttr, and UniFreeAttrObject as an atomic operation for the invariant attributes.

The locale may be specified as NULL to indicate default Unicode character attributes

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L' ';    /* Unicode space character */
         /*****************************************************************/
         /* 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;
         }
         /* Query character attribute */
         result = UniQueryBlank(locale_object, uni_char);
         if (result)
           printf("UniChar character %04X is a blank character\n", uni_char);
         else
           printf("UniChar character %04X is not a blank character\n", uni_char);

return ULS_SUCCESS;
}


UniQueryChar

UniQueryChar determines if the character supplied has the attribute(s) requested.

Format


#include <unidef.h>

int UniQueryChar
(UniChar uc, ULONG attrName)


Parameters  

uc  (UniChar) 
The Unicode character whose attribute(s) are being examined.
 
attrName  (ULONG) 
The name of the attribute being examined in the Unicode character.

Returns

Return Value  (ulong)  -  returns 
If the named attribute is true for the Unicode character supplied, the function returns a 1. Otherwise, 0 is returned.

Remarks

This function takes the attributes supplied by the caller and tests the character to determine if they are true for that Unicode character. Attribute names that have a leading _ or # character represent classes of characters. These attributes must be tested as individual attributes. The remaining attributes can be or'ed together before testing.

Related Functions

Example


This example shows how to query if a character has particular attributes.
#include <stdio.h>
#include <unidef.h>
int main(void) {
         int          result = 0;
         UniChar      uni_char = L'A';    /* Unicode A character */

         /* Query character for upper case and graphic attributes */
         result = UniQueryChar(uni_char, C1_UPPER || C1_GRAPH);
         if (result)
           printf("UniChar is upper case and a graphic character\n");
         else
           printf("UniChar is not upper case and a graphic character\n"_;
         /* Query character for Latin character set attribute */
         result = UniQueryChar(uni_char, CHS_LATIN);
         if (result)
           printf("UniChar is a Latin character\n");
         else
           printf("UniChar is not a Latin character\n");

         return ULS_SUCCESS;
}

UniQueryCharAttr

UniQueryCharAttr queries the attributes of a character.

Format


#include <unidef.h>

int UniQueryCharAttr
(AttrObject attr_object, UniChar uc)


Parameters

attr_object  (AttrObject) 
An attribute object created by UniCreateAttrObject.  
 
uc  (UniChar) 
The UniChar character whose attributes will be queried.

Returns

return value  (int)  -  returns 
If the result of the test is true (the code element has the attribute associated with the attribute object, attr_object), UniQueryCharAttr returns the value 1.

If the result of the test is false, UniQueryCharAttr returns the value 0.

Remarks

UniQueryCharAttr determines whether the code element uc has the attributes specified by the attribute object argument, attr_object.

Related Functions

Example


This example shows how to create and use a character attribute object.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;

AttrObject   attr_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'c';    /* Unicode lowercase Latin letter c */
         /*****************************************************************/
         /* 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;
         }
         /* Create an attribute object */
         rc = UniCreateAttrObject(locale_object,
                                 (UniChar *)L"alpha xdigit", &attr_object);
         if (rc != ULS_SUCCESS) {
           printf("UniCreateAttrObject error: return code = %u\n", rc);
           return 1;
         }
         /* Make call to determine if character matches attributes */
         result = UniQueryCharAttr(attr_object, uni_char);
         if (result)
           printf("UniChar character %04X matches attributes\n", uni_char);
         else
           printf("UniChar character %04X does not match attributes\n", uni_char);
         return ULS_SUCCESS;

}


UniQueryCharType

UniQueryCharType is used to query the type of the character.

Format


#include <unidef.h>

UNICTYPE * UniQueryCharType
( UniChar uc )


Parameters

uc  (UniChar) 
The UniChar character whose type will be queried.

Returns

return value  (UNICTYPE *)  -  returns 
A pointer to a structure of type UNICTYPE Iis returned from this call.

Remarks

UniQueryCharType is designed to provide information to support both the XPG/4 character type as well as the Win32 GetCharType type.  Where the function is similar, this API is designed to be a superset of the Win32 function so that the Win32 functions can be supported by masking off bits in the returned data structure.  GetCharType is similar to the C library "is" functions. 

The UNICTYPE structure contains character set information, information regarding Bidirectional attributes, information regarding XPG/4 attributes and information on extended attributes. 

Related Functions

Example


This example shows how to query a character type.
#include <stdio.h>

#include <unidef.h>
int main(void) {
UNICTYPE     * uct;
UniChar      uni_char = 0x3456;    /* Some random Unicode character */
 
     /* Query the character type */
     uct = UniQueryCharType(uni_char);
 
     /* Examine the returned structure to determine information about
        the character.  For example, what is its BiDi orientation and
        is the character Arabic or Hebrew? */
     if (uct->bidi==C2_RIGHTTOLEFT)
        printf("Character is presented right to left\n");
     else
        printf("Character is presented left to right\n");
 
     if (uct->charset==CHS_ARABIC)
        printf("Character is Arabic\n");
     else if (uct->charset==CHS_HEBREW)
        printf("Character is Hebrew\n");
     else
        printf("Character is not Arabic or Hebrew\n");

return ULS_SUCCESS;
}


UniQueryCharTypeTable

UniQueryCharTypeTable is used to query the type of the character.

Format


#include <unidef.h>

ULONG UniQueryCharTypeTable
( ULONG * count, UNICTYPE * * unictype )


Parameters

count  (ULONG  *) 
count is set to the length of the table being accessed.
 
unictype  (UNICTYPE  *  *)
unictype is set to point to a table of UNICTYPE structures.

Returns

return value  (ULONG)  -  returns 
A ULONG equal to zero is always returned.

Remarks

UniQueryCharTypeTable is passed a pointer to a count and a pointer to a table of UNICTYPE structures.  count is set to the number of entries in the UNICTYPE structure table.  unictype is set to the first structure in the table.

Related Functions

Example


This example shows how to query a character type table.
#include <unidef.h>
#include <stdlib.h>
 
    /*
     * StringBidi: Determine bidi types for each character in a string
     * Return string of bidi bits, and return value with
     * OR of all bits.
     */
    USHORT StringBidi(UniChar * instr, USHORT * charsets) {
    ULONG count;
    UNICTYPE * typetab;
    USHORT index, *pcs, out;
    int rc, i, len;
 
    /*
     * Get addressability to the character type table
     */
    UniQueryCharTypeTable (&count, &typetab);
 
    /*
     * Create an output string
     */
    len = UniStrlen(instr);
    UniQueryStringType(instr, len, charsets, CT_INDEX);
 
    /*
     * Replace each index with bidi flags
     */
    pcs = charsets;
    out = 0;
    for (i=0; i<len; i++) {
        index = *pcs;
        *pcs = 0;
        if (typetab[index].bidi == C2_RIGHTTOLEFT)
            *pcs |= 1;
        if (typetab[index].charset == CHS_ARABIC)
            *pcs |= 2;
        if (typetab[index].charset == CHS_HEBREW)
            *pcs |= 4;
        out |= *pcs++;
    }
    return out;
}


UniQueryCntrl

UniQueryCntrl queries character attributes.

Format


#include <unidef.h>

int UniQueryCntrl
(const LocaleObject locale_object, UniChar uc)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
uc  (UniChar) 
The UniChar character to query.

Returns

Return Value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

This function provides the functionality of UniCreateAttrObject, UniQueryCharAttr, and UniFreeAttrObject as an atomic operation for the invariant attributes.

The locale may be specified as NULL to indicate default Unicode character attributes

Related Functions

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = 0x000A;    /* Unicode newline character */
         /*****************************************************************/
         /* 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;
         }
         /* Query character attribute */
         result = UniQueryCntrl(locale_object, uni_char);
         if (result)
           printf("UniChar character %04X is a control character\n", uni_char);
         else
           printf("UniChar character %04X is not a control character\n", uni_char);

return ULS_SUCCESS;
}


UniQueryCountryName

UniQueryCountryName returns the name of the country in the language specified.

Format


#include <unidef.h>

int UniQueryCountryName
(UniChar * country, UniChar * isolang, UniChar * * infoitem)


Parameters

country  (UniChar *) 
The two character ID of the country to query.  
 
isolang  (UniChar  *) 
The two character ID of the language used to return the country name.
 
infoitem  (UniChar  *  *)
A pointer to the country name.

Returns  

Return Value  (int)  -  returns 
UniQueryCountryName returns one of the following values:
ULS_INVALID
The country ID supplied is not known.
 
0 is returned upon success and the country name has been returned to the caller.

Remarks

Related Functions

Example


 
This example shows how to query a country name.
#include <stdio.h>

#include <unidef.h>
#include <ulsitem.h>
 
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      *pinfo;
UniChar      *langName;
UniChar      *countryName;
UniChar      *mriLanguage;
UniChar      uni_char = L'5';    /* Unicode number 5 character */
 
    /*****************************************************************/
    /* 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;
    }
 
    /* Determine the language to get the country name in */
    rc = UniQueryLocaleItem(locale_object, LOCI_sLanguageID,
            &mriLanguage);

    if (rc != ULS_SUCCESS) {
        printf("UniQueryLocaleItem error: return code = %u\n", rc);
        return 1;
    }
 
    /* Get the ISO country ID    
    rc = UniQueryLocaleItem(locale_object, LOCI_sCountryID, &pinfo);

    if (rc != ULS_SUCCESS) {
       printf("UniQueryLocaleItem error: return code = %u\n", rc);
       return 1;
    }
 
    /* Now we can determine the country name in the proper language */
    rc = UniQueryCountryName(pinfo, mriLanguage, &countryName);

    if (rc != ULS_SUCCESS) {
       printf("UniQueryCountryName error: return code = %u\n", rc);
       return 1;
    }
 
   printf("Country name is = %ls\n", countryName);

return ULS_SUCCESS;
}


UniQueryDigit

UniQueryDigit queries character attributes.

Format


#include <unidef.h>

int UniQueryDigit
(const LocaleObject locale_object, UniChar uc)


Parameters

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
uc  (UniChar) 
The UniChar character to query.
 

Returns  

Return Value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'5';    /* Unicode number 5 character */
         /*****************************************************************/
         /* 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;
         }
         /* Query character attribute */
         result = UniQueryDigit(locale_object, uni_char);
         if (result)
           printf("UniChar character %04X is a digit\n", uni_char);
         else
           printf("UniChar character %04X is not a digit\n", uni_char);

return ULS_SUCCESS;
}


UniQueryGraph

UniQueryGraph queries character attributes.

Format


#include <unidef.h>

int UniQueryGraph
(const LocaleObject locale_object, UniChar uc)


Parameters

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject or NULL.  
 
uc  (UniChar) 
The UniChar character to query.

Returns  

Return Value  (int)  -  returns 
If the result of the test is true, the function returns 1. Otherwise, 0 is returned.

Remarks

This function provides the functionality of UniCreateAttrObject, UniQueryCharAttr, and UniFreeAttrObject as an atomic operation for the invariant attributes.

The locale may be specified as NULL to indicate default Unicode character attributes

Related Functions

Example


This example shows how to query character attributes.
#include <stdio.h>

#include <unidef.h>
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      uni_char = L'S';    /* Unicode Latin uppercase letter S */
         /*****************************************************************/
         /* 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;
         }
         /* Query character attribute */
         result = UniQueryGraph(locale_object, uni_char);
         if (result)
           printf("UniChar character %04X is a graphic character\n", uni_char);
         else
           printf("UniChar character %04X is not a graphic character\n", uni_char);

return ULS_SUCCESS;
}


UniQueryLanguageName

UniQueryLanguageName returns the name of the language in the language specified.

Format


#include <unidef.h>

int UniQueryLanguageName
(UniChar * language, UniChar * isolang, UniChar * * infoitem)


Parameters

language  (UniChar *) 
The two character ID  of the language to query.  
 
isolang  (UniChar  *) 
The two character ID of the language used to return the language name.
 
infoitem  (UniChar  *  *)
A pointer to the language name.

Returns  

Return Value  (int)  -  returns 
UniQueryLanguageName returns one of the following values:
ULS_INVALID
The language ID supplied is not known.
 
0 is returned upon success and the language name has been returned to the caller.

Remarks

Related Functions

Example


 
This example shows how to query a language name.
#include <stdio.h>

#include <unidef.h>
#include <ulsitem.h>
 
int main(void) {
LocaleObject locale_object = NULL;
int          result = 0;
int          rc = ULS_SUCCESS;
UniChar      *pinfo;
UniChar      *languageName;
UniChar      *mriLanguage;
UniChar      uni_char = L'5';    /* Unicode number 5 character */
 
    /*****************************************************************/
    /* 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;
    }
 
    /* Determine the language to get the language name in */
    rc = UniQueryLocaleItem(locale_object, LOCI_sLanguageID,
            &mriLanguage);

    if (rc != ULS_SUCCESS) {
        printf("UniQueryLocaleItem error: return code = %u\n", rc);
        return 1;
    }
 
    /* Get the ISO country ID    
    rc = UniQueryLocaleItem(locale_object, LOCI_sLanguageID, &pinfo);

    if (rc != ULS_SUCCESS) {
       printf("UniQueryLocaleItem error: return code = %u\n", rc);
       return 1;
    }
 
    /* Now we can determine the country name in the proper language */
    rc = UniQueryCountryName(pinfo, mriLanguage, &languageName);

    if (rc != ULS_SUCCESS) {
       printf("UniQueryCountryName error: return code = %u\n", rc);
       return 1;
    }
 
   printf("Language name is = %ls\n", languageName);

return ULS_SUCCESS;
}

UniQueryLocaleInfo

UniQueryLocaleInfo retrieves information about locale conventions.

Format


#include <unidef.h>

int UniQueryLocaleInfo
(const LocaleObject locale_object, struct UniLconv **UniLconv_addr_ptr)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject.
 
UniLconv_addr_ptr  (struct UniLconv **) 
The address of a pointer to receive a structure filled with locale conventions.

Returns  

return value  (int)  -  returns 
UniQueryLocaleInfo returns one of the following values:
ULS_SUCCESS
The UniLconv structure was successfully filled with items associated with the locale object locale_object.
ULS_BADOBJ
The locale object specified by locale_object is not a valid locale object.

Remarks

UniQueryLocaleInfo retrieves information from the locale indicated by the locale_object argument and places the information in a UniLconv structure. UniQueryLocaleInfo allocates memory to hold the UniLconv structure. It is the application's responsibility to free the memory with UniFreeLocaleInfo when the UniLconv structure is no longer needed. The address of the UniLconv structure is returned in UniLconv_struct. The UniLconv structure is filled in, according to the locale indicated by the locale object handle argument.

The UniLconv structure contains the following members:

UniChar *decimal_point;
/* non-monetary decimal point */
UniChar *thousands_sep;
/* non-monetary thousands separator */
UniChar *grouping;
/* non-monetary size of grouping */
UniChar *int_curr_symbol;
/* international currency symbol and separator */
UniChar *currency_symbol;
/* local currency symbol */
UniChar *mon_decimal_point;
/* monetary decimal point */
UniChar *mon_thousands_sep;
/* monetary thousands separator */
UniChar *mon_grouping;
/* monetary size of grouping */
UniChar *positive_sign;
/* non-negative values sign */
UniChar *negative_sign;
/* negative values sign */
UniChar int_frac_digits;
/* number of fractional digits - int currency */
UniChar frac_digits;
/* number of fractional digits - local currency */
UniChar p_cs_precedes;
/* (non-neg curr sym) 1-precedes, 0-succeeds */
UniChar p_sep_by_space;
/* (non-neg curr sym) 1-space, 0-no space */
UniChar n_cs_precedes;
/* (neg curr sym) 1-precedes, 0-succeeds */
UniChar n_sep_by_space;
/* (neg curr sym) 1-space, 0-no space */
UniChar p_sign_posn;
/* positioning of non-negative monetary sign */
UniChar n_sign_posn;
/* positioning of negative monetary sign */
short os2_mondecpt;
/* os2 curr sym positioning */
UniChar *debit_sign;
/* non-negative-valued monetary symbol - "DB"*/
UniChar *credit_sign;
/* negative-valued monetary symbol - "CR" */
UniChar *left_parenthesis;
/* negative-valued monetary symbol - "(" */
UniChar *right_parenthesis;
/* negative-valued monetary symbol - ")" */

The value of grouping and mon_grouping is interpreted according to the following:

0xffff
No further grouping is to be performed.
0x0000
The previous element is to be repeatedly used for the remainder of the digits.
other
The integer value is the number of digits that comprise the current group.

The next element is examined to determine the size of the next group of digits before the current group.

The n_sign_posn and p_sign_posn elements are interpreted according to the following:

0
Quantity and currency_symbol are enclosed in parentheses
1
Sign precedes the quantity and currency_symbol
2
Sign follows the quantity and currency_symbol
3
Sign precedes the currency_symbol
4
Sign follows the currency_symbol
5
Use debit or credit sign for p_sign_posn or n_sign_posn

Related Functions

Example


This example shows how to retrieve information about locale conventions.
#include <stdio.h>
#include <unidef.h>

int main(void) {
LocaleObject      locale_object = NULL;
struct UniLconv   *puni_lconv = NULL;

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;
         }
         /* Retrieve locale information */
         rc = UniQueryLocaleInfo(locale_object, &puni_lconv);
         if (rc != ULS_SUCCESS) {
           printf("UniQueryLocaleInfo error: return code = %u\n", rc);
           return 1;
         }
         /* print the value of the os2 currency symbol position */
         printf("The os2 currency symbol position is %d\n",
                 puni_lconv->os2_mondecpt);
         return ULS_SUCCESS;

}


UniQueryLocaleItem

UniQueryLocaleItem retrieves locale information by item.

Format


#include <unidef.h>

int UniQueryLocaleItem
(const LocaleObject locale_object, LocaleItem item, UniChar **info_item_addr_ptr)


Parameters  

locale_object  (const LocaleObject) 
A locale object created by UniCreateLocaleObject.  
item  (LocaleItem) 
The item to be queried.  
 
info_item_addr_ptr  (UniChar **) 
Address of a pointer where the locale information will be received.

Returns  

return value  (int)  -  returns 
UniQueryLocaleItem returns one of the following values:
ULS_SUCCESS
The info_item_addr_ptr string is successfully filled with item associated with the locale object locale_object.
ULS_INVALID
The locale item is not a valid locale item.

Remarks

UniQueryLocaleItem returns a pointer in info_item_addr_ptr to a null-terminated UniChar string containing information found in the locale object identified by locale_object about the language or cultural item named by the item argument. UniQueryLocaleItem allocates the memory to hold the UniChar string and returns a pointer in info_item_addr_ptr. Use UniFreeMem to free the memory associated with info_item_addr_ptr by UniQueryLocaleItem.

The constant names and values for item are contained in ulsitem.h:
Item Name
Item Description
LOCI_sDateTime
Date and time format string
LOCI_sShortDate
Short date format
LOCI_sTimeFormat
Time format string