ListenerUtil.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:SwiftAnalyzer 作者:
/**
 * Returns location of the end multiline comment symbol.
 *
 * @param comment A token representing a comment
 * @return Location of the end symbol
 */
public static Location getEndOfMultilineComment(Token comment) {
    String commentText = comment.getText();
    if (commentText.charAt(commentText.length() - 1) == '\n') {
        commentText = commentText.substring(0, commentText.length() - 1);
    }
    int numNewlines = 0;
    int lastNewlineIndex = -1;
    for (int i = 0; i < commentText.length(); i++) {
        if (commentText.charAt(i) == '\n') {
            lastNewlineIndex = i;
            numNewlines += 1;
        }
    }
    String lastLine = commentText.substring(lastNewlineIndex + 1);
    return new Location(comment.getLine() + numNewlines,
        numNewlines == 0 ? comment.getCharPositionInLine() + lastLine.length() - 1 : lastLine.length() - 1);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号