从Delphi 2007迁移时的CharInSet批量转换

时间:2015-10-02 00:26:08

标签: delphi unicode migration delphi-xe8

我们正在将一些项目从Delphi 2007转移到XE8,并发出以下警告(数百个):

[dcc32 Warning] X.PAS(1568): W1050 WideChar reduced to byte char in set expressions.  Consider using 'CharInSet' function in 'SysUtils' unit.`

我发现其中很多都是

形式
if x in ['1','2','3'] then

需要转换为

if CharInSet(x, ['1','2','3']) then

这看起来可能存在某种正则表达式类型搜索和替换,可用于批量执行这些操作。

有人能想出一种批量转换这些的方法吗?

1 个答案:

答案 0 :(得分:2)

这可以通过IDE中的搜索/替换来完成。

以下内容适用于 XE4

  • 搜索:

    if {[a-z]} in \[{{'[0-9]+'\,? ?}+}\] then
    

    如果要匹配长度超过一个字符的变量,请考虑使用某些量词,例如[a-z]+

  • 替换为:

    if CharInSet\(\0, \[\1\]\) then
    

请注意,IDE使用{}表示组,\0\1 ...作为替换占位符。

Embarcadero Regular Expressions reference for Delphi XE4

IDE 正则表达式搜索:

IDE regex search

结果单位:

IDE regex search replaced

您可能还会发现this question对于进一步参考有用。