【问题标题】:Convert new lines from linux to windows using replaceregexp with ant使用带有 ant 的 replaceregexp 将新行从 linux 转换为 windows
【发布时间】:2016-12-23 11:00:39
【问题描述】:

我想在 ant 脚本上使用 replaceregexp 将所有源代码转换为 windows 行,但是对于更多组合我尝试失败了。

我已尝试使用下一个代码,但它会打印文字“rl”:

<replaceregexp match="\n" replace="\r\n" flags="g" byline="false" >
    <fileset dir="${src}">
        <include name="**/*.java" />
    </fileset>
</replaceregexp>

我不能使用 ${line.separator},因为我正在从 linux 执行 ant 脚本,所以它被评估为 \n

可以吗?怎么样?

【问题讨论】:

    标签: regex linux ant newline


    【解决方案1】:

    您可以使用专门用于此目的的 Ant &lt;fixcrlf&gt; 任务。比如:

    <fixcrlf eol="crlf" srcdir="${src}" includes="**/*.java" />
    

    还具有无需添加多个\r 字符即可安全重复的优点。

    要使用replaceregexp 任务自己插入 CRLF,请使用 XML 实体:

    ... replace="&#13;&#10;" ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多