Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8ccac519 authored by Cole Faust's avatar Cole Faust Committed by Gerrit Code Review
Browse files

Merge "Add function for flattening 2d lists"

parents 4890a4ea 6f6060a3
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -619,6 +619,12 @@ def _last_word(input):
        return ""
        return ""
    return input[l-1]
    return input[l-1]


def _flatten_2d_list(list):
    result = []
    for x in list:
        result += x
    return result

def _dir(paths):
def _dir(paths):
    """Equivalent to the GNU make function $(dir).
    """Equivalent to the GNU make function $(dir).


@@ -785,7 +791,7 @@ def _mkstrip(s):
    if t == "list":
    if t == "list":
        s = " ".join(s)
        s = " ".join(s)
    elif t != "string":
    elif t != "string":
        fail("Argument to mkstrip must be a string or list.")
        fail("Argument to mkstrip must be a string or list, got: "+t)
    result = ""
    result = ""
    was_space = False
    was_space = False
    for ch in s.strip().elems():
    for ch in s.strip().elems():
@@ -879,6 +885,7 @@ rblf = struct(
    findstring = _findstring,
    findstring = _findstring,
    first_word = _first_word,
    first_word = _first_word,
    last_word = _last_word,
    last_word = _last_word,
    flatten_2d_list = _flatten_2d_list,
    inherit = _inherit,
    inherit = _inherit,
    indirect = _indirect,
    indirect = _indirect,
    mk2rbc_error = _mk2rbc_error,
    mk2rbc_error = _mk2rbc_error,
+5 −1
Original line number Original line Diff line number Diff line
@@ -43,7 +43,7 @@ assert_eq(["a", "b", "c"], rblf.mksort(["b", "a", "c", "c"]))


assert_eq("", rblf.mkstrip(" \n \t    "))
assert_eq("", rblf.mkstrip(" \n \t    "))
assert_eq("a b c", rblf.mkstrip("  a b   \n  c \t"))
assert_eq("a b c", rblf.mkstrip("  a b   \n  c \t"))
assert_eq(1, rblf.mkstrip(1))
assert_eq("1", rblf.mkstrip("1 "))


assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
assert_eq("b1 b2", rblf.mksubst("a", "b", "a1 a2"))
assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
assert_eq(["b1", "x2"], rblf.mksubst("a", "b", ["a1", "x2"]))
@@ -90,6 +90,10 @@ assert_eq("bar", rblf.last_word(["foo", "bar"]))
assert_eq("", rblf.last_word(""))
assert_eq("", rblf.last_word(""))
assert_eq("", rblf.last_word([]))
assert_eq("", rblf.last_word([]))


assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo", "bar"]]))
assert_eq(["foo", "bar"], rblf.flatten_2d_list([["foo"], ["bar"]]))
assert_eq([], rblf.flatten_2d_list([]))

assert_eq(
assert_eq(
    ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
    ["build/make/tests/board.rbc", "build/make/tests/board_input_vars.rbc"],
    rblf.expand_wildcard("build/make/tests/board*.rbc")
    rblf.expand_wildcard("build/make/tests/board*.rbc")