Skip to content

Commit

Permalink
Finish implementing ConsoleWindow features
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Oct 27, 2018
1 parent 22b0966 commit 4986c54
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 103 deletions.
2 changes: 1 addition & 1 deletion GalaxiAPI/src/net/ME1312/Galaxi/Library/Log/LogStream.java
Expand Up @@ -65,7 +65,7 @@ public LogLevel getLevel() {
private void write(String str) {
Logger.messages.add(new NamedContainer<LogStream, String>(this, str));
}

@SuppressWarnings("unchecked")
private String convert(TextElement original) {
StringBuilder message = new StringBuilder();
Expand Down
16 changes: 9 additions & 7 deletions GalaxiAPI/src/net/ME1312/Galaxi/Library/Log/Logger.java
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.PrimitiveIterator;

import static net.ME1312.Galaxi.Library.Log.LogLevel.*;

Expand Down Expand Up @@ -111,12 +112,13 @@ private static void log() {
LinkedList<String> messages = new LinkedList<String>();
boolean terminate = false;
if (container.get().length() > 0) {
String message = "";
StringBuilder message = new StringBuilder();
boolean terminate_with_prefix = false;
for (char c : container.get().toCharArray()) {
for (PrimitiveIterator.OfInt $i = container.get().codePoints().iterator(); $i.hasNext();) {
int c = $i.nextInt();
if (terminate) {
messages.add(message);
message = "";
messages.add(message.toString());
message = new StringBuilder();
}

switch (c) {
Expand All @@ -127,13 +129,13 @@ private static void log() {
terminate_with_prefix = true;
break;
default:
message += c;
message.appendCodePoint(c);
terminate = false;
terminate_with_prefix = false;
break;
}
}
if (message.length() > 0) messages.add(message);
if (message.length() > 0) messages.add(message.toString());
if (terminate && (terminate_with_prefix || messages.size() <= 0)) messages.add("");
}

Expand Down Expand Up @@ -178,7 +180,7 @@ private static void log() {
Logger.messages.remove(0);
if (pse.get() != null) e.printStackTrace(pse.get());
}
Util.isException(() -> Thread.sleep(50));
Util.isException(() -> Thread.sleep(32));
}
})).start();
}
Expand Down
65 changes: 44 additions & 21 deletions GalaxiAPI/src/net/ME1312/Galaxi/Library/Util.java
Expand Up @@ -320,29 +320,29 @@ public static void unzip(InputStream zip, File dir) {
* @return Unescaped String
*/
public static String unescapeJavaString(String str) {

StringBuilder sb = new StringBuilder(str.length());

for (int i = 0; i < str.length(); i++) {
char ch = str.charAt(i);
int ch = str.codePointAt(i);
if (ch == '\\') {
char nextChar = (i == str.length() - 1) ? '\\' : str
.charAt(i + 1);
int nextChar = (i == str.length() - 1) ? '\\' : str
.codePointAt(i + 1);
// Octal escape?
if (nextChar >= '0' && nextChar <= '7') {
String code = "" + nextChar;
StringBuilder code = new StringBuilder();
code.appendCodePoint(nextChar);
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
&& str.codePointAt(i + 1) <= '7') {
code.appendCodePoint(str.codePointAt(i + 1));
i++;
if ((i < str.length() - 1) && str.charAt(i + 1) >= '0'
&& str.charAt(i + 1) <= '7') {
code += str.charAt(i + 1);
if ((i < str.length() - 1) && str.codePointAt(i + 1) >= '0'
&& str.codePointAt(i + 1) <= '7') {
code.appendCodePoint(str.codePointAt(i + 1));
i++;
}
}
sb.append((char) Integer.parseInt(code, 8));
sb.append((char) Integer.parseInt(code.toString(), 8));
continue;
}
switch (nextChar) {
Expand Down Expand Up @@ -370,22 +370,45 @@ public static String unescapeJavaString(String str) {
case '\'':
ch = '\'';
break;
// Hex Unicode: u????
// Hex Unicode Char: u????
// Hex Unicode Codepoint: u{??????}
case 'u':
if (i >= str.length() - 5) {
try {
if (i >= str.length() - 4) throw new IllegalStateException();
StringBuilder escape = new StringBuilder();
int offset = 2;

if (str.codePointAt(i + 2) != '{') {
if (i >= str.length() - 5) throw new IllegalStateException();
while (offset <= 5) {
Integer.toString(str.codePointAt(i + offset), 16);
escape.appendCodePoint(str.codePointAt(i + offset));
offset++;
}
offset--;
} else {
offset++;
while (str.codePointAt(i + offset) != '}') {
Integer.toString(str.codePointAt(i + offset), 16);
escape.appendCodePoint(str.codePointAt(i + offset));
offset++;
}
}
sb.append(new String(new int[]{
Integer.parseInt(escape.toString(), 16)
}, 0, 1));

i += offset;
continue;
} catch (Throwable e){
sb.append('\\');
ch = 'u';
break;
}
int code = Integer.parseInt(
"" + str.charAt(i + 2) + str.charAt(i + 3)
+ str.charAt(i + 4) + str.charAt(i + 5), 16);
sb.append(Character.toChars(code));
i += 5;
continue;
}
i++;
}
sb.append(ch);
sb.appendCodePoint(ch);
}
return sb.toString();
}
Expand Down

0 comments on commit 4986c54

Please sign in to comment.