private/parsing/Split-ConfluenceLayout.ps1

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
# map structure pseudocode:
# $map = $(sections) # sections are either a bool ($true = UserSection) or an array of bools
#
# Example:
# $map = $($true,$($true,$false),$($false,$true,$false))
# ----------------------------------------------------
# | SINGLE COLUMN USER SECTION |
# ----------------------------------------------------
# ----------------------------------------------------
# | USER CELL | GENERATED CELL |
# ----------------------------------------------------
# ----------------------------------------------------
# | GEN. CELL | USER CELL | GEN. CELL |
# ----------------------------------------------------

function Split-ConfluenceLayout($StorageFormat,$StartToken,$EndToken)
{
    #start a list
    $sections = @()
    
    # find the starting indexes of the $StartToken in the entire body and loop through them
    $startMatches = [regex]::Matches($StorageFormat, $StartToken)
    foreach ($match in $startMatches) {
        # start by taking the part of the string that occurs after the start of the StartToken
        $section = $StorageFormat.Substring($match.Index)

        # now chop off everything after the end of the first EndToken in the remaining string
        $section = $section.Substring(0, ([regex]::Matches($section, $EndToken))[0].Index + $EndToken.Length)

        # add the trimmed section to the list
        $sections += $section
    }

    #return the list
    $sections
}