Search in sources :

Example 1 with CodePosition

use of uk.me.parabola.imgfmt.app.srt.CodePosition in project mkgmap by openstreetmap.

the class SrtTextReader method expandState.

/**
 * Within an 'expand' command. The whole command is read before return, they can not span
 * lines.
 *
 * @param tok The first token after the keyword.
 */
private void expandState(TokenScanner scanner, Token tok) {
    String val = tok.getValue();
    Code code = new Code(scanner, val).read();
    String s = scanner.nextValue();
    if (!s.equals("to"))
        throw new SyntaxException(scanner, "Expected the word 'to' in expand command");
    int secondary = 0;
    int tertiary = 0;
    int num = 0;
    while (!scanner.isEndOfFile()) {
        Token t = scanner.nextRawToken();
        if (t.isEol())
            break;
        if (t.isWhiteSpace())
            continue;
        Code r = new Code(scanner, t.getValue()).read();
        CodePosition cp = new CodePosition();
        int b = r.getBval();
        int primary = sort.getPrimary(b);
        cp.setPrimary((char) primary);
        // character so adjust the ordering at other strengths.  May need further tweaks.
        if (EXPERIMENTAL) {
            secondary = sort.getSecondary(b);
            tertiary = sort.getTertiary(b);
            if (num++ == 0) {
                Integer max = maxSec.get(primary);
                secondary += max == null ? 0 : max;
                if (charFlags(code) == 1) {
                    max = maxTert.get(primary);
                    tertiary += max == null ? 0 : max;
                }
            } else {
                secondary = 1;
            }
            cp.setSecondary((byte) (secondary));
            cp.setTertiary((byte) (tertiary));
        } else {
            num++;
            secondary = sort.getSecondary(b) & 0xff;
            cp.setSecondary((byte) (secondary + 7));
            tertiary = sort.getTertiary(b) & 0xff;
            cp.setTertiary((byte) (tertiary + 2));
        }
        expansions.add(cp);
    }
    int flags = charFlags(code) | (num - 1) << 4;
    sort.add(code.getBval(), expansions.size() - num + 1, 0, 0, flags);
    state = IN_INITIAL;
}
Also used : CodePosition(uk.me.parabola.imgfmt.app.srt.CodePosition) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) Token(uk.me.parabola.mkgmap.scan.Token)

Aggregations

CodePosition (uk.me.parabola.imgfmt.app.srt.CodePosition)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1 Token (uk.me.parabola.mkgmap.scan.Token)1