Implement methods to go backwards and look backwards inside Scanner
还没有人认领这个 Issue。
评估
调研方向
从 Scanner 入口点开始,比较 issue 中描述的现有 next 和 find 行为。定义按要求更新 scanner 位置的向后等价功能,包括有界搜索行为,并验证 image-link 解析用例能够获取预期范围。
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
I'm trying to implement an InlineContentParser for images from a custom markdown spec from a certain website. Given I already parsed the opener, the spec requires me to look for the first whitespace character or end of text, then going backwards from there, look for the first ). Everything between the opener and ) is considered the image link.
This is a bit annoying to implement with the current limited set of methods Scanner has, and I also imagine the performance would be worse when instead of going backwards from the closer, you go forward from the opener via scanner.find(')') and perform an additional find to see if you just found the last ).
Describe the solution you'd like
I would like for there to be similar methods to next and find that would instead look back from the current Scanner position, i.e prev, and findPrev. Then I could just do the following (sorry that the code is in Kotlin as I don't regularly write Java, I hope the intent is clear):
val start = scanner.position() // position after the opener has been parsed
scanner.find { char -> char.isWhitespace() } // scanner gets moved to first whitespace or very end if there is none
scanner.findPrev(')') // scanner gets moved backwards until the position is at ')'. Ideally there would also be an overload that takes a position until which it should move, so i could pass the `start` to it and it would early exit if it doesn't find one by then
val end = scanner.position()
val imageLink = scanner.getSource(start, end).getContent()
Describe alternatives you've considered
As stated above I have considered iterating forward from the current position to find the next ) and check if there's another one to see if I'd found the last one.
- 主要语言
- Java
- 星标
- 2.7k
- 派生
- 337
- 平均合并
- 15 天 9 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
commonmark/commonmark-java 的其他 Issue
-
Unclosed link reference definition title keeps the partial title and the following paragraph's source spans (0.30.0)可能已有人在做 @sean0407 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 70/100
commonmark/commonmark-java#460 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 74/100
commonmark/commonmark-java#457 ·
-
难度 3/5 1-2 天 新手友好度 48/100
commonmark/commonmark-java#443 · 4 条评论 ·
-
Option to define custom flanking/canOpen/canClose rules for delimiters可能重新可做 @abhiramaab 于 60 天前认领,目前没有进行中的 PR。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 45/100
commonmark/commonmark-java#428 · 4 条评论 ·
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
commonmark/commonmark-java#414 · 1 条评论 · 1 个 reaction ·
查看 commonmark/commonmark-java 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 64/100
utopia-rise/godot-jvm#1004 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
spring-projects/spring-grpc#442 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
resilience4j/resilience4j#2547 ·
维护者通常 9 天内回复
-
Clock.MakeDate continues execution and returns a rolled-over instant after dispatching error on invalid date可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 82/100
mit-cml/appinventor-sources#4155 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 62/100
Hira-shi/PW1-DAI-Carrel-Egal-Eyer#28 ·
维护者通常 1 天内回复