find_close_bucket

Crates.iofind_close_bucket
lib.rsfind_close_bucket
version0.1.2
created_at2025-07-23 08:02:59.14638+00
updated_at2025-07-23 08:08:33.399537+00
descriptionfind_close_bucket
homepagehttps://github.com/i18n-site/rust/tree/dev/find_close_bucket
repositoryhttps://github.com/i18n-site/rust.git
max_upload_size
id1764469
size21,759
i18n.site (i18nsite)

documentation

README

find_close_bucket

pub fn find_close_bucket(txt: impl AsRef<str>, start: char, end: char) -> Option<usize> {
  let txt = txt.as_ref();

  let mut count: usize = 0;
  let mut iter = txt.char_indices();

  while let Some((i, c)) = iter.next() {
    if c == start {
      count += 1;
    } else if c == end {
      if count == 0 {
        return Some(i);
      }
      count -= 1;
    } else if c == '\\' {
      iter.next();
    }
  }

  None
}

About

This project is an open-source component of i18n.site ⋅ Internationalization Solution.

关于

本项目为 i18n.site ⋅ 国际化解决方案 的开源组件。

Commit count: 68

cargo fmt