Questions tagged [collator]

A Collator is a class which performs locale-sensitive String comparison. You can use this class to build searching and sorting routines for natural language text processing.

The Collator class performs locale-sensitive String comparison. You use this class to build searching and sorting routines for natural language text processing.

Java documentation can be found here

30 questions
11
votes
1 answer

Intl.Collator for JS Objects

I am not able to find any example of sorting objects using collator.compare anywhere. Can anyone provide ? All the documentation and examples so far I came across show array sorting as example below: var myArray = ['1_Document', '11_Document',…
user2004082
  • 141
  • 2
  • 8
7
votes
2 answers

Numeric comparing option for Java Collator

Problem: Let's say we have the following list of strings {"Test1.txt", "Test2.txt", "Test11.txt", "Test22.txt"}, sorting them using String::compareTo or Collator::compare would result in following…
Alireza Dastyar
  • 88
  • 1
  • 11
3
votes
1 answer

Why does Intl.Collator sort negative numbers in descending order?

I cam across this use case and I am puzzled by it : const naturalCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }); const comparator = (a, b) => naturalCollator.compare(a, b); const numbers = [-1, 0, 1, 10, NaN,…
Yanick Rochon
  • 51,409
  • 25
  • 133
  • 214
3
votes
0 answers

Unexpected output using Intl.Collator with Latvian alphabet

I need to sort an array of objects by key in Latvian language but when I use Intl.Collator or compareLocale, the output is not correct. My example: function letterSort(lang, strings) { strings.sort(new Intl.Collator(lang).compare); return…
Kristine
  • 737
  • 2
  • 9
  • 22
3
votes
2 answers

Using Collator with Ukrainian language

Please look at my method where I try to implement Collator to sort Objects with a "title" field. Method: public List findAllByOrderByTitle() { List schoolSubjects = subjectRepository.findAllByOrderByTitle(); …
3
votes
0 answers

Can we check if the locale output from boost::locale::generator::generate is invalid?

This is a 2-part question that began with me wondering: what happens if the ID input to boost::locale::generator::generate() was some invalid value? I checked the documentation and I couldn't find anything on what happens if we passed in something…
cechow
  • 170
  • 8
3
votes
2 answers

Collator Locale German - How to sort accented letters only after the normal ones

i have used Collator to sort an array of objects. But I found out that it treats accented letters like normal ones: Aktivierung Änderung Auszahlung Bar instead i would like to have this Aktivierung Auszahlung Änderung Bar the accented letter…
ayasha
  • 1,221
  • 5
  • 27
  • 46
2
votes
0 answers

JavaScript: Sort a string that contains letters and numbers in a case-sensitive manner using Intl.Collator

With the requirement that I need to use the Intl.Collator (English language only) to sort strings that contains both letters and numbers (anywhere in the string). I need to have them sorted such that: Capital letters come before lower-case letters…
Russ
  • 623
  • 8
  • 14
2
votes
1 answer

How to sort by Numbers first then Alphabetical

I'm trying to sort an array: ["B3", "D2", "F1", "A9", "D12", "A2", "C1", "Z0", "B1"] The expected output should be: ["Z0", "B1", "C1", "F1", "A2", "D2", "B3", "A9", "D12"] Here's my code: let array = ["B3", "D2", "F1", "A9", "D12", "A2", "C1",…
2
votes
3 answers

Custom Intl.Collator in JS

I need to sort this array ['$', 'z', 7, 'a', 1, '%', '.', 5, '% hello', ' ', 'f', '^' , '-', '_'] as [ , %, % hello, _, -, ., ^, $, 1, 5, 7, a, f, z] But the result I'm getting is [ , _, -, ., %, % hello, ^, $, 1, 5, 7, a, f, z] Is there any…
Jessica David
  • 117
  • 3
  • 11
2
votes
1 answer

JavaScript sorting: Collator - Fix for aa (å)

I'm trying to make a sorting system. The problem I am facing is that the 'aa' comes last because in Danish 'aa' means 'å' and that is why it is last. If it is possible I want the 'aa' to be first and not last in the list. So to simplify, this is the…
2
votes
0 answers

Java Collator orders the strings in French incorrectly

I've been attempting to sort text in French, but been having problems. Java Collator class seems to order some strings incorrectly. Please suggest why this is happening? import java.util.List; import java.util.stream.Stream; import…
Henco
  • 59
  • 4
2
votes
5 answers

Javascript how to sort array of objects by numeric value of the string

Below is an example of my array of objects and I am supposed to sort these by name. The js normal sorting sorts as shown below, however my target is to sort by the numeric value, eg: "1 ex, 2 ex, 3 ex, 4 ex, 11 ex ..". Could someone help me how to…
user2004082
  • 141
  • 2
  • 8
1
vote
0 answers

Sorting text field in PostgreSQL is not sorting as expected

I have a text column in PostgreSQL that I am ordering by in ASC order and it is returning the following order: SELECT column_A FROM table ORDER BY column_A ASC: column_A IKvap06:52:22.52 i.lost.all.my.tacos IQKPb06:55:51.53 But I was…
1
vote
2 answers

sorting Hungarian dictionary

I'm trying to sort Hungarian words in the dictionary by alphabetical order. The expected order for all letters should be aábcdeéfggyhiíjklmnoóöőpqrsttyuúüűvwxyz I was trying to use Intl.Collator() and localeCompare but the expected output was never…
1
2