| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
HaskellWorks.Data.BalancedParens.Internal.Broadword.FindClose.Word8
Documentation
findClose :: Word8 -> Count -> Maybe Count Source #
Find the position of the matching close parenthesis.
The position argument and return value is one-based.
If the parenthesis at the input position is an a close, then that is considered the matching close parenthesis.
>>>import HaskellWorks.Data.Bits.BitRead>>>import Data.Maybe
The following scans for the matching close parenthesis for the open parenthesis at position 1:
>>>findClose (fromJust $ bitRead "10000000") 1Just 2
>>>findClose (fromJust $ bitRead "11000000") 1Just 4
>>>findClose (fromJust $ bitRead "11010000") 1Just 6
The following scans for the matching close parenthesis for the open parenthesis at position 2:
>>>findClose (fromJust $ bitRead "11010000") 2Just 3
If the input position has a close parenthesis, then that position is returned:
>>>findClose (fromJust $ bitRead "11010000") 3Just 3
The scan can continue past the end of the input word because every bit after then end of the word is considered to be zero, which is a closing parenthesis:
>>>findClose (fromJust $ bitRead "11111110") 1Just 14