collrange() — Calculate the range list of collating elements

Standards

Standards / Extensions C or C++ Dependencies
Language Environment both  

Format

#include <collate.h>

int collrange(collel_t start, collel_t end, collel_t **list);

General description

Finds a list of collating elements whose primary weights are between the start and end points, inclusive. The number returned is the number of elements in the list, whose pointer is returned.

This value will be zero if the end point collates earlier than the start point. The list returned is valid until the next call to setlocale().

Returned value

If successful, collrange() returns the number of elements in the list, whose pointer is returned.

If either start or end are out of range, collrange() returns -1.

Notes:
  1. Collating elements specified with the weight of IGNORE in the LC_COLLATE category are defined having the lowest weight. Therefore, such elements can only be specified as the starting collating element.
  2. The list will only contain characters defined in the charmap file in the current locale.

Example

CELEBC24
⁄* CELEBC24

   This example prints the collating elements in the range
   between the start and end points passed in
   argv[1] and argv[2], using the
   &collrap. function.

 *⁄
#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 s, e, *rp;
   int i;

   setlocale(LC_ALL, "TEXAN.IBM-1024");
   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