protected static Map parseSetAttributesAsTextArg()

in stetho/src/main/java/com/facebook/stetho/inspector/elements/Descriptor.java [74:101]


  protected static Map<String, String> parseSetAttributesAsTextArg(String text) {
    String value = "";
    String key = "";
    StringBuilder buffer = new StringBuilder();
    Map<String, String> keyValuePairs = new HashMap<>();
    boolean isInsideQuotes = false;
    for (int i = 0, N = text.length(); i < N; ++i) {
      final char c = text.charAt(i);
      if (c == '=') {
        key = buffer.toString();
        buffer.setLength(0);
      } else if (c == '\"') {
        if (isInsideQuotes) {
          value = buffer.toString();
          buffer.setLength(0);
        }
        isInsideQuotes = !isInsideQuotes;
      } else if (c == ' ' && !isInsideQuotes) {
        keyValuePairs.put(key, value);
      } else {
        buffer.append(c);
      }
    }
    if (!key.isEmpty() && !value.isEmpty()) {
      keyValuePairs.put(key, value);
    }
    return keyValuePairs;
  }