Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我需要对给定字符串中的 XML 转义字符进行转义:例如,我需要&用&、"with "、<with<等替换。我更喜欢纯粹的功能解决方案。
&
&
"
"
<
<
这样做有意义scalaz.Zipper吗?Zipper允许检查焦点右侧的字符并在向前移动时跳过它们。不会是矫枉过正吗?你会建议一个更简单的解决方案吗?
scalaz.Zipper
Zipper
Zipper更擅长处理需要访问任一侧字符的 1:1 字符-字符映射,而不是更改字符串中字符数的映射。
我建议使用 XML 解析库(scala 有一个合理的 scala-xml 形式的内置 ish)、字符串转义/取消转义实用程序函数(apache commons 中有一个处理 xml 实体 IIRC)或如果您真的想要一个花哨的解决方案,那么也许可以使用 scala-parser-combinators 解析您的字符串。