private static Pair<StringBuilder, Boolean> convertFormat(PyStringLiteralExpression stringLiteralExpression, String prefix) {
    // python string may be made of several literals, all different
    List<StringBuilder> constants = new ArrayList<>();
    boolean usesNamedFormat = false;
    final List<ASTNode> stringNodes = stringLiteralExpression.getStringNodes();
    sure(stringNodes);
    sure(stringNodes.size() > 0);
    for (ASTNode stringNode : stringNodes) {
      // preserve prefixes and quote form
      CharSequence text = stringNode.getChars();
      int openPos = 0;
      boolean hasPrefix = false;
      final int prefixLength = PyStringLiteralUtil.getPrefixLength(String.valueOf(text));
      if (prefixLength != 0) hasPrefix = true;
      openPos += prefixLength;

      char quote = text.charAt(openPos);
      sure("\"'".indexOf(quote) >= 0);
      if (text.length() - openPos >= 6) {
        // triple-quoted?
        if (text.charAt(openPos+1) == quote && text.charAt(openPos+2) == quote) {
          openPos += 2;
        }
      }
      int index = openPos + 1; // from quote to first in-string char
      StringBuilder out = new StringBuilder(text.subSequence(0, openPos+1));
      if (!hasPrefix) out.insert(0, prefix);
      Matcher scanner = FORMAT_PATTERN.matcher(text);
      while (scanner.find(index)) {
        // store previous non-format part
        appendDoublingBraces(text.subSequence(index, scanner.start()), out);
        //out.append(text.subSequence(index, scanner.start()));
        // unpack format
        final String f_key = scanner.group(1);
        final String f_modifier = scanner.group(2);
        final String f_width = scanner.group(3);
        String fConversion = scanner.group(4);
        // convert to format()'s
        if ("%%".equals(scanner.group(0))) {
          // shortcut to put a literal %
          out.append("%");
        }
        else {
          sure(fConversion);
          sure(!"%".equals(fConversion)); // a padded percent literal; can't bother to autoconvert, and in 3k % is different.
          out.append("{");
          if (f_key != null) {
            out.append(f_key);
            usesNamedFormat = true;
          }
          if ("r".equals(fConversion)) out.append("!r");
          // don't convert %s -> !s, for %s is the normal way to output the default representation
          out.append(":");
          if (f_modifier != null) {
            out.append(convertFormatSpec(f_modifier, f_width, fConversion));
          }
          if (f_width != null) {
            out.append(f_width);
          }
          if ("i".equals(fConversion) || "u".equals(fConversion)) out.append("d");
          else if (!"s".equals(fConversion) && !"r".equals(fConversion)) out.append(fConversion);

          final int lastIndexOf = out.lastIndexOf(":");
          if (lastIndexOf == out.length() - 1) {
            out.deleteCharAt(lastIndexOf);
          }
          out.append("}");
        }
        index = scanner.end();
      }
      // store non-format final part
      //out.append(text.subSequence(index, text.length()-1));
      appendDoublingBraces(text.subSequence(index, text.length()), out);
      constants.add(out);
    }
    // form the entire literal filling possible gaps between constants.
    // we assume that a string literal begins with its first constant, without a gap.
    TextRange full_range = stringLiteralExpression.getTextRange();
    int full_start = full_range.getStartOffset();
    CharSequence full_text = stringLiteralExpression.getNode().getChars();
    TextRange prev_range = stringNodes.get(0).getTextRange();
    int fragment_no = 1; // look at second and further fragments
    while (fragment_no < stringNodes.size()) {
      TextRange next_range = stringNodes.get(fragment_no).getTextRange();
      int left = prev_range.getEndOffset() - full_start;
      int right = next_range.getStartOffset() - full_start;
      if (left < right) {
        constants.get(fragment_no-1).append(full_text.subSequence(left, right));
      }
      fragment_no += 1;
      prev_range = next_range;
    }
    final int left = prev_range.getEndOffset() - full_start;
    final int right = full_range.getEndOffset() - full_start;
    if (left < right) {
      // the barely possible case of last dangling "\"
      constants.get(constants.size()-1).append(full_text.subSequence(left, right));
    }

    // join everything
    StringBuilder result = new StringBuilder();
    for (StringBuilder one : constants) result.append(one);
    return new Pair<>(result, usesNamedFormat);
  }
private static Pair<StringBuilder, Boolean> convertFormat(PyStringLiteralExpression stringLiteralExpression, String prefix)