你听说过 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 也有一个明显的缺点:由于分隔符是不可打印字符,这些文件无法在标准文本编辑器中轻松阅读或手动编辑。尽管如此,作者认为该格式对于程序化使用非常高效,并特别称赞了使用传输结束字符作为文件结尾的明确标记。

近期在 Hacker News 上的一场讨论探讨了“CCSV”(或 ASV/USV)文件格式的概念,该格式使用非打印的 ASCII/Unicode 控制字符而非逗号作为分隔符。 尽管支持者认为这种格式可以解决 CSV 中常见的转义和复杂嵌套数据问题,但社区对此普遍持怀疑态度。共识在于,该格式由于牺牲了 CSV 最核心的优势——人类可读性,且未能提供如 Protobuf 等真正二进制格式所具备的性能优势,因此很难成功。 评论者指出了几个实际障碍: * **工具支持:** 大多数文本编辑器和电子表格应用程序不支持原生显示这些控制字符,导致文件难以打开或查看。 * **可用性:** 这些文件无法通过命令行或标准文本编辑器轻松创建或编辑。 * **采用率:** 由于缺乏广泛支持,该格式陷入了“网络效应”困境;因现有工具无法处理,导致其极少被使用。 归根结底,用户认为如果一种数据格式不再具有人类可编辑性,那么与其继续沿用类似 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