locbalpar {lazy.tools}R Documentation

Return the locations of the matching parentheses in a string.

Description

Return the locations of the matching parentheses in a string.

Usage

locbalpar(exp, loc)

Arguments

exp

Input string: a single (vector of length 1).

loc

The starting or ending locations of the parentheses whose matching pair will be found.

Details

loc must be positive and less than nchar(exp).
substring(exp,loc,loc) must be opening or closing parens.
Otherwise, this function returns 0.

Value

The location vecotr of length(loc) of the matching parens or 0.

Examples

# Input string
#                1111111111222222222233333333
#       1234567890123456789012345678901234567
exp <- "a+([a+b]*(c*{d+e}))-(f-g) +(((<()>)) "

locbalpar( exp, 3 )
locbalpar( exp, 19 )
locbalpar( exp, c(4,8) )
locbalpar( exp, c(13,17) )
locbalpar( exp, c(31,34) )
locbalpar( exp, c(34,31, 3,19) )

locbalpar( exp, regexpr( "\\(", exp ) )

# No matching paren
locbalpar( exp, 28 )


# As long as substr(exp,n,1) is a paren, below should always be true.
n <- 10; n == locbalpar( exp, locbalpar( exp, n ) )
n <- 36; n == locbalpar( exp, locbalpar( exp, n ) )


[Package lazy.tools version 0.1.4 ]