nested

package
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package nested provides functions for testing strings proper brackets nesting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBalanced

func IsBalanced(input string) bool

IsBalanced returns true if provided input string is properly nested.

Input is a sequence of brackets: '(', ')', '[', ']', '{', '}'.

A sequence of brackets `s` is considered properly nested if any of the following conditions are true:

  • `s` is empty;
  • `s` has the form (U) or [U] or {U} where U is a properly nested string;
  • `s` has the form VW where V and W are properly nested strings.

For example, the string "()()[()]" is properly nested but "[(()]" is not.

**Note** Providing characters other then brackets would return false, despite brackets sequence in the string. Make sure to filter input before usage.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL