import Foundation

func stripBlocks(from str: String, open: String = "") -> String {
  guard!open.isEmpty &&!close.isEmpty else {
    return str
  }

  var ret = str

  while let begin = ret.range(of: open), let end = ret[begin.upperBound...].range(of: close) {
    ret.replaceSubrange(Range(uncheckedBounds: (begin.lowerBound, end.upperBound)), with: "")
  }

  return ret
}

let test = """
             
           function subroutine() {
            a =  b + c;
           }
           

           
            function something() {
            }
           """

print(stripBlocks(from: test))