code: public String chompBalanced(char open, char close) {
          int start = -1;
          int end = -1;
          int depth = 0;
          char last = 0;
          boolean inQuote = false;
  
          do {
              if (isEmpty())
                  break;
              Character c = consume();
              if (last == 0 || last != ESC) {
                  if ((c.equals('\'') || c.equals('"')) && c != open)
                      inQuote = !inQuote;
                  if (inQuote)
                      continue;
                  if (open != close) {
                      if (c.equals(open)) {
                          depth++;
                          if (start == -1)
                              start = pos;
                      } else if (c.equals(close))
                          depth--;
                  } else {// 开闭相同的时候,相同即可退出
                      if (c.equals(open)) {
                          depth++;
                          if (start == -1) {
                              start = pos;
                          }
                      }
                      if (depth == 2) {
                          end = pos - 1;// 末尾数据不要
                          break;
                      }
                  }
              }
  
              if (depth > 0 && last != 0)
                  end = pos; // don't include the outer match pair in the return
              last = c;
          } while (depth > 0);
          // 允许为空结果
          if (start == end) {
              return "";
          }
  
          // 如匹配失败,返回null
          return (end >= 0) ? queue.substring(start, end) : null;
      }
docs: Pulls a balanced string off the queue. E.g. if queue is "(one (two) three) four", (,) will return
  "one (two) three", and leave " four" on the queue. Unbalanced openers and closers can quoted (with ' or ") or
  escaped (with \). Those escapes will be left in the returned string, which is suitable for regexes (where we need
  to preserve the escape), but unsuitable for contains text strings; use unescape for that.
  
  @param open opener
  @param close closer
  @return data matched from the queue