UniScanForAttr

From EDM2
Jump to: navigation, search

UniScanForAttr scans a Unicode string for an attribute match.

Syntax

UniScanForAttr (attr_object, ucs, num_elems, inverse_op, offset)

Parameters

attr_object (AttrObject)
An attribute object created by UniCreateAttrObject.
ucs (const UniChar *)
The array of UniChar code elements to be scanned for the set of attributes in attr_object.
num_elems (size_t)
The number of UniChar code elements to be searched.
inverse_op (ulsBool)
Determines scanning rules. Set to FALSE to search for the first match. Set to TRUE to search for the first nonmatching element.
offset (size_t *)
An integer identifying the location of the first element meeting the criteria.

Returns

Return value (int) - returns:

ULS_SUCCESS 
The function was successful.
ULS_NOMATCH 
No code element meets the specified criteria.
ULS_BADOBJ 
The attribute object specified by attr_object is not a valid attribute object.

Remarks

UniScanForAttr scans the array of code elements identified by ucs, from the position specified by ucs, searching for the first code element that matches or does not match the set of attributes specified by attr_object.

The inverse_op argument determines the rules for scanning and is an integer type containing one of the following values:

0 : FALSE
1 : TRUE

If inverse_op is set to FALSE, the function searches for the first code element that matches all of the attributes of the specified attr_object; if inverse_op is set to TRUE, the function searches for the first code element that matches none of the attributes of attr_object.

The search begins from the code element identified by ucs, through the next num_elems code elements. A non-negative integer identifying the location of the first code element meeting all of the criteria specified by attr_object is returned in the area pointed to by offset. This indicates the number of code elements offset from the code element identified by ucs, to the code element at which the attribute match is satisfied. If no code element meets the specified criteria, the contents of offset are undefined.

Example

This example shows how to scan a Unicode string for an attribute match.

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

int main(void) {

     LocaleObject locale_object = NULL;
     AttrObject   attr_object = NULL;
     int          result = 0;
     int          rc = ULS_SUCCESS;
     size_t       offset = 0;
     UniChar      *uni_char = L"os2";

     /*****************************************************************/
     /* 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"digit", &attr_object);
     if (rc != ULS_SUCCESS) {
       printf("UniCreateAttrObject error: return code = %u\n", rc);
       return 1;
     }

     /* Make call to determine if string matches attributes */
     rc = UniScanForAttr(attr_object, uni_char, UniStrlen(uni_char),
                         FALSE, &offset);
     if (rc != ULS_SUCCESS) {
       printf("UniScanForAttr error: return code = %u\n", rc);
       return 1;
     }
     return ULS_SUCCESS;
} 

Format

#include <unidef.h>

int UniScanForAttr (
    AttrObject    attr_object,    /* I  - Attribute object                     */
    const UniChar *ucs,           /* I  - Unicode input string to be scanned   */
    size_t        num_elems,      /* I  - Maximum number of characters to scan */
    ulsBool       inverse_op,     /* I  - Search type flag                     */
    size_t        *offset         /* O  - Position of first character found    */
)

Related Functions