use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class ErlideScanner method lightScanString.
@Override
public List<ErlToken> lightScanString(final String string, final int offset) throws ScannerException {
OtpErlangObject r1 = null;
try {
r1 = backend.call("erlide_scanner", "light_scan_string", "ba", string, ErlideScanner.ENCODING);
} catch (final Exception e) {
throw new ScannerException("Could not parse string \"" + string + "\": " + e.getMessage());
}
if (r1 == null) {
return null;
}
if (!(r1 instanceof OtpErlangTuple)) {
throw new ScannerException("Could not parse string \"" + string + "\": weird return value " + r1);
}
final OtpErlangTuple t1 = (OtpErlangTuple) r1;
List<ErlToken> toks = null;
if (Util.isOk(t1)) {
if (t1.elementAt(1) instanceof OtpErlangBinary) {
final OtpErlangBinary b = (OtpErlangBinary) t1.elementAt(1);
final byte[] bytes = b.binaryValue();
toks = new ArrayList<>(bytes.length / 10);
for (int i = 0; i < bytes.length; i += 10) {
final ErlToken tk = new ErlToken(bytes, i, offset);
toks.add(tk);
}
return toks;
}
throw new ScannerException("unexpected token format");
}
throw new ScannerException("Could not parse string \"" + string + "\": " + t1.toString());
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class UtilTest method stringValue_4.
@Test
public void stringValue_4() {
final OtpErlangObject input = new OtpErlangBinary(new byte[] { 51, 52, 53 });
final String expected = "345";
final String actual = Util.stringValue(input);
Assert.assertEquals(expected, actual);
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class ErlangLogEventHandler method handleEvent.
@Subscribe
public void handleEvent(final ErlEvent event) {
if (!event.getTopic().equals(getTopic())) {
return;
}
final OtpErlangTuple t = (OtpErlangTuple) event.getEvent();
final OtpErlangAtom module = (OtpErlangAtom) t.elementAt(0);
final OtpErlangLong line = (OtpErlangLong) t.elementAt(1);
final OtpErlangAtom level = (OtpErlangAtom) t.elementAt(2);
final OtpErlangObject logEvent = t.elementAt(3);
String ss = "";
if (t.arity() == 5) {
final OtpErlangTuple backtrace_0 = (OtpErlangTuple) t.elementAt(4);
final OtpErlangBinary backtrace = (OtpErlangBinary) backtrace_0.elementAt(1);
ss = new String(backtrace.binaryValue());
}
try {
ErlLogger.getInstance().erlangLog(module.atomValue() + ".erl", line.uIntValue(), level.atomValue().toUpperCase(), "%s %s", logEvent.toString(), ss);
} catch (final Exception e) {
ErlLogger.warn(e);
}
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class UtilTest method stringValue_6.
@Test
public void stringValue_6() {
final byte[] bytes = { (byte) 0xE8, (byte) 0x8F, (byte) 0xAF };
final OtpErlangObject input = new OtpErlangBinary(bytes);
final byte[] expected = bytes;
final String actual = Util.stringValue(input);
assertThat(actual.getBytes(Charsets.UTF_8)).isEqualTo(expected);
}
use of com.ericsson.otp.erlang.OtpErlangBinary in project erlide_eclipse by erlang.
the class UtilTest method stringValue_5.
@Test
public void stringValue_5() {
final byte[] bytes = { 197 - 256, 246 - 256 };
final OtpErlangObject input = new OtpErlangBinary(bytes);
final byte[] expected = bytes;
final String actual = Util.stringValue(input);
assertThat(actual.getBytes(Charsets.ISO_8859_1)).isEqualTo(expected);
}
Aggregations