neo-decompiler 0.10.2

Neo N3 NEF decompiler: parse, disassemble, lift bytecode to high-level pseudocode and C# skeletons, with a CLI, JSON reports, and optional WebAssembly bindings.
Documentation
use super::super::super::HighLevelEmitter;

impl HighLevelEmitter {
    /// Collapse `((expr))` to `(expr)` whenever the inner parens form a
    /// matched pair surrounding the entire content.
    pub(crate) fn reduce_double_parens(statements: &mut [String]) {
        for stmt in statements.iter_mut() {
            loop {
                let mut next: Option<String> = None;
                let bytes = stmt.as_bytes();
                let mut i = 0;
                while i + 1 < bytes.len() {
                    if bytes[i] == b'(' && bytes[i + 1] == b'(' {
                        let inner_open = i + 1;
                        let mut depth = 1usize;
                        let mut j = inner_open + 1;
                        while j < bytes.len() {
                            match bytes[j] {
                                b'(' => depth += 1,
                                b')' => {
                                    depth -= 1;
                                    if depth == 0 {
                                        break;
                                    }
                                }
                                _ => {}
                            }
                            j += 1;
                        }
                        if depth != 0 {
                            break;
                        }
                        if j + 1 < bytes.len() && bytes[j + 1] == b')' {
                            let mut rebuilt = String::with_capacity(stmt.len() - 2);
                            rebuilt.push_str(&stmt[..i]);
                            rebuilt.push('(');
                            rebuilt.push_str(&stmt[inner_open + 1..j]);
                            rebuilt.push(')');
                            rebuilt.push_str(&stmt[j + 2..]);
                            next = Some(rebuilt);
                            break;
                        }
                    }
                    i += 1;
                }
                match next {
                    Some(rebuilt) => *stmt = rebuilt,
                    None => break,
                }
            }
        }
    }
}