Skip to content
Snippets Groups Projects
Commit 02d39b6f authored by stepan's avatar stepan
Browse files

ls builtin respects the Locale when ordering the result

parent 1aaa6e9f
No related branches found
No related tags found
No related merge requests found
......@@ -87,9 +87,7 @@ public class OptionsFunctions {
Arrays.sort(entries, new Comparator<Map.Entry<String, Object>>() {
@Override
public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
String k1 = o1.getKey();
String k2 = o2.getKey();
return collator == null ? k1.compareTo(k2) : collator.compare(k1, k2);
return RLocale.compare(collator, o1.getKey(), o2.getKey());
}
});
......
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -74,6 +74,10 @@ public enum RLocale {
return collator;
}
public static int compare(Collator collator, String k1, String k2) {
return collator == null ? k1.compareTo(k2) : collator.compare(k1, k2);
}
public static final class ContextStateImpl implements RContext.ContextState {
private final EnumMap<RLocale, Locale> locales = new EnumMap<>(RLocale.class);
private final EnumMap<RLocale, Charset> charsets = new EnumMap<>(RLocale.class);
......
/*
* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -22,9 +22,12 @@
*/
package com.oracle.truffle.r.runtime.env.frame;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.regex.Pattern;
......@@ -38,7 +41,9 @@ import com.oracle.truffle.api.frame.FrameSlotTypeException;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.r.runtime.RError;
import com.oracle.truffle.r.runtime.RError.Message;
import com.oracle.truffle.r.runtime.RLocale;
import com.oracle.truffle.r.runtime.RRuntime;
import com.oracle.truffle.r.runtime.context.RContext;
import com.oracle.truffle.r.runtime.data.RDataFactory;
import com.oracle.truffle.r.runtime.data.RMissing;
import com.oracle.truffle.r.runtime.data.RStringVector;
......@@ -193,7 +198,14 @@ public final class REnvTruffleFrameAccess extends REnvFrameAccess {
String[] data = new String[matchedNamesList.size()];
matchedNamesList.toArray(data);
if (sorted) {
Arrays.sort(data);
Locale locale = RContext.getInstance().stateRLocale.getLocale(RLocale.COLLATE);
Collator collator = locale == Locale.ROOT || locale == null ? null : RLocale.getOrderCollator(locale);
Arrays.sort(data, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return RLocale.compare(collator, o1, o2);
}
});
}
return RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment