class LocaleHeaderDelegate implements RuntimeDelegate.HeaderDelegate<Locale> {

    @Override
    public Locale fromString(String header) {
        if (header == null) {
            throw new IllegalArgumentException();
        }

        header = removeWhitespaces(header);
        int p = scan(header, ',');
        if (charAtIs(header, p, ',')) {
            header = header.substring(0, p);
        }

        p = scan(header, '-');
        if (charAtIs(header, p, '-')) {
            return new Locale(header.substring(0, p), header.substring(p + 1));
        }
        return new Locale(header);
    }

}