private static int parseLocalProperties()

in zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/ParagraphTextParser.java [72:164]


  private static int parseLocalProperties(
          final String text, int startPos,
          Map<String, String> localProperties) throws  RuntimeException{
    startPos++;
    String propKey = null;
    boolean insideQuotes = false, parseKey = true, finished = false;
    StringBuilder sb = new StringBuilder();
    while(!finished && startPos < text.length()) {
      char ch = text.charAt(startPos);
      switch (ch) {
        case ')': {
          if (!insideQuotes) {
            if (parseKey) {
              propKey = sb.toString().trim();
              if (!propKey.isEmpty()) {
                localProperties.put(propKey, propKey);
              }
            } else {
              localProperties.put(propKey, sb.toString().trim());
            }
            finished = true;
          } else {
            sb.append(ch);
          }
          break;
        }
        case '\\': {
          if ((startPos + 1) == text.length()) {
            throw new RuntimeException(
                    "Problems by parsing paragraph. Unfinished escape sequence");
          }
          startPos++;
          ch = text.charAt(startPos);
          switch (ch) {
            case 'n':
              sb.append('\n');
              break;
            case 't':
              sb.append('\t');
              break;
            default:
              sb.append(ch);
          }
          break;
        }
        case '"': {
          insideQuotes = !insideQuotes;
          break;
        }
        case '=': {
          if (insideQuotes) {
            sb.append(ch);
          } else {
            if (!parseKey) {
              throw new RuntimeException(
                      "Invalid paragraph properties format");
            }
            propKey = sb.toString().trim();
            sb.delete(0, sb.length());
            parseKey = false;
          }
          break;
        }
        case ',': {
          if (insideQuotes) {
            sb.append(ch);
          } else if (propKey == null || propKey.trim().isEmpty()) {
            throw new RuntimeException(
                    "Problems by parsing paragraph. Local property key is empty");
          } else {
            if (parseKey) {
              propKey = sb.toString().trim();
              localProperties.put(propKey, propKey);
            } else {
              localProperties.put(propKey, sb.toString().trim());
            }
            propKey = null;
            parseKey = true;
            sb.delete(0, sb.length());
          }
          break;
        }
        default:
          sb.append(ch);
      }
      startPos++;
    }
    if (!finished) {
      throw new RuntimeException(
              "Problems by parsing paragraph. Not finished interpreter configuration");
    }
    return startPos;
  }