0

In my Linux environment, I use u8_casecoll to sort strings. With local set to "en_US.UTF-8", below is the sort order.

  1. "Member1_LN"
  2. "Member Group"

But in Windows environment, I use CompareStringW to sort, and below is the sort order.

  1. "Member Group"
  2. "Member1_LN"

I have a requirement to make the Linux environment exhibit the same behavior as Windows. Can someone help to tweak the Linux code to get the expected sort order? Thanks in advance.

Below is the C code for the Linux environment.

#include <errno.h>
#include <locale.h>
#include <unitypes.h>
int main()
{
    setlocale(LC_ALL, "en_US.UTF-8");
    uint8_t text1[] = "Member1_LN";
    uint8_t text2[] = "Member Group";
    int ret_val = 0;
    int resultp = 0;
    ret_val = u8_casecoll(text1,u8_strlen(text1),text2,u8_strlen(text2), NULL, NULL, &resultp);
    if(0 == ret_val)
    {
        printf("resultp = %d\n", resultp);
        printf("expected = 1\n");
    }
    else
    {
        int err = errno;
        printf("u8_casecoll ret = %d errno = %d\n", ret_val, err);
    }
    return 0;
}

Output:

resultp = -1
expected = 1
Wolf
  • 9,679
  • 7
  • 62
  • 108
  • You might want to research the behavior of these different functions, especially on how they treat character like `underscore, white-space` and upper/lowercase. Suggest you to test using alphabet only (leave out the `underscore, white-space`) on both systems and see if the deviation still happen. – Agus Dec 05 '20 at 16:17
  • To replicate the Windows comparison function you probably want to try a comparison function, rather than a collation function. That would be u8_casecmp. But there is no guarantee. If you want guaranteed identical results, use the same function. – n. m. could be an AI Dec 05 '20 at 16:34
  • Thanks for your suggestion. I'll try it out. – Natarajan R J Dec 07 '20 at 05:16

0 Answers0