collequiv() — Return a list of equivalent collating elements
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Language Environment | both |
Format
#include <collate.h>
int collequiv(collel_t c, collel_t **list);
General description
Finds all the collating elements whose primary weight is the same as the primary weight of c. It then updates the list to point to the first element of the array in which all the found elements are stored. The list of elements is valid until the next call to setlocale(), with categories LC_ALL, LC_COLLATE, or LC_CTYPE.
Another call to collequiv() may override the current list.
For information about the effect of setlocale() and locale.h, see “Internationalization: Locales and Character Sets” in z/OS XL C/C++ Programming Guide.
Returned value
If successful, collequiv() returns the number of collating elements found.
If the value of c is not in the valid range of collating elements in the current locale, collequiv() returns -1.
Notes:
- If the collating element passed is specified with the weight of IGNORE in the LC_COLLATE category, the list returned will contain all the characters specified as IGNORE.
- The list will only contain characters defined in the charmap file in the current locale.
Example
CELEBC22
/* CELEBC22
This example prints the collating elements that have an
equivalent weight as the collating element passed in
argv[1].
*/
#include "stdio.h"
#include "locale.h"
#include "collate.h"
#include "stdlib.h"
#include "wctype.h"
#include "wchar.h"
main(int argc, char *argv[]) {
collel_t e, *rp;
int i;
setlocale(LC_ALL, "");
if ((e = strtocoll(argv[1])) == (collel_t)-1) {
printf("'%s' collating element not defined\n", argv[1]);
exit(1);
}
if ((i = collequiv(e, &rp)) == -1) {
printf("Invalid collating element '%s'\n", argv[1]);
exit(1);
}
for (; i-- > 0; rp++) {
if (ismccollel(*rp))
printf("'%s' ", colltostr(*rp));
else if (iswprint(*rp))
printf("'%lc' ", *rp);
else
printf("'%x' ", *rp);
}
}
Related information
- collate.h
- cclass() — Return characters in a character class
- collorder() — Return list of collating elements
- collrange() — Calculate the range list of collating elements
- colltostr() — Return a string for a collating element
- getmccoll() — Get next collating element from string
- getwmccoll() — Get next collating element from wide string
- ismccollel() — Identify a multicharacter collating element
- maxcoll() — Return maximum collating element
- strtocoll() — Return collating element for string