summaryrefslogtreecommitdiff
path: root/support/arara/source/src/main/kotlin/org/islandoftex/arara/ruleset/DirectiveAssembler.kt
blob: a431df6ae295082ac859875996a1eb730936c219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// SPDX-License-Identifier: BSD-3-Clause
package org.islandoftex.arara.ruleset

/**
 * Implements a directive assembler in order to help build a directive from a
 * list of strings.
 *
 * @author Island of TeX
 * @version 5.0
 * @since 4.0
 */
class DirectiveAssembler {
    // this variable holds a list of
    // line numbers indicating which
    // lines composed the resulting
    // potential directive
    private val lineNumbers = mutableListOf<Int>()

    // this variable holds the textual
    // representation of the directive
    private var text: String = ""

    /**
     * Checks if an append operation is allowed.
     * @return A boolean value indicating if an append operation is allowed.
     */
    val isAppendAllowed: Boolean
        get() = lineNumbers.isNotEmpty()

    /**
     * Adds a line number to the assembler.
     * @param line An integer representing the line number.
     */
    fun addLineNumber(line: Int) = lineNumbers.add(line)

    /**
     * Appends the provided line to the assembler text.
     * @param line The provided line.
     */
    fun appendLine(line: String) {
        text = text + " " + line.trim()
    }

    /**
     * Gets the list of line numbers.
     * @return The list of line numbers.
     */
    fun getLineNumbers(): List<Int> = lineNumbers

    /**
     * Gets the text.
     * @return The assembler text, properly trimmed.
     */
    fun getText(): String = text.trim()
}