Crates.io | find-matching-bracket |
lib.rs | find-matching-bracket |
version | 0.2.0 |
source | src |
created_at | 2024-07-17 22:41:28.220863 |
updated_at | 2024-07-17 22:43:18.145778 |
description | Finds the matching closing bracket for a given opening bracket in a string. Supports curly braces, square brackets, and parentheses. This crate is useful for parsing code, validating expressions, and more. |
homepage | |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1306658 |
size | 9,180 |
find-matching-bracket
is a Rust crate that helps you find the matching closing bracket for a given opening bracket in a string. It supports curly braces, square brackets, and parentheses. This crate is useful for parsing code, validating expressions, and more.
{}
, square brackets []
, and parentheses ()
.Add this crate to your Cargo.toml
:
[dependencies]
find-matching-bracket = "0.2.0"
use find_matching_bracket::{find_matching_curly_brace, find_matching_square_bracket, find_matching_paren};
fn main() {
let text = "{content}";
let position = find_matching_curly_brace(text, 0);
println!("Matching position: {:?}", position); // Output: Matching position: Some(8)
}
find_matching_bracket
Finds the matching closing bracket for the given opening bracket in a string.
text
: The input string.start
: The starting position of the opening bracket.bracket_type
: The type of bracket (Curly, Square, or Paren).Option<usize>
: The position of the matching closing bracket, or None if no matching bracket is found.find_matching_curly_brace
Finds the matching closing curly bracket {} for the given opening bracket in a string.
text
: The input string.start
: The starting position of the opening curly bracket.Option<usize>
: The position of the matching closing bracket, or None if no matching bracket is found.find_matching_square_bracket
Finds the matching closing square bracket [] for the given opening bracket in a string.
text
: The input string.start
: The starting position of the opening square bracket.Option<usize>
: The position of the matching closing bracket, or None if no matching bracket is found.find_matching_paren
Finds the matching closing parenthesis () for the given opening bracket in a string.
text
: The input string.start
: The starting position of the opening parenthesis.Option<usize>
: The position of the matching closing bracket, or None if no matching bracket is found.let text = "{[()][]}";
let position = find_matching_curly_brace(text, 0);
assert_eq!(position, Some(7));
This project is licensed under the MIT License.