code: private static String[] split(String input) {
          char macroStart = MACRO_START.charAt(0);
          char macroEnd = MACRO_END.charAt(0);
  
          int startIndex = 0;
          boolean inMacro = false;
  
          List<String> list = new ArrayList<String>();
  
          for (int endIndex = 0; endIndex < input.length(); endIndex++) {
              char chr = input.charAt(endIndex);
  
              if (!inMacro) {
                  if (chr == macroStart) {
                      String result = input.substring(startIndex, endIndex);
                      if (result.length() > 0) {
                          list.add(result);
                      }
                      inMacro = true;
                      startIndex = endIndex;
                  }
              } else {
                  if (chr == macroEnd) {
                      String result = input.substring(startIndex, endIndex + 1);
                      if (result.length() > 0) {
                          list.add(result);
                      }
                      inMacro = false;
                      startIndex = endIndex + 1;
                  }
              }
          }
  
          String result = input.substring(startIndex);
          if (result.length() > 0) {
              list.add(result);
          }
  
          return list.toArray(new String[list.size()]);
      }
docs: Split keeping delimiters in split result