Skip to content

csv_file_t

概述

操作CSV文件。

函数

函数名称说明
csv_file_append_row追加一行。
csv_file_clear保存。
csv_file_create根据文件创建csv对象。
csv_file_create_empty创建空的csv对象。
csv_file_create_with_buff根据buff创建csv对象。
csv_file_destroy销毁csv对象。
csv_file_find_first查找第一个满足条件的行。
csv_file_get获取指定行列的数据。
csv_file_get_by_name根据列名获取数据。
csv_file_get_checked_rows获取checked行数(包括标题)。
csv_file_get_col_of_name根据列名获取列号。
csv_file_get_cols获取列数。
csv_file_get_first_checked获取第一个勾选的行。
csv_file_get_row获取指定行。
csv_file_get_rows获取行数(包括标题)。
csv_file_get_title获取标题(不存在则返回NULL)。
csv_file_insert_row插入一行。
csv_file_is_row_checked判断指定行是否勾选。
csv_file_load_buff从内存加载csv。
csv_file_load_file从文件加载csv。
csv_file_load_file保存。
csv_file_reload丢弃内存中的修改,重新加载当前文件。
csv_file_remove_checked_rows删除全部勾选的行。
csv_file_remove_row删除指定行。
csv_file_save保存。
csv_file_save_to_buff保存。
csv_file_set修改指定行列的数据。
csv_file_set_filter设置过滤函数。
csv_file_set_max_rows设置最大行数。
csv_file_set_row_checked勾选指定行。
csv_file_set_single_select设置是否单选。
csv_file_uncheck_all取消勾选全部行。

属性

属性名称类型说明
has_titlebool_t是否有标题。
single_selectbool_t是否单选。

csv_file_append_row 函数

  • 函数功能:

追加一行。

  • 函数原型:
ret_t csv_file_append_row (csv_file_t* csv, const char* data);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
dataconst char*数据。

csv_file_clear 函数

  • 函数功能:

保存。

  • 函数原型:
ret_t csv_file_clear (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。

csv_file_create 函数

  • 函数功能:

根据文件创建csv对象。

  • 函数原型:
csv_file_t* csv_file_create (const char* filename, char sep);
  • 参数说明:
参数类型说明
返回值csv_file_t*返回csv对象。
filenameconst char*文件名。
sepchar分隔符。

csv_file_create_empty 函数

  • 函数功能:

创建空的csv对象。

  • 函数原型:
csv_file_t* csv_file_create_empty (char sep, csv_file_filter_t filter, void* ctx);
  • 参数说明:
参数类型说明
返回值csv_file_t*返回csv对象。
sepchar分隔符。
filtercsv_file_filter_t过滤函数。
ctxvoid*过滤函数的上下文。

csv_file_create_with_buff 函数

  • 函数功能:

根据buff创建csv对象。

  • 函数原型:
csv_file_t* csv_file_create_with_buff (const char* buff, uint32_t size, char sep);
  • 参数说明:
参数类型说明
返回值csv_file_t*返回csv对象。
buffconst char*数据。
sizeuint32_t数据长度。
sepchar分隔符。

csv_file_destroy 函数

  • 函数功能:

销毁csv对象。

  • 函数原型:
ret_t csv_file_destroy (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。

csv_file_find_first 函数

  • 函数功能:

查找第一个满足条件的行。

  • 函数原型:
csv_row_t* csv_file_find_first (csv_file_t* csv, tk_compare_t compare, void* ctx);
  • 参数说明:
参数类型说明
返回值csv_row_t*返回行对象。
csvcsv_file_t*csv对象。
comparetk_compare_t比较函数。
ctxvoid*比较函数的上下文。

csv_file_get 函数

  • 函数功能:

获取指定行列的数据。

  • 函数原型:
const char* csv_file_get (csv_file_t* csv, uint32_t row, uint32_t col);
  • 参数说明:
参数类型说明
返回值const char*返回数据。
csvcsv_file_t*csv对象。
rowuint32_t行号。
coluint32_t列号。

csv_file_get_by_name 函数

  • 函数功能:

根据列名获取数据。

  • 函数原型:
const char* csv_file_get_by_name (csv_file_t* csv, uint32_t row, const char* name);
  • 参数说明:
参数类型说明
返回值const char*返回数据。
csvcsv_file_t*csv对象。
rowuint32_t行号。
nameconst char*列名。

csv_file_get_checked_rows 函数

  • 函数功能:

获取checked行数(包括标题)。

  • 函数原型:
uint32_t csv_file_get_checked_rows (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值uint32_t返回checked行数。
csvcsv_file_t*csv对象。

csv_file_get_col_of_name 函数

  • 函数功能:

根据列名获取列号。

  • 函数原型:
int32_t csv_file_get_col_of_name (csv_file_t* csv, const char* name);
  • 参数说明:
参数类型说明
返回值int32_t返回列号。
csvcsv_file_t*csv对象。
nameconst char*列名。

csv_file_get_cols 函数

  • 函数功能:

获取列数。

  • 函数原型:
uint32_t csv_file_get_cols (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值uint32_t返回列数。
csvcsv_file_t*csv对象。

csv_file_get_first_checked 函数

  • 函数功能:

获取第一个勾选的行。

  • 函数原型:
int32_t csv_file_get_first_checked (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值int32_t返回行号。
csvcsv_file_t*csv对象。

csv_file_get_row 函数

  • 函数功能:

获取指定行。

  • 函数原型:
csv_row_t* csv_file_get_row (csv_file_t* csv, uint32_t row);
  • 参数说明:
参数类型说明
返回值csv_row_t*返回行对象。
csvcsv_file_t*csv对象。
rowuint32_t行号。

csv_file_get_rows 函数

  • 函数功能:

获取行数(包括标题)。

  • 函数原型:
uint32_t csv_file_get_rows (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值uint32_t返回行数。
csvcsv_file_t*csv对象。

csv_file_get_title 函数

  • 函数功能:

获取标题(不存在则返回NULL)。

  • 函数原型:
const char* csv_file_get_title (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值const char*返回标题。
csvcsv_file_t*csv对象。

csv_file_insert_row 函数

  • 函数功能:

插入一行。

  • 函数原型:
ret_t csv_file_insert_row (csv_file_t* csv, uint32_t row, const char* data);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
rowuint32_t行号。
dataconst char*数据。

csv_file_is_row_checked 函数

  • 函数功能:

判断指定行是否勾选。

  • 函数原型:
bool_t csv_file_is_row_checked (csv_file_t* csv, uint32_t row);
  • 参数说明:
参数类型说明
返回值bool_t返回TRUE表示勾选,否则表示没勾选。
csvcsv_file_t*csv对象。
rowuint32_t行号。

csv_file_load_buff 函数

  • 函数功能:

从内存加载csv。

  • 函数原型:
ret_t csv_file_load_buff (csv_file_t* csv, const char* buff, uint32_t size);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
buffconst char*数据。
sizeuint32_t数据长度。

csv_file_load_file 函数

  • 函数功能:

从文件加载csv。

  • 函数原型:
ret_t csv_file_load_file (csv_file_t* csv, const char* filename);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
filenameconst char*文件名。

csv_file_load_file 函数

  • 函数功能:

保存。

  • 函数原型:
ret_t csv_file_load_file (csv_file_t* csv, const char* filename);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
filenameconst char*文件名。

csv_file_reload 函数

  • 函数功能:

丢弃内存中的修改,重新加载当前文件。

  • 函数原型:
ret_t csv_file_reload (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。

csv_file_remove_checked_rows 函数

  • 函数功能:

删除全部勾选的行。

  • 函数原型:
ret_t csv_file_remove_checked_rows (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。

csv_file_remove_row 函数

  • 函数功能:

删除指定行。

  • 函数原型:
ret_t csv_file_remove_row (csv_file_t* csv, uint32_t row);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
rowuint32_t行号。

csv_file_save 函数

  • 函数功能:

保存。

  • 函数原型:
ret_t csv_file_save (csv_file_t* csv, const char* filename);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
filenameconst char*文件名。

csv_file_save_to_buff 函数

  • 函数功能:

保存。

  • 函数原型:
ret_t csv_file_save_to_buff (csv_file_t* csv, wbuffer_t* buff);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
buffwbuffer_t*保存结果数据。

csv_file_set 函数

  • 函数功能:

修改指定行列的数据。

  • 函数原型:
ret_t csv_file_set (csv_file_t* csv, uint32_t row, uint32_t col, const char* value);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
rowuint32_t行号。
coluint32_t列号。
valueconst char*值。

csv_file_set_filter 函数

  • 函数功能:

设置过滤函数。

  • 函数原型:
ret_t csv_file_set_filter (csv_file_t* csv, csv_file_filter_t filter, void* ctx);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
filtercsv_file_filter_t过滤函数。
ctxvoid*过滤函数的上下文。

csv_file_set_max_rows 函数

  • 函数功能:

设置最大行数。

  • 函数原型:
ret_t csv_file_set_max_rows (csv_file_t* csv, uint32_t max_rows);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
max_rowsuint32_t最大行数。

csv_file_set_row_checked 函数

  • 函数功能:

勾选指定行。

  • 函数原型:
ret_t csv_file_set_row_checked (csv_file_t* csv, uint32_t row, bool_t checked);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
rowuint32_t行号。
checkedbool_t是否勾选。

csv_file_set_single_select 函数

  • 函数功能:

设置是否单选。

  • 函数原型:
ret_t csv_file_set_single_select (csv_file_t* csv, bool_t single_select);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。
single_selectbool_t是否单选。

csv_file_uncheck_all 函数

  • 函数功能:

取消勾选全部行。

  • 函数原型:
ret_t csv_file_uncheck_all (csv_file_t* csv);
  • 参数说明:
参数类型说明
返回值ret_t返回RET_OK表示成功,否则表示失败。
csvcsv_file_t*csv对象。

has_title 属性

是否有标题。

  • 类型:bool_t

single_select 属性

是否单选。

  • 类型:bool_t