Matching Brackets Function Functional

Have amended the matching_brackets() function and it passes all
tests thus far. There may be more room for tidying up, the switch
statement feels like overkill, but I can't think how to generalise it.