我最近一直在处理很多字符集,在尝试为随机网页建立正确的字符集时发现了很多问题。
字符集可以在 html 文档的标题中设置,也可以在 <head>
中设置。节,多次或有时省略声明。尽管存在这些问题,chrome 每次都在设置最佳字符集方面做得很好。
我试过搜索 the sources但没有设法找到任何东西,因为我不知道去哪里找。
所以我的问题是我在哪里可以找到算法?
谢谢
更新:
有问题的例子:
文档的 HTTP header (基于服务器配置):
Content-type: text/html; charset=utf-8
文件看起来像:
<?xml version="1.0" encoding="ISO-8859-1"?>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-type" content="text/html;charset=ISO-8859-1" />
</head>
<body>...</body>
</html>
将使用哪种编码来呈现文本?
最佳答案
Chrome 使用 https://github.com/google/compact_enc_det
如果你想阅读调用该项目的实际代码,函数是 DetectTextEncoding
在文件中 third_party/blink/renderer/platform/text/text_encoding_detector.cc
关于google-chrome - chrome 如何建立正确的字符编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13155467/