你听说过 CSV 文件,但你听说过 CCSV 文件吗?
You've heard of CSV files, but have you heard of CCSV files?

原始链接: https://robida.net/entries/2026/08/12/youve-heard-of-csv-files-but-have-you-heard-of-ccs

虽然 CSV 文件是一种流行且简单的表格数据格式,但一旦数据中包含逗号或引号,解析就会变得困难,因为目前没有官方规范来处理这些边缘情况。 为了解决这个问题,作者提倡使用 **CCSV(控制字符分隔值)**。CCSV 不使用逗号和换行符,而是利用不可打印的 ASCII 控制字符:单元分隔符(ASCII 31)用于分隔列,记录分隔符(ASCII 30)用于分隔行,传输结束字符(ASCII 4)用于标识结尾。由于这些字符不太可能出现在标准数据中,因此解析过程变得更加简便且稳健,无需复杂的逻辑来处理特殊符号。 然而,CCSV 也有一个明显的缺点:由于分隔符是不可打印字符,这些文件无法在标准文本编辑器中轻松阅读或手动编辑。尽管如此,作者认为该格式对于程序化使用非常高效,并特别称赞了使用传输结束字符作为文件结尾的明确标记。

关于“CCSV”(字符分隔值)——即使用不可打印的 ASCII 控制字符替代逗号的分隔格式——Hacker News 上的讨论最终认为,该格式在很大程度上是不切实际的。 尽管支持者认为使用特定的控制字符来分隔单元和记录可以避免标准 CSV 的解析复杂性(例如需要对字符串中的逗号进行转义),但社区指出其存在几个关键缺陷: * **易用性差:** 文件变得难以编辑,无法在标准文本编辑器中查看,如果不使用专门的解码工具,也无法通过命令行工具读取。 * **缺乏互操作性:** 大多数电子表格软件和第三方工具不支持这些分隔符,这破坏了 CSV 的主要优势,即其通用、简单的可交换性。 * **多此一举:** 批评者认为,如果文件已不再可读,那么应该转向结构化的二进制格式(如 Protobuf)或得到广泛支持的替代方案(如 TSV,即制表符分隔值),而不是去重新发明一种“隐藏的”文本格式。 归根结底,用户认为尽管 CSV 有其令人沮丧之处,但其简单性和普及性使其成为一种“常青”标准。尽管现代技术试图通过晦涩的控制字符来“修复”它,但 CSV 在通用数据共享方面仍然更胜一筹。
相关文章

原文

Comma Separated Values (CSV) is a simple plain text format for storing tabular data. To create a CSV file, just write every row of your data as a line in your file, and separate columns using a comma:

name,age,favorite food
Beto,48,hummus
Martim,11,hamburger

It's trivial to parse. For example, here's an example in Python:

for row in open(filename):
    for column in row.strip().split(","):
        print(column)

Easy. Or is it?

What if Martim's favorite food was hamburger, fries, and soda? Now we need to use quotes to represent the cell value:

name,age,favorite food
Beto,48,hummus
Martim,11,"hamburger, fries, and soda"

Parsing is now harder, since we need to keep track of opening and closing quotes. We need to strip the quotes as well, so that the value is hamburger, fries, and soda, instead of "hamburger, fries, and soda". But what if one of the cells has quotes? We need to preserve those!

As you can see, it quickly becomes complicated. Combined with the fact that there's no official specification, parsing CSV files can be a nightmare.

A nice alternative is CCSV: Control Character Separated Values. CCSV files use 3 characters that are non-printable, used only for control:

  • ASCII 30: record separator (␞)

  • ASCII 31: unit separator (␟)

  • ASCII 4: end-of-transmission (␄)

The advantage of using these characters instead of line breaks and commas is that they are very VERY unlikely to appear in your data. When parsing a CCSV file you don't need to handle special cases. Our CSV file would look like this:

name␟age␟favorite food␞
Beto␟48␟hummus␞
Martim␟11␟hamburger, fries, and soda␄

And to parse:

for row in open(filename).read().rstrip(chr(4)).split(chr(30)):
    for column in row.split(chr(31)):
        print(column)

I've been using the format with my new Gforth blog, since it's trivial to generate and parse. But as the CCSV website rightly calls out, there are drawbacks:

The delimiters used in .ccsv files are generally not visible in an ordinary text editor. Editing the files by hand can be difficult, if not impossible, using an editor that is unaware of the file format.

The thing I like the most about CCSV files is that it uses an END OF TRANSMISSION character at the end. How cool is that?

␄

联系我们 contact @ memedata.com