public static String removeIndentation()

in src/main/com/intellij/lang/jsgraphql/types/parser/StringValueParsing.java [50:106]


  public static String removeIndentation(String rawValue) {
    String[] lines = rawValue.split("\\n");
    Integer commonIndent = null;
    for (int i = 0; i < lines.length; i++) {
      if (i == 0) continue;
      String line = lines[i];
      int length = line.length();
      int indent = leadingWhitespace(line);
      if (indent < length) {
        if (commonIndent == null || indent < commonIndent) {
          commonIndent = indent;
        }
      }
    }
    List<String> lineList = new ArrayList<>(Arrays.asList(lines));
    if (commonIndent != null) {
      for (int i = 0; i < lineList.size(); i++) {
        String line = lineList.get(i);
        if (i == 0) continue;
        if (line.length() > commonIndent) {
          line = line.substring(commonIndent);
          lineList.set(i, line);
        }
      }
    }
    while (!lineList.isEmpty()) {
      String line = lineList.get(0);
      if (containsOnlyWhiteSpace(line)) {
        lineList.remove(0);
      }
      else {
        break;
      }
    }
    while (!lineList.isEmpty()) {
      int endIndex = lineList.size() - 1;
      String line = lineList.get(endIndex);
      if (containsOnlyWhiteSpace(line)) {
        lineList.remove(endIndex);
      }
      else {
        break;
      }
    }
    StringBuilder formatted = new StringBuilder();
    for (int i = 0; i < lineList.size(); i++) {
      String line = lineList.get(i);
      if (i == 0) {
        formatted.append(line);
      }
      else {
        formatted.append("\n");
        formatted.append(line);
      }
    }
    return formatted.toString();
  }