A bit more code cleanup
This commit is contained in:
@ -1,58 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "language.h"
|
||||
|
||||
void languageInit(language_t *language, char *filename) {
|
||||
// Open the asset buffer
|
||||
language->asset = assetBufferOpen(filename);
|
||||
|
||||
// Get the headers
|
||||
csvHeadersGet(language->asset, &language->header);
|
||||
|
||||
// Get the row indexes
|
||||
language->headerIndexKey = csvColumnGetIndex(
|
||||
&language->header, LANGUAGE_HEADER_KEY
|
||||
);
|
||||
language->headerIndexValue = csvColumnGetIndex(
|
||||
&language->header, LANGUAGE_HEADER_VALUE
|
||||
);
|
||||
}
|
||||
|
||||
int32_t languageGet(
|
||||
language_t *language, char *key, char output[CSV_CELL_SIZE_MAX]
|
||||
) {
|
||||
csvrow_t row;
|
||||
// Reset the buffer
|
||||
assetBufferStart(language->asset);
|
||||
|
||||
// Search the CSV
|
||||
int32_t rowIndex = csvRowSearch(
|
||||
language->asset, &row, language->headerIndexKey, key
|
||||
);
|
||||
if(rowIndex == -1) return rowIndex;// Didn't find anything
|
||||
|
||||
// Copy the string
|
||||
arrayCopy(
|
||||
sizeof(char), row.columns[language->headerIndexValue],
|
||||
CSV_CELL_SIZE_MAX, output
|
||||
);
|
||||
return rowIndex;
|
||||
}
|
||||
|
||||
int32_t languageGetAndParse(language_t *language, char *key,
|
||||
stringhandlebarvariable_t *variables, int32_t variableCount, char *buffer
|
||||
) {
|
||||
char csvBuffer[CSV_CELL_SIZE_MAX];
|
||||
int32_t i = languageGet(language, key, csvBuffer);
|
||||
if(i == -1) return -1;
|
||||
return stringHandlebarsBuffer(csvBuffer, variables, variableCount, buffer);
|
||||
}
|
||||
|
||||
void languageDispose(language_t *language) {
|
||||
assetBufferClose(language->asset);
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2021 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../libs.h"
|
||||
#include "../util/string.h"
|
||||
#include "../file/asset.h"
|
||||
#include "../file/csv.h"
|
||||
|
||||
/** Column name for the KEY within the CSV */
|
||||
#define LANGUAGE_HEADER_KEY "Key"
|
||||
/** Column name for the VALUE within the CSV */
|
||||
#define LANGUAGE_HEADER_VALUE "Value"
|
||||
|
||||
/** 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;
|
||||
} languagecsvget_t;
|
||||
|
||||
/**
|
||||
* Initializes a language.
|
||||
* @param language Language to initialize.
|
||||
* @param filename The filename of the asset that the language uses.
|
||||
*/
|
||||
void languageInit(language_t *language, char *filename);
|
||||
|
||||
/**
|
||||
* Get the value for a given key out of the language buffer.
|
||||
*
|
||||
* @param language Language to get from.
|
||||
* @param key Key to get.
|
||||
* @param output Output buffer to return.
|
||||
* @return Row within the CSV it was found, otherwise -1.
|
||||
*/
|
||||
int32_t languageGet(
|
||||
language_t *language, char *key, char output[CSV_CELL_SIZE_MAX]
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns the parsed handlebars out of the language CSV.
|
||||
*
|
||||
* @param language Language to buffer from.
|
||||
* @param key Key to get out of the CSV.
|
||||
* @param variables Array of variables to parse the handlebars with.
|
||||
* @param variableCount Count of variables in the array.
|
||||
* @param buffer Buffer to store the output data in.
|
||||
* @return Forwarded result of stringHandlebarsBuffer.
|
||||
*/
|
||||
int32_t languageGetAndParse(language_t *language, char *key,
|
||||
stringhandlebarvariable_t *variables, int32_t variableCount, char *buffer
|
||||
);
|
||||
|
||||
/**
|
||||
* Cleanup a previously initialized language.
|
||||
* @param language Language to dispose.
|
||||
*/
|
||||
void languageDispose(language_t *language);
|
Reference in New Issue
Block a user