Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-7071

The sort() function should support multilanguage.

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.2.0
    • Component/s: Querying
    • Labels:
      None
    • Environment:
      windows 7, language zh_CN.UTF-8

      My local language is zh_CN.UTF-8.
      When I do query using sort(),the return values may be wrong.
      As you know, the sort() use compareElementValues() do strings' compare.
      In compareElementValues():
      ...
      case String:
      /* todo: a utf sort order version one day... */

      { // we use memcmp as we allow zeros in UTF8 strings int lsz = l.valuestrsize(); int rsz = r.valuestrsize(); int common = std::min(lsz, rsz); int res = memcmp(l.valuestr(), r.valuestr(), common); if( res ) return res; // longer string is the greater one return lsz-rsz; }

      ...
      This function use memcmp() do compare, so it can return right result with UTF8 string ,but not zh_CN.UTF-8.
      May be we can use strcoll() instead of memcmp() here, the it can support multilanguage sort.
      strcoll can compare two strings using locale language:

      int strcoll ( const char * str1, const char * str2 );
      Compare two strings using locale
      Compares the C string str1 to the C string str2, both interpreted appropiately according to the LC_COLLATE category of the current locale.
      This function starts comparing the first character of each string. If they are equal to each other continues with the following pair until the characters differ or until a null-character signaling the end of a string is reached.

      For more informationg, see http://www.cplusplus.com/reference/clibrary/cstring/strcoll/ and http://www.cplusplus.com/reference/clibrary/clocale/setlocale/

            Assignee:
            Unassigned Unassigned
            Reporter:
            tomliugen liugen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: