Skip to content

Commit 1edb277

Browse files
authored
Merge pull request #128 from aya-lang/dict-repr
Don't truncate string values when converting dicts to strings
2 parents 8fa9b94 + 6a7d534 commit 1edb277

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/aya/ReprStream.java

+11
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void delTrailingSpaces() {
2727
private Stack<Obj> _visited;
2828
// In safe mode, do not try to call __repr__ on objects
2929
private boolean _safe_mode;
30+
private boolean _full_strings; // If long strings will be printed completely or with "abc ... xyz"
3031

3132
public ReprStream() {
3233
_lines = new ArrayList<ReprStream.Line>();
@@ -35,6 +36,7 @@ public ReprStream() {
3536
_visited = new Stack<Obj>();
3637
_current_line = new Line(_current_indent);
3738
_safe_mode = false;
39+
_full_strings = false;
3840
}
3941

4042

@@ -195,4 +197,13 @@ public void setSafeMode(boolean safe_mode) {
195197
public boolean isSafeMode() {
196198
return _safe_mode;
197199
}
200+
201+
202+
public void setFullStrings(boolean b) {
203+
_full_strings = true;
204+
}
205+
206+
public boolean isFullStrings() {
207+
return _full_strings;
208+
}
198209
}

src/aya/obj/dict/Dict.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ public boolean hasMetaTable() {
313313

314314
/** Return a string representation of the dict */
315315
private String dictStr() {
316-
return dictRepr(new ReprStream()).toStringOneline();
316+
final boolean fullStr = true;
317+
ReprStream stream = new ReprStream();
318+
stream.setFullStrings(true);
319+
return dictRepr(stream).toString();//.toStringOneline();
317320
}
318321

319322
/** Return a string representation of the dict

src/aya/obj/list/Str.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -429,10 +429,10 @@ public boolean bool() {
429429

430430
@Override
431431
public ReprStream repr(ReprStream stream) {
432-
if (_str.length() > 100) {
433-
stream.print(StringUtils.quote(_str.substring(0, 30) + " ... " + _str.substring(_str.length()-30)));
434-
} else {
432+
if (stream.isFullStrings() || _str.length() <= 100) {
435433
stream.print(StringUtils.quote(_str));
434+
} else {
435+
stream.print(StringUtils.quote(_str.substring(0, 30) + " ... " + _str.substring(_str.length()-30)));
436436
}
437437
return stream;
438438
}

0 commit comments

Comments
 (0)