DOC-103 实现 TXT 文本读取 #8

Closed
opened 2026-05-30 19:49:00 +08:00 by wangdl · 2 comments
Owner

读取 TXT 内容,按段落或行生成 block。

UTF-8 读取,非法编码返回明确错误。

验收标准:能读取 UTF-8 TXT、能生成 paragraph blocks、能返回 line count/word count、有单元测试

读取 TXT 内容,按段落或行生成 block。 UTF-8 读取,非法编码返回明确错误。 验收标准:能读取 UTF-8 TXT、能生成 paragraph blocks、能返回 line count/word count、有单元测试
wangdl added this to the M1:Document Core v0.1 milestone 2026-05-30 19:49:00 +08:00
wangdl added the
priority:p0
type:implementation
area:text
labels 2026-05-30 19:49:00 +08:00
Author
Owner

完成项

read_text(file_path) 已实现,UTF-8 读取
parse_text_content(content) 按空行分段落
text_stats(content) 返回行数和字数

API

函数 用途
read_text 读文件 → Vec
parse_text_content 字符串 → 段落 blocks
text_stats 行数 + 字数
TextStats {line_count, word_count}

测试

  • 6 个单元测试,26 个总计全部通过
  • 覆盖:空文本、单/多段落、空白裁剪、统计、文件不存在错误

待跟进

DOC-104 图片 metadata

## 完成项 ✅ read_text(file_path) 已实现,UTF-8 读取 ✅ parse_text_content(content) 按空行分段落 ✅ text_stats(content) 返回行数和字数 ## API | 函数 | 用途 | |------|------| | read_text | 读文件 → Vec<DocumentBlock> | | parse_text_content | 字符串 → 段落 blocks | | text_stats | 行数 + 字数 | | TextStats | {line_count, word_count} | ## 测试 - 6 个单元测试,26 个总计全部通过 - 覆盖:空文本、单/多段落、空白裁剪、统计、文件不存在错误 ## 待跟进 ⬜ DOC-104 图片 metadata
Author
Owner

补充:FFI 已暴露

parseText(content:)[DocumentBlock] 已通过 UDL 导出
按空行分段,返回 Paragraph blocks
readTextStats(filePath:) 返回行数/字数
TextStats { line_count, word_count } 已暴露

Swift 调用示例:

let blocks = try parseText(content: txtString)  // 段落 blocks
let stats = try readTextStats(filePath: path)   // 统计
print("Lines: \(stats.lineCount), Words: \(stats.wordCount)")
## 补充:FFI 已暴露 ✅ ``parseText(content:)`` → ``[DocumentBlock]`` 已通过 UDL 导出 ✅ 按空行分段,返回 Paragraph blocks ✅ ``readTextStats(filePath:)`` 返回行数/字数 ✅ ``TextStats { line_count, word_count }`` 已暴露 Swift 调用示例: ```swift let blocks = try parseText(content: txtString) // 段落 blocks let stats = try readTextStats(filePath: path) // 统计 print("Lines: \(stats.lineCount), Words: \(stats.wordCount)") ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wangdl/zhixi-document-runtime#8
No description provided.