diff --git a/eo-runtime/pom.xml b/eo-runtime/pom.xml
index 260cd2f18c..31815dd6a3 100644
--- a/eo-runtime/pom.xml
+++ b/eo-runtime/pom.xml
@@ -78,7 +78,7 @@ SOFTWARE.
org.cactoos
cactoos
- provided
+ test
org.llorllale
@@ -104,17 +104,6 @@ SOFTWARE.
test
-
- org.apache.commons
- commons-lang3
- 3.14.0
- provided
-
-
- org.apache.commons
- commons-text
-
-
diff --git a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
index 86b5487aea..87bd91e5db 100644
--- a/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
+++ b/eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
@@ -34,19 +34,15 @@
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
+import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReference;
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.commons.lang3.SystemUtils;
-import org.cactoos.bytes.Base64Bytes;
-import org.cactoos.bytes.BytesOf;
-import org.cactoos.bytes.IoCheckedBytes;
-import org.cactoos.text.TextOf;
import org.eolang.AtFree;
import org.eolang.AtLambda;
import org.eolang.Attr;
@@ -54,7 +50,6 @@
import org.eolang.ExFailure;
import org.eolang.ExNative;
import org.eolang.PhDefault;
-import org.eolang.PhWith;
import org.eolang.Phi;
import org.eolang.Universe;
import org.eolang.UniverseDefault;
@@ -100,14 +95,15 @@ public class EOrust extends PhDefault {
);
}
final String lib;
- if (SystemUtils.IS_OS_WINDOWS) {
+ final String OS = System.getProperty("os.name").toLowerCase();
+ if (OS.contains("win")) {
lib = "common.dll";
- } else if (SystemUtils.IS_OS_LINUX) {
+ } else if (OS.contains("nix") || OS.contains("nux") || OS.contains("aix")) {
lib = "libcommon.so";
- } else if (SystemUtils.IS_OS_MAC) {
+ } else if (OS.contains("mac")) {
lib = "libcommon.dylib";
} else {
- throw new NotImplementedException(
+ throw new UnsupportedOperationException(
String.format(
"Rust inserts are not supported by %s os. Only windows, linux and macos are allowed.",
System.getProperty("os.name")
@@ -189,13 +185,9 @@ public EOrust(final Phi sigma) {
private static ConcurrentHashMap load(final String src) throws IOException {
try (ObjectInputStream map = new ObjectInputStream(
new ByteArrayInputStream(
- new IoCheckedBytes(
- new Base64Bytes(
- new BytesOf(
- new TextOf(Paths.get(src))
- )
- )
- ).asBytes()
+ Base64.getDecoder().decode(
+ Files.readAllBytes(Paths.get(src))
+ )
)
)) {
final Object result = map.readObject();
@@ -230,9 +222,10 @@ private Phi translate(final byte[] message, final String insert) {
final byte determinant = message[0];
final byte[] content = Arrays.copyOfRange(message, 1, message.length);
final Phi ret;
+ final ByteBuffer buffer;
switch (determinant) {
case 0:
- ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES);
+ buffer = ByteBuffer.allocate(Integer.BYTES);
buffer.put(content);
buffer.flip();
final int vertex = buffer.getInt();
diff --git a/eo-runtime/src/main/java/org/eolang/Data.java b/eo-runtime/src/main/java/org/eolang/Data.java
index eae70a8789..46c0be7420 100644
--- a/eo-runtime/src/main/java/org/eolang/Data.java
+++ b/eo-runtime/src/main/java/org/eolang/Data.java
@@ -32,7 +32,6 @@
import java.nio.charset.StandardCharsets;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
-import org.apache.commons.text.StringEscapeUtils;
/**
* A data container.
@@ -234,7 +233,7 @@ private static Phi toPhi(final Object obj, final Phi value) {
} else if (obj instanceof String) {
phi = new EOstring(Phi.Φ);
delta = false;
- bytes = StringEscapeUtils.unescapeJava(
+ bytes = Data.ToPhi.unescapeJavaString(
(String) obj
).getBytes(StandardCharsets.UTF_8);
} else if (obj instanceof Double) {
@@ -258,6 +257,83 @@ private static Phi toPhi(final Object obj, final Phi value) {
}
return phi;
}
+
+ private static String unescapeJavaString(final String str) {
+ final StringBuilder sb = new StringBuilder(str.length());
+ for (int i = 0; i < str.length(); i++) {
+ char chr = str.charAt(i);
+ if (chr == '\\') {
+ final char nextChar = (i == str.length() - 1) ? '\\' : str.charAt(i + 1);
+ // Octal escape?
+ if (nextChar >= '0' && nextChar <= '7') {
+ String code = String.valueOf(nextChar);
+ i++;
+ if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
+ && str.charAt(i + 1) <= '7') {
+ code += str.charAt(i + 1);
+ i++;
+ if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
+ && str.charAt(i + 1) <= '7') {
+ code += str.charAt(i + 1);
+ i++;
+ }
+ }
+ sb.append((char) Integer.parseInt(code, 8));
+ continue;
+ }
+ switch (nextChar) {
+ case '\\':
+ break;
+ case 'b':
+ chr = '\b';
+ break;
+ case 'f':
+ chr = '\f';
+ break;
+ case 'n':
+ chr = '\n';
+ break;
+ case 'r':
+ chr = '\r';
+ break;
+ case 't':
+ chr = '\t';
+ break;
+ case '\"':
+ chr = '\"';
+ break;
+ case '\'':
+ chr = '\'';
+ break;
+ // Hex Unicode: u????
+ case 'u':
+ if (i >= str.length() - 5) {
+ chr = 'u';
+ break;
+ }
+ sb.append(
+ Character.toChars(
+ Integer.parseInt(
+ String.join(
+ "",
+ String.valueOf(str.charAt(i + 2)),
+ String.valueOf(str.charAt(i + 3)),
+ String.valueOf(str.charAt(i + 4)),
+ String.valueOf(str.charAt(i + 5))
+ ),
+ 16
+ )
+ )
+ );
+ i += 5;
+ continue;
+ }
+ i++;
+ }
+ sb.append(chr);
+ }
+ return sb.toString();
+ }
}
/**