You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief 流式 TSV 解析器:按块喂数据,每解析出一整行就回调,只保留未完成尾块
|
|
|
|
|
|
*/
|
|
|
|
|
|
class StreamingTsvParser
|
|
|
|
|
|
{
|
|
|
|
|
|
public:
|
|
|
|
|
|
/// lineIndex 0 = 表头行,之后为数据行;fields 为该行按 Tab 分割的字段(UTF-8)
|
|
|
|
|
|
using LineCallback = std::function<void(int lineIndex, const std::vector<std::string>& fields)>;
|
|
|
|
|
|
|
|
|
|
|
|
void SetCallback(LineCallback cb) { m_callback = std::move(cb); }
|
|
|
|
|
|
|
|
|
|
|
|
/// 喂入一块数据,可能触发多次 OnLine 回调
|
|
|
|
|
|
void Feed(const void* data, size_t size);
|
|
|
|
|
|
|
|
|
|
|
|
/// 结束:处理缓冲区中剩余内容作为最后一行(若有)
|
|
|
|
|
|
void End();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
void ProcessBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
std::string m_buffer;
|
|
|
|
|
|
int m_lineIndex = 0;
|
|
|
|
|
|
LineCallback m_callback;
|
|
|
|
|
|
};
|