From dfa9161f56838bf20d32b701208f07ccad3ff970 Mon Sep 17 00:00:00 2001
From: Christian Humer <christian.humer@oracle.com>
Date: Wed, 19 Aug 2015 13:37:20 +0200
Subject: [PATCH] Make pretty printer more flexible for different character
 representations.

---
 .../r/nodes/builtin/base/PrettyPrinterNode.java    | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
index e59e132970..b746c83368 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/PrettyPrinterNode.java
@@ -612,7 +612,7 @@ public abstract class PrettyPrinterNode extends RNode {
         if (rowHeaderUsesIndices(dimNames)) {
             return concat("[", intString(c), ",]");
         } else {
-            RStringVector dimNamesVector = (RStringVector) dimNames.getDataAt(0);
+            RAbstractStringVector dimNamesVector = (RAbstractStringVector) getDimNamesAt(dimNames, 1);
             String dimId = dimNamesVector.getDataAt(c - 1);
             if (RRuntime.isNA(dimId)) {
                 dimId = RRuntime.NA_HEADER;
@@ -631,15 +631,23 @@ public abstract class PrettyPrinterNode extends RNode {
     private static String getDimId(RAbstractVector vector, int dimLevel, int dimInd, RAttributeProfiles attrProfiles) {
         String dimId;
         RList dimNames = vector.getDimNames(attrProfiles);
-        if (dimNames == null || dimNames.getDataAt(dimLevel - 1) == RNull.instance) {
+        if (dimNames == null || getDimNamesAt(dimNames, dimLevel) == RNull.instance) {
             dimId = intString(dimInd + 1);
         } else {
-            RStringVector dimNamesVector = (RStringVector) dimNames.getDataAt(dimLevel - 1);
+            RAbstractStringVector dimNamesVector = (RAbstractStringVector) getDimNamesAt(dimNames, dimLevel);
             dimId = dimNamesVector.getDataAt(dimInd);
         }
         return dimId;
     }
 
+    private static Object getDimNamesAt(RList dimNames, int dimLevel) {
+        Object result = dimNames.getDataAt(dimLevel - 1);
+        if (result instanceof String) {
+            return RString.valueOf((String) result);
+        }
+        return result;
+    }
+
     private static double calcRoundFactor(double input, long maxFactor) {
         if (Double.isNaN(input) || Double.isInfinite(input) || input == 0.0) {
             return maxFactor * 10;
-- 
GitLab