B
@Xyro said:@PJH said:Perhaps it's a double-null-terminated string? I somehow doubt it though...WTF.(re-reads post) WTF WTF. Never in my wildest nightmares would I dream up something so demented. You know what language could really use something like this? Java.
public class DoubleNullString {
private String _str;
public DoubleNullString() {
_str = "";
}
public DoubleNullString(String [] strs)
{
_str = "";
for (int i = 0; i < strs.length; ++i) {
_str = _str + strs[i] + ((char)0);
}
}
public int size() {
int count = 0;
int idx = _str.indexOf(0);
while (idx > 0) {
++count;
idx = _str.indexOf(0, idx + 1);
}
return count;
}
public String get(int idx) {
if (idx < 0)
throw new IndexOutOfBoundsException(Integer.toString(idx) + " < 0");
int start = 0;
int end = _str.indexOf(0);
String val;
for (int i = 0; i < idx; ++i) {
start = end + 1;
end = _str.indexOf(0, end + 1);
if (end < 0)
throw new IndexOutOfBoundsException(Integer.toString(idx) + " > size");
}
return _str.substring(start, end);
}
public void put(int idx, String str) {
if (idx < 0)
throw new IndexOutOfBoundsException(Integer.toString(idx) + " < 0");
int size = size();
if (idx > size) {
for (int i = 0; i < (idx - size); ++i)
_str = _str + ((char)0);
_str = _str + str + ((char)0);
}
else {
int start = 0;
int end = _str.indexOf(0);
String val;
for (int i = 0; i < idx; ++i) {
start = end + 1;
end = _str.indexOf(0, end + 1);
}
_str = _str.substring(0, start) + str + _str.substring(end);
}
return;
}
public void append(String str) {
_str = _str + str + ((char)0);
return;
}
public java.util.List<String> toList() {
return java.util.Arrays.asList(_str.split(Character.toString((char)0), -1));
}
}