UniCreateAttrObject

From EDM2
Jump to: navigation, search

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

Syntax

UniCreateAttrObject (locale_object, AttrName, attr_object)

Parameters

locale_object (const LocaleObject)
A 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

ULS_SUCCESS
Successful completion; attr_object points to a valid attribute object.
ULS_UNSUPPORTED
The attribute name specified in AttrName is not supported by 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 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 UniQueryAttr 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 space and horizontal tab characters.
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.

Examples

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

Related Functions