Skip to content

Commit

Permalink
fix(#2702): no cactoos, no apache
Browse files Browse the repository at this point in the history
  • Loading branch information
maxonfjvipon committed Dec 15, 2023
1 parent b03aeca commit 5888b05
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 33 deletions.
13 changes: 1 addition & 12 deletions eo-runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ SOFTWARE.
<groupId>org.cactoos</groupId>
<artifactId>cactoos</artifactId>
<!-- version from parent POM -->
<scope>provided</scope>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.llorllale</groupId>
Expand All @@ -104,17 +104,6 @@ SOFTWARE.
<!-- version from parent POM -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<!-- version from parent POM -->
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
31 changes: 12 additions & 19 deletions eo-runtime/src/main/java/EOorg/EOeolang/EOrust.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,22 @@
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;
import org.eolang.Data;
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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -189,13 +185,9 @@ public EOrust(final Phi sigma) {
private static ConcurrentHashMap<String, String> 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();
Expand Down Expand Up @@ -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();
Expand Down
80 changes: 78 additions & 2 deletions eo-runtime/src/main/java/org/eolang/Data.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
}
}

/**
Expand Down

0 comments on commit 5888b05

Please sign in to comment.