Files
mdg-filius/packages/fls/src/javaString.ts
T
julian.kiedaischandClaude Opus 5.5 8f9930f1ff fix(fls): follow Java's formats, not Java's errors
Java stays the reference for the .fls format, but its errors are no longer
copied. The Java oracle still measures Java as it is; each deliberate
departure is named in the tests with its reason (JAVA_BUGS) and must really
depart. The corpus - what Java itself writes - still reads exactly as in
Java.

- /dns/hosts: a label may start with a digit, holds no backslash, and the
  last one is not all digits (RFC 1123, RFC 3696); A, MX and NS are read in
  any case (RFC 4343); a negative TTL is invalid, so 3600 (RFC 2181). Also
  for the e-mail server's domain.
- /mailserver/konten.txt: empty fields count (Java's StringTokenizer skips
  them and shifts the rest, so an empty password breaks the account); a
  short line alone is left out, with a warning (Java throws for the whole
  file); a message keeps an empty text or subject (Java's split loses it);
  a ";" in an unescaped subject stays in the message; CRLF lines.
- /konten.txt: the last complete line is the account, also with an empty
  address (Java takes the last line and loses the account); CRLF lines.
- Static DHCP assignments: a broken entry alone is left out (Java loses
  every entry after it).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 07:20:52 +00:00

20 lines
763 B
TypeScript

// java.lang.String as FILIUS's text formats use it - each differs from its
// JavaScript namesake.
/** `String.trim()`: every UTF-16 unit up to U+0020 off both ends. */
export function javaTrim(text: string): string {
return text.replace(/^[\u0000-\u0020]+|[\u0000-\u0020]+$/g, '');
}
/**
* `text.split(separator)` for a one-character separator: trailing empty
* parts are dropped — "a;b;;".split(";") is two parts, ";;" none — but a
* text without the separator is one part, even the empty text.
*/
export function javaSplit(text: string, separator: string): string[] {
if (!text.includes(separator)) return [text];
const parts = text.split(separator);
while (parts.length > 0 && parts[parts.length - 1] === '') parts.pop();
return parts;
}