use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class Util method stringValue.
/**
* Get the string value of an Erlang string, empty if empty list
*
* @param o
* Erlang string or list
* @return string value
*/
public static String stringValue(final OtpErlangObject o) {
if (o instanceof OtpErlangString) {
final OtpErlangString s = (OtpErlangString) o;
return s.stringValue();
} else if (o instanceof OtpErlangList) {
final OtpErlangList l = (OtpErlangList) o;
if (l.arity() == 0) {
return "";
}
try {
return l.stringValue();
} catch (final OtpErlangException e) {
ErlLogger.error(e);
return null;
}
} else if (o instanceof OtpErlangBinary) {
final OtpErlangBinary b = (OtpErlangBinary) o;
String result;
result = Util.decode(b.binaryValue(), Charsets.UTF_8);
if (result == null) {
result = Util.decode(b.binaryValue(), Charsets.ISO_8859_1);
}
if (result == null) {
ErlLogger.error("bad binary value in stringValue" + " (can't decode): " + o);
}
return result;
}
// ErlLogger.warn("bad value in stringValue: " + o);
return null;
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class Util method ioListToStringBuilder.
private static StringBuilder ioListToStringBuilder(final OtpErlangObject o, final StringBuilder sb0, final int maxLength) {
StringBuilder sb = sb0;
if (sb.length() >= maxLength) {
return sb;
}
if (o instanceof OtpErlangLong) {
final OtpErlangLong l = (OtpErlangLong) o;
try {
sb.append(l.charValue());
} catch (final OtpErlangRangeException e) {
}
} else if (o instanceof OtpErlangString) {
final OtpErlangString s = (OtpErlangString) o;
sb.append(s.stringValue());
} else if (o instanceof OtpErlangList) {
final OtpErlangList l = (OtpErlangList) o;
for (final OtpErlangObject i : l) {
if (sb.length() < maxLength) {
Util.ioListToStringBuilder(i, sb, maxLength);
}
}
if (sb.length() < maxLength) {
Util.ioListToStringBuilder(l.getLastTail(), sb, maxLength);
}
} else if (o instanceof OtpErlangBinary) {
final OtpErlangBinary b = (OtpErlangBinary) o;
String s = Util.decode(b.binaryValue(), Charsets.UTF_8);
if (s == null) {
s = new String(b.binaryValue(), Charsets.ISO_8859_1);
}
sb.append(s);
} else if (o != null) {
sb.append(o.toString());
}
if (sb.length() > maxLength) {
sb = new StringBuilder(sb.substring(0, maxLength));
sb.append("... <truncated>");
}
return sb;
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class IndexedErlangValue method getElementAt.
protected OtpErlangObject getElementAt(final int index) {
if (value instanceof OtpErlangTuple) {
final OtpErlangTuple t = (OtpErlangTuple) value;
final int ofs = record != null ? 1 : 0;
return t.elementAt(index + ofs);
} else if (value instanceof OtpErlangList) {
final OtpErlangList l = (OtpErlangList) value;
return l.elementAt(index);
} else if (value instanceof OtpErlangBinary) {
final OtpErlangBinary bs = (OtpErlangBinary) value;
int j = bs.binaryValue()[index];
if (j < 0) {
j += 256;
}
return new OtpErlangLong(j);
} else if (list != null) {
return list.elementAt(index);
}
return null;
}
Aggregations