import java.util.*;
import java.util.zip.*;
import java.util.List;
import java.util.regex.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import javax.swing.table.*;
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.lang.ref.*;
import java.lang.management.*;
import java.security.*;
import java.security.spec.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.*;
import java.math.*;
public class main {
public static void main(String[] args) throws Exception {
//S s = "hello";
String s = fromUtf8(bytesFromHex("f0908cbcf0908cb0f0908cb2")) + "."; // 3 runes and a dot
print(s);
for (int i = 0; i < l(s); i++) {
boolean x = isExtendedUnicodeCharacter(s, i);
print(codePointToString(s.codePointAt(i)) + ": " + (x ? "extended unicode char" : "normal unicode char"));
if (x) ++i;
}
String escaped = escapeMultichars(s);
print("Escaped: " + escaped);
assertEquals("[xchar 0001033c][xchar 00010330][xchar 00010332].", escaped);
String unescaped = unescapeMultichars(escaped);
assertEquals(s, unescaped);
print("ok!");
}
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static volatile StringBuffer print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
//static int print_maxLineLength = 0; // 0 = unset
static boolean print_silent; // total mute if set
static void print() {
print("");
}
// slightly overblown signature to return original object...
static A print(A o) {
if (print_silent) return o;
String s = String.valueOf(o) + "\n";
// TODO if (print_maxLineLength != 0)
StringBuffer loc = local_log;
StringBuffer buf = print_log;
int loc_max = print_log_max;
if (buf != loc && buf != null) {
print_append(buf, s, print_log_max);
loc_max = local_log_max;
}
if (loc != null)
print_append(loc, s, loc_max);
System.out.print(s);
return o;
}
static void print(long l) {
print(String.valueOf(l));
}
static void print(char c) {
print(String.valueOf(c));
}
static void print_append(StringBuffer buf, String s, int max) {
synchronized(buf) {
buf.append(s);
max /= 2;
if (buf.length() > max) try {
int newLength = max/2;
int ofs = buf.length()-newLength;
String newString = buf.substring(ofs);
buf.setLength(0);
buf.append("[...] ").append(newString);
} catch (Exception e) {
buf.setLength(0);
}
}
}
static String codePointToString(int codePoint) {
return new String(Character.toChars(codePoint));
}
static byte[] bytesFromHex(String s) {
return hexToBytes(s);
}
static A assertEquals(Object x, A y) {
return assertEquals(null, x, y);
}
static A assertEquals(String msg, Object x, A y) {
if (!(x == null ? y == null : x.equals(y)))
throw fail((msg != null ? msg + ": " : "") + structure(x) + " != " + structure(y));
return y;
}
static String unescapeMultichars(String s) {
return regexReplace(s, "\\[xchar ([a-f0-9]+)\\]", new Object() { Object get(Matcher m) { return
codePointToString(hexToInt(m.group(1)))
; }
public String toString() { return "codePointToString(hexToInt(m.group(1)))"; }});
}
static String fromUtf8(byte[] bytes) { try {
return new String(bytes, "UTF-8");
} catch (Throwable __e) { throw __e instanceof RuntimeException ? (RuntimeException) __e : new RuntimeException(__e); }}
static boolean isExtendedUnicodeCharacter(String s, int idx) {
return Character.charCount(s.codePointAt(idx)) > 1;
}
static String escapeMultichars(String s) {
StringBuilder buf = new StringBuilder();
for (int i = 0; i < l(s); i++)
if (isExtendedUnicodeCharacter(s, i)) {
buf.append("[xchar " + intToHex(s.codePointAt(i)) + "]");
++i;
} else
buf.append(s.charAt(i));
return str(buf);
}
static byte[] hexToBytes(String s) {
int n = l(s) / 2;
byte[] bytes = new byte[n];
for (int i = 0; i < n; i++) {
String hex = substring(s, i*2, i*2+2);
try {
bytes[i] = (byte) parseHexByte(hex);
} catch (Throwable _e) {
throw fail("Bad hex byte: " + quote(hex) + " at " + i*2 + "/" + l(s));
}
}
return bytes;
}
// f : Matcher -> S
static String regexReplace(String s, String pat, Object f) {
Matcher m = Pattern.compile(pat).matcher(s);
StringBuffer buf = new StringBuffer();
while (m.find())
m.appendReplacement(buf, m.quoteReplacement(str(callF(f, m))));
m.appendTail(buf);
return str(buf);
}
static int l(Object[] a) { return a == null ? 0 : a.length; }
static int l(boolean[] a) { return a == null ? 0 : a.length; }
static int l(byte[] a) { return a == null ? 0 : a.length; }
static int l(int[] a) { return a == null ? 0 : a.length; }
static int l(float[] a) { return a == null ? 0 : a.length; }
static int l(char[] a) { return a == null ? 0 : a.length; }
static int l(Collection c) { return c == null ? 0 : c.size(); }
static int l(Map m) { return m == null ? 0 : m.size(); }
static int l(CharSequence s) { return s == null ? 0 : s.length(); }
static int l(Object o) {
return l((List) o); // incomplete
}
static String structure(Object o) {
HashSet refd = new HashSet();
return structure_2(structure_1(o, new structure_Data(refd)), refd);
}
// leave to false, unless unstructure() breaks
static boolean structure_allowShortening = false;
static int structure_shareStringsLongerThan = 20;
static class structure_Data {
int stringSizeLimit;
IdentityHashMap