API

BetweenFlags API Documentation

Flag(word::String,
     word_boundaries_left::Vector{String},
     word_boundaries_right::Vector{String})

A flag that BetweenFlags looks for to denote the start/stop position of a given "level" or scope. The word boundaries need only be unique since every permutation of left and right word boundaries are taken to determine levels.

julia>
using BetweenFlags
# find: ["\nfunction", " function", ";function"]
start_flag = BetweenFlags.Flag("function",
                               ["\n", "\s", ";"],
                               ["\n", "\s"])
# find: ["\nend", " end", ";end"]
stop_flag = BetweenFlags.Flag("end",
                              ["\n", "\s", ";"],
                              ["\n", "\s", ";"])
source
FlagSet(start::Flag, stop::Flag)

A flag set that defines the start and stop of the substring of interest.

julia>
using BetweenFlags
# find: ["\nfunction", " function", ";function"]
start_flag = BetweenFlags.Flag("function",
                               ["\n", "\s", ";"],
                               ["\n", "\s"])
# find: ["\nend", " end", ";end"]
stop_flag = BetweenFlags.Flag("end",
                              ["\n", "\s", ";"],
                              ["\n", "\s", ";"])
flag_set = FlagSet(start_flag, stop_flag)
source
get_flat(s::String,
                  flags_start::Vector{String},
                  flags_stop::Vector{String},
                  inclusive::Bool = true)

Gets the substring based on the start and stop flag vectors, and a Bool which determines whether the flags themselves should be returned or not.

This function will grab the inner-most string, assuming that you do not have multiple start flags before reaching a corresponding stop flag.

julia> s = "Some text... {GRAB THIS}, some more text {GRAB THIS TOO}..."
"Some text... {GRAB THIS}, some more text {GRAB THIS TOO}..."

julia> L = BetweenFlags.get_flat(s, ["{"], ["}"])
2-element Array{String,1}:
 "{GRAB THIS}"
 "{GRAB THIS TOO}"
source
get_level_flat(s::String,
               flags_start::Vector{String},
               flags_stop::Vector{String},
               inclusive::Bool = true)

getlevelflat gets the substring based on the flags_start and flags_stop vectors, and a Bool which determines whether the flags themselves should be returned or not.

This function will grab the outer-most string by ignoring stop flags when multiple start flags occur before stop flags.

julia> using BetweenFlags

julia> s = "Some text... {GRAB {THIS}}, some more text {GRAB THIS TOO}..."
"Some text... {GRAB {THIS}}, some more text {GRAB THIS TOO}..."

julia> L = BetweenFlags.get_level_flat(s, ["{"], ["}"])
2-element Array{String,1}:
 "{GRAB {THIS}}"
 "{GRAB THIS TOO}"
source
get_level(s::String,
          outer_flags::FlagSet,
          inner_flags::Vector{FlagSet},
          inclusive::Bool = true)

This is the featured function of BetweenFlags.

Gets the substring based on the outer and inner flag sets, and a Bool which determines whether the flags themselves should be returned or not.

To see an example of this function in action, go to BetweenFlags/test/runtests.jl.

source