add maxLength argument to Input.showRegion()
authoradam <adam@megacz.com>
Tue, 27 Mar 2007 23:39:13 +0000 (19:39 -0400)
committeradam <adam@megacz.com>
Tue, 27 Mar 2007 23:39:13 +0000 (19:39 -0400)
darcs-hash:20070327233913-5007d-bdcad3b136e659105f9c22fb9881653e3b5daab1.gz

src/edu/berkeley/sbp/Input.java
src/edu/berkeley/sbp/chr/CharInput.java
src/edu/berkeley/sbp/tib/Tib.java

index 13c45d4..bf0d50d 100644 (file)
@@ -22,12 +22,13 @@ public interface Input<Token> {
 
     /**
      *  <b>Optional:</b> <i>If possible</i>, this method will return a
 
     /**
      *  <b>Optional:</b> <i>If possible</i>, this method will return a
-     *  <60 char long rendering of the input region (for example, if
-     *  the input is a region of characters, it would be those
-     *  characters, possibly with ellipses in the middle to truncate
-     *  the length) -- otherwise, returns null.
+     *  rendering of the input region (for example, if the input is a
+     *  region of characters, it would be those characters) --
+     *  otherwise, returns null.  In any case, the string returned
+     *  will be no more than <tt>maxLength</tt> characters long;
+     *  typically ellipses will be inserted to perform truncation.
      */
      */
-    public abstract String showRegion(Region<Token> r);
+    public abstract String showRegion(Region<Token> r, int maxLength);
 
     /** <font color=purple>a location (position) in the input stream -- <i>between tokens</i></font> */
     public static interface Location<Token> extends Comparable<Location> {
 
     /** <font color=purple>a location (position) in the input stream -- <i>between tokens</i></font> */
     public static interface Location<Token> extends Comparable<Location> {
index a03f940..3ebbb88 100644 (file)
@@ -157,7 +157,7 @@ public class CharInput extends Cartesian.Input<Character> {
         if (i>0) { r.unread(CharAtom.left); redent(i-1); return; }
     }
 
         if (i>0) { r.unread(CharAtom.left); redent(i-1); return; }
     }
 
-    public String showRegion(Region<Character> rc) {
+    public String showRegion(Region<Character> rc, int maxLength) {
         if (cache == null) return null;
         Cartesian.Region r = (Cartesian.Region)rc;
         int start = r.getStart().getScalar()+1;
         if (cache == null) return null;
         Cartesian.Region r = (Cartesian.Region)rc;
         int start = r.getStart().getScalar()+1;
@@ -166,10 +166,10 @@ public class CharInput extends Cartesian.Input<Character> {
         if (end < start) end = start;
         if (end > cache.length()) end = cache.length();
         String ret;
         if (end < start) end = start;
         if (end > cache.length()) end = cache.length();
         String ret;
-        if (end-start < 60) ret = cachesubstring(start, end);
-        else ret = cachesubstring(start, start+25) +
+        if (end-start < maxLength) ret = cachesubstring(start, end);
+        else ret = cachesubstring(start, start+(maxLength/2-5)) +
                  "..." +
                  "..." +
-                 cachesubstring(end-25, end);
+                 cachesubstring(end-(maxLength/2-5), end);
         return StringUtil.escapify(ret, "\n\r");
     }
 
         return StringUtil.escapify(ret, "\n\r");
     }
 
index 387f5ed..a86b3ab 100644 (file)
@@ -20,7 +20,7 @@ import java.io.*;
  */
 public class Tib implements Input<Character> {
 
  */
 public class Tib implements Input<Character> {
 
-    public String showRegion(Region<Character> r) { return ""; }
+    public String showRegion(Region<Character> r, int max) { return ""; }
 
     public Tib(String s) throws IOException { this(new StringReader(s)); }
     public Tib(Reader r) throws IOException { this(new BufferedReader(r)); }
 
     public Tib(String s) throws IOException { this(new StringReader(s)); }
     public Tib(Reader r) throws IOException { this(new BufferedReader(r)); }