Polishing the CSV and Language Parser(s).
This commit is contained in:
@ -9,8 +9,17 @@
|
||||
#include "../libs.h"
|
||||
#include "asset.h"
|
||||
|
||||
#define CSV_BUFFER_SIZE 128
|
||||
#define CSV_BUFFER_ROW_SIZE 16
|
||||
/** Maximum characters that a cell can support */
|
||||
#define CSV_BUFFER_SIZE 32
|
||||
|
||||
/** Maximum characters in any given cell */
|
||||
#define CSV_CELL_SIZE_MAX 1024
|
||||
|
||||
/** Maximum number of columns/cells in a given row */
|
||||
#define CSV_ROW_COLUMNS_MAX 16
|
||||
|
||||
/** Count of characters maximum that a row can support */
|
||||
#define CSV_ROW_CHARACTERS_MAX CSV_CELL_SIZE_MAX * CSV_ROW_COLUMNS_MAX
|
||||
|
||||
/** Result of a CSV buffer operation. */
|
||||
typedef struct {
|
||||
@ -23,28 +32,61 @@ typedef struct {
|
||||
} csvbufferresult_t;
|
||||
|
||||
/** Callback to receive data for each cell in a CSV being buffered */
|
||||
typedef void csvbuffercallback_t(
|
||||
typedef bool csvbuffercallback_t(
|
||||
assetbuffer_t *asset, void *user, int32_t row, int32_t column, char *data
|
||||
);
|
||||
|
||||
/** Representation of a CSV Row's complete data. */
|
||||
typedef struct {
|
||||
/** Characters within the row */
|
||||
char data[CSV_ROW_CHARACTERS_MAX];
|
||||
/** Pointer to the start of each string within the row */
|
||||
char *columns[CSV_ROW_COLUMNS_MAX];
|
||||
/** How many columns within the row */
|
||||
int32_t columnCount;
|
||||
} csvrow_t;
|
||||
|
||||
/** Callback to receive buffer data for a CSV row */
|
||||
typedef void csvbufferrowcallback_t(
|
||||
typedef bool csvbufferrowcallback_t(
|
||||
assetbuffer_t *asset, void *user, int32_t row, csvrow_t *csv
|
||||
);
|
||||
|
||||
/** Callback to receive buffer data for a CSV row, but includes CSV headers. */
|
||||
typedef bool csvbufferrowwitheaderscallback_t(
|
||||
assetbuffer_t *asset, void *user, int32_t row,
|
||||
char **columns, int32_t columnCount
|
||||
csvrow_t *header, csvrow_t *current
|
||||
);
|
||||
|
||||
/** Data used by the cell callback for when the row buffering is progressing */
|
||||
typedef struct {
|
||||
/** Which row the current buffer is on */
|
||||
int32_t row;
|
||||
/** Count of columns (in the current row) */
|
||||
int32_t columnCount;
|
||||
/** Array of characters for the row */
|
||||
char rowData[CSV_BUFFER_ROW_SIZE * CSV_BUFFER_SIZE];
|
||||
/** Pointers to the start of each string within the row */
|
||||
char *columns[CSV_BUFFER_ROW_SIZE];
|
||||
/** Information about the current row being parsed */
|
||||
csvrow_t rowCurrent;
|
||||
/** Pointer to custom user data */
|
||||
void *user;
|
||||
/** Pointer to custom user callback */
|
||||
csvbufferrowcallback_t *callback;
|
||||
} csvbufferrowdata_t;
|
||||
} csvbufferrowdata_t;
|
||||
|
||||
/** Data used by the row callback for when the header row is parsed */
|
||||
typedef struct {
|
||||
/** Information about the header row */
|
||||
csvrow_t headerRow;
|
||||
/** Pointer to custom user data */
|
||||
void *user;
|
||||
/** Pointer to custom user callback */
|
||||
csvbufferrowwitheaderscallback_t *callback;
|
||||
} csvbufferrowwithheadersdata_t;
|
||||
|
||||
/** Data used while searching a CSV */
|
||||
typedef struct {
|
||||
/** Row to store the data in */
|
||||
csvrow_t *row;
|
||||
/** Row's index */
|
||||
int32_t rowIndex;
|
||||
/** Column to check */
|
||||
int32_t column;
|
||||
/** Value to check row */
|
||||
char *value;
|
||||
} csvsearchdata_t;
|
@ -7,16 +7,23 @@
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../file/asset.h"
|
||||
#include "../file/csv.h"
|
||||
|
||||
/** Maximum number of strings a language can hold. */
|
||||
#define LANGUAGE_STRING_MAX 128
|
||||
/** Definition for a Language */
|
||||
typedef struct {
|
||||
/** The buffer to read the asset from. */
|
||||
assetbuffer_t *asset;
|
||||
/** CSV Row for the header */
|
||||
csvrow_t header;
|
||||
/** The index in the header row that the key column is in. */
|
||||
int32_t headerIndexKey;
|
||||
/** The index in the header row that the value column is in. */
|
||||
int32_t headerIndexValue;
|
||||
} language_t;
|
||||
|
||||
typedef struct {
|
||||
language_t *language;
|
||||
csvrow_t *row;
|
||||
char *key;
|
||||
char *text;
|
||||
} languagestring_t;
|
||||
|
||||
typedef struct {
|
||||
languagestring_t strings[LANGUAGE_STRING_MAX];
|
||||
int32_t stringCount;
|
||||
} language_t;
|
||||
} languagecsvget_t;
|
Reference in New Issue
Block a user