strtocoll() — Return collating element for string
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
Language Environment |
both |
Format
#include <collate.h>
collel_t strtocoll(char *s);
General description
Determines whether the string pointed to by s represents the valid element as defined in the LC_COLLATE category of the current locale.
If a string pointed to by s contains only one character, the collating element representing this character always exists. Otherwise, a valid collating element exists if the LC_COLLATE category contains the definition of a sequence of characters that collate as one for the purpose of culture-sensitive string comparison. This many-characters-to-one-collating element relation is also called many-to-one mapping.
Returned value
The type collel_t represents the collating elements.
If many-to-one mapping is not defined in the LC_COLLATE of the current locale, strtocoll() returns (collel_t)-1.
Also, if the string is not a valid collating element or is of zero length, strtocoll() returns (collel_t)-1.
Example
/* CELEBS52
This example uses the strtocoll() function to get the
collel_t value for the start and end collating-elements for
the collrange() function.
*/
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
#include <collate.h>
#include <wchar.h>
#include <wctype.h>
main(int argc, char *argv[]) {
collel_t s, e, *rp;
int i;
setlocale(LC_ALL, "");
if ((s = strtocoll(argv[1])) == (collel_t)-1) {
printf("%s collating element not defined\n", argv[1]);
exit(1);
}
if ((e = strtocoll(argv[2])) == (collel_t)-1) {
printf("%s collating element not defined\n", argv[2]);
exit(1);
}
if ((i = collrange(s, e, &rp)) == -1) {
printf("Invalid range for %s to %s\n", argv[1], argv[2]);
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
- collequiv() — Return a list of equivalent collating elements
- 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