X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Fchr%2FCharInput.java;h=e4ac550af670981cb98c6ce5fb20941302c46bc1;hp=95609bc3be232c1ddb061ee45d1b33753652adb6;hb=HEAD;hpb=e87676acf584aa0cd6786f001b0c343631c8d2de diff --git a/src/edu/berkeley/sbp/chr/CharInput.java b/src/edu/berkeley/sbp/chr/CharInput.java index 95609bc..e4ac550 100644 --- a/src/edu/berkeley/sbp/chr/CharInput.java +++ b/src/edu/berkeley/sbp/chr/CharInput.java @@ -1,4 +1,4 @@ -// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license +// Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license package edu.berkeley.sbp.chr; import java.io.*; @@ -59,17 +59,23 @@ public class CharInput extends Cartesian.Input { private final RollbackReader r; - public CharInput(String s) { this(new StringReader(s)); } - public CharInput(Reader r) { this(r, null); } - public CharInput(Reader r, String s) { this.r = new RollbackReader(new BufferedReader(r)); } - public CharInput(InputStream i) { this(i, null); } - public CharInput(InputStream i, String s) { this(new InputStreamReader(i), s); } + public CharInput(Reader r, String s) { + this.name = s; + this.r = new RollbackReader(new BufferedReader(r)); + } + public CharInput(String s) { this(new StringReader(s)); } + public CharInput(Reader r) { this(r, null); } + public CharInput(InputStream i) { this(i, null); } + public CharInput(InputStream i, String s) { this(new InputStreamReader(i), s); } + public CharInput(File f) throws IOException { this(new FileInputStream(f), f.getName()); } public CharInput(InputStream i, String s, boolean indent) { this(new InputStreamReader(i), s); this.indent = indent; } + public String getName() { return name; } + private String name; boolean cr = false; boolean indent = false; private int count = 0; @@ -89,11 +95,6 @@ public class CharInput extends Cartesian.Input { Character ret = __next(); if (ret==null) return null; char c = ret.charValue(); - if (indent) { - if (ret==CharAtom.left) System.out.print("\033[31m{\033[0m"); - else if (ret==CharAtom.right) System.out.print("\033[31m}\033[0m"); - else System.out.print(c+""); - } return ret; } public Character __next() throws IOException { @@ -102,10 +103,8 @@ public class CharInput extends Cartesian.Input { int i = r.read(); if (i==-1) { - /*System.err.print("\r...done \r"); */ if (indent && indentation >= 0) { redent(indentation - lastIndentation); - //System.err.println("\r \rindent: " + (indentation - lastIndentation)); lastIndentation = indentation; indentation = -1; return __next(); @@ -153,20 +152,20 @@ public class CharInput extends Cartesian.Input { if (i>0) { r.unread(CharAtom.left); redent(i-1); return; } } - public String showRegion(Region rc) { + public String showRegion(Region rc, int maxLength) { if (cache == null) return null; Cartesian.Region r = (Cartesian.Region)rc; - int start = r.getStart().getScalar()+1; - int end = r.getEnd().getScalar()+1; + int start = r.getStart().getScalar(); + int end = r.getEnd().getScalar(); if (start < 0) start = 0; 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); - return StringUtil.escapify(ret, "\n\r"); + cachesubstring(end-(maxLength/2-5), end); + return StringUtil.escapify(ret, "\n\r\t"); } private String cachesubstring(int start, int end) { @@ -177,4 +176,5 @@ public class CharInput extends Cartesian.Input { return cache.substring(start, end); } + public void close() { } }