From 02d39b6f157c87d36caf702756da55f29fbb277e Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Tue, 6 Feb 2018 15:50:41 +0100 Subject: [PATCH] ls builtin respects the Locale when ordering the result --- .../r/nodes/builtin/base/OptionsFunctions.java | 4 +--- .../com/oracle/truffle/r/runtime/RLocale.java | 6 +++++- .../env/frame/REnvTruffleFrameAccess.java | 16 ++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java index 53722a742e..1e1194bbfc 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/OptionsFunctions.java @@ -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()); } }); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RLocale.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RLocale.java index 649cb26fc0..d0f4a304f5 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RLocale.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RLocale.java @@ -1,5 +1,5 @@ /* - * 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); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/frame/REnvTruffleFrameAccess.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/frame/REnvTruffleFrameAccess.java index a1bab552c1..c6c6e182eb 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/frame/REnvTruffleFrameAccess.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/env/frame/REnvTruffleFrameAccess.java @@ -1,5 +1,5 @@ /* - * 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); } -- GitLab