Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't truncate string values when converting dicts to strings #128

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/aya/ReprStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void delTrailingSpaces() {
private Stack<Obj> _visited;
// In safe mode, do not try to call __repr__ on objects
private boolean _safe_mode;
private boolean _full_strings; // If long strings will be printed completely or with "abc ... xyz"

public ReprStream() {
_lines = new ArrayList<ReprStream.Line>();
Expand All @@ -35,6 +36,7 @@ public ReprStream() {
_visited = new Stack<Obj>();
_current_line = new Line(_current_indent);
_safe_mode = false;
_full_strings = false;
}


Expand Down Expand Up @@ -195,4 +197,13 @@ public void setSafeMode(boolean safe_mode) {
public boolean isSafeMode() {
return _safe_mode;
}


public void setFullStrings(boolean b) {
_full_strings = true;
}

public boolean isFullStrings() {
return _full_strings;
}
}
5 changes: 4 additions & 1 deletion src/aya/obj/dict/Dict.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,10 @@ public boolean hasMetaTable() {

/** Return a string representation of the dict */
private String dictStr() {
return dictRepr(new ReprStream()).toStringOneline();
final boolean fullStr = true;
ReprStream stream = new ReprStream();
stream.setFullStrings(true);
return dictRepr(stream).toString();//.toStringOneline();
}

/** Return a string representation of the dict
Expand Down
6 changes: 3 additions & 3 deletions src/aya/obj/list/Str.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ public boolean bool() {

@Override
public ReprStream repr(ReprStream stream) {
if (_str.length() > 100) {
stream.print(StringUtils.quote(_str.substring(0, 30) + " ... " + _str.substring(_str.length()-30)));
} else {
if (stream.isFullStrings() || _str.length() <= 100) {
stream.print(StringUtils.quote(_str));
} else {
stream.print(StringUtils.quote(_str.substring(0, 30) + " ... " + _str.substring(_str.length()-30)));
}
return stream;
}
Expand Down
Loading