### Function

# GLib utf8_collate_key_for_filename

since: 2.8

#### Declaration [src]

    gchar*
    g_utf8_collate_key_for_filename (
      const gchar* str,
      gssize len
    )

#### Description [src]

Converts a string into a collation key that can be compared with other collation keys produced by the same function using strcmp().

In order to sort filenames correctly, this function treats the dot ‘.’ as a special case. Most dictionary orderings seem to consider it insignificant, thus producing the ordering “event.c” “eventgenerator.c” “event.h” instead of “event.c” “event.h” “eventgenerator.c”. Also, we would like to treat numbers intelligently so that “file1” “file10” “file5” is sorted as “file1” “file5” “file10”.

Note that this function depends on the current locale.

Note that the returned string is not guaranteed to be in any encoding, especially UTF-8. The returned value is meant to be used only for comparisons.

Available since: 2.8

#### Parameters

`str`

  Type: `const gchar*`

  A UTF-8 encoded string.

  The data is owned by the caller of the function.
  The value is a NUL terminated UTF-8 string.

`len`

  Type: `gssize`

  Length of `str`, in bytes, or -1 if `str` is nul-terminated.

#### Return value

Type: `gchar*`

A newly allocated string. The contents of the string are only meant to be used when sorting. This string should be freed with `g_free()` when you are done with it.

The caller of the function takes ownership of the data, and is responsible for freeing it.
The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.