Given an ordered list of same-case letter strings (a-z XOR A-Z) where each string is preceded by 0 or more space ( ) characters, output the same list but with the strings sorted at each level of indentation. Indentation depths under different parents count as distinct lists for sorting purposes.
If your input is:
bdellium fox hound alien aisle wasabi elf alien horseradish xeno irk wren tsunami djinn zebra
your output should be
aisle horseradish xeno wasabi alien elf bdellium alien fox hound djinn zebra irk tsunami wren
If you like, think of it like a directory listing, and you need to sort the names within each directory.
- An item may be indented by any number of spaces. If it is indented by the same number of spaces as the previous item it belongs in the same sort hierarchy as the previous item. If it is indented by more spaces it is the start of a new sub-hierarchy.
- If a line is indented by fewer spaces than the line above it, it links up to the closest sub group above it with the same # or fewer spaces before it (like horseradish in the above example, which links onto the wasabi group above it because wasabi is the first item above it to not have more spaces than horseradish)
- You must preserve the indenting level of each input item in your output
- Tabs in the output are disallowed
- The first line of the input will never be indented
- Your program must handle at least one of all-uppercase and all-lowercase strings; it doesn't have to handle both.
This is a code-golf, so the answer which uses the fewest bytes wins.