Beispiel #1
0
  /** Handles the case where we found a '#' in the code. */
  private int handleComment(
      FormatStd std,
      char[] cs,
      FastStringBuffer buf,
      FastStringBuffer tempBuf,
      ParsingUtils parsingUtils,
      int i) {
    if (std.spacesBeforeComment != FormatStd.DONT_HANDLE_SPACES) {
      for (int j = i - 1; j >= 0; j--) {
        char cj = cs[j];
        if (cj == '\t' || cj == ' ') {
          continue;
        }
        // Ok, found a non-whitespace -- if it's not a new line, we're after some
        // code, in which case we have to put the configured amount of spaces.
        if (cj != '\r' && cj != '\n') {
          buf.rightTrim();
          buf.appendN(' ', std.spacesBeforeComment);
        }
        break;
      }
    }

    tempBuf.clear();
    i = parsingUtils.eatComments(tempBuf, i);
    if (std.trimLines) {
      String endLine = "";
      if (tempBuf.endsWith("\r\n")) {
        endLine = "\r\n";
        tempBuf.deleteLastChars(2);
      } else if (tempBuf.endsWith('\r') || tempBuf.endsWith('\n')) {
        endLine += tempBuf.lastChar();
        tempBuf.deleteLast();
      }
      tempBuf.rightTrim();
      tempBuf.append(endLine);
    }

    formatComment(std, tempBuf);

    buf.append(tempBuf);
    return i;
  }