如何防止BOM从Perforce unicode文件中删除 [英] How to keep BOM from removal from Perforce unicode files

查看:249
本文介绍了如何防止BOM从Perforce unicode文件中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将具有.NET和SQL源的整个分支转换为具有BOM表的 UTF-8 ,并在同一操作中将其Perforce文件类型更改为 Unicode . (编码上的差异可能令人困惑,但是在Perforce中, Unicode 文件类型表示UTF-8文件的内容.)但是后来我发现Perforce默默地从UTF-8文件中消除了BOM标记.是否可以将Perforce设置为在 Unicode 文件类型的文件中保留UTF-8 BOM标记?我找不到记录.

I have converted entire branch with .NET and SQL sources to UTF-8 with BOM, having their Perforce file type changed to Unicode in the same operation. (Encoding difference might sound confusing, but in Perforce, Unicode file type denotes UTF-8 file content.) But later I have found out that Perforce silently elliminates BOM marker from UTF-8 files. Is it possible to set Perforce to keep UTF-8 BOM markers in files of Unicode file type? I can't find it documented.

Perforce服务器已切换为 Unicode 模式,连接编码为 UTF-8 ,没有BOM(但使用BOM将其更改为 UTF-8 没什么区别.)

Perforce server is switched to Unicode mode, connection encoding is UTF-8 no BOM (but changing it to UTF-8 with BOM doesn't make any difference).

示例:

  1. 从Perforce签出源文件
  2. 将文件类型更改为 Unicode
  3. 将文件内容转换为带BOM的UTF-8"格式
  4. 提交文件(现在文件仍将BOM保留在前3个字节中)
  5. 从工作区中删除文件
  6. 获取文件的最新修订版(现在文件开头不包含BOM)
  1. check out a source file from Perforce
  2. change file type to Unicode
  3. convert file content to format "UTF-8 with BOM"
  4. submit the file (now the file still keeps BOM in first 3 bytes)
  5. remove the file from workspace
  6. get the latest revision of the file (now the file doesn't contain BOM at the beginning)

推荐答案

好的,Hans Passant的评论鼓励我重新检查P4CHARSET,最后,答案包括两个部分:

OK, Hans Passant's comment encouraged me to re-examine P4CHARSET and finally, the answer has two parts:

对于Perforce命令行访问,设置P4CHARSET变量可控制行为.要启用将BOM添加到 Unicode 类型的文件中,请使用命令

For Perforce command line access, setting of P4CHARSET variable controls the behavior. To enable adding BOM to files of Unicode type, use command

p4 set P4CHARSET=utf8-bom

要使这些文件没有 BOM,请使用

In order to have these files without BOM, use

p4 set P4CHARSET=utf8


对于P4V Perforce Visual Client ,可以通过菜单Connection> Choose Character Encoding...更改设置.使用值Unicode (UTF-8)启用添加BOM表,使用Unicode (UTF-8, no BOM)禁止添加BOM表.


For P4V The Perforce Visual Client, the setting can be changed via menu Connection > Choose Character Encoding.... Use value Unicode (UTF-8) to enable adding BOM and Unicode (UTF-8, no BOM) to suppress it.

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆