161 lines
4.4 KiB
C
161 lines
4.4 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "asset/asset.h"
|
|
|
|
#define ASSET_LOCALE_FILE_PLURAL_FORM_COUNT 6
|
|
|
|
typedef enum {
|
|
ASSET_LOCALE_PLURAL_OP_EQUAL,
|
|
ASSET_LOCALE_PLURAL_OP_NOT_EQUAL,
|
|
ASSET_LOCALE_PLURAL_OP_LESS,
|
|
ASSET_LOCALE_PLURAL_OP_LESS_EQUAL,
|
|
ASSET_LOCALE_PLURAL_OP_GREATER,
|
|
ASSET_LOCALE_PLURAL_OP_GREATER_EQUAL
|
|
} assetlocalepluraloperation_t;
|
|
|
|
typedef enum {
|
|
ASSET_LOCALE_ARG_STRING,
|
|
ASSET_LOCALE_ARG_INT,
|
|
ASSET_LOCALE_ARG_FLOAT
|
|
} assetlocaleargtype_t;
|
|
|
|
typedef struct {
|
|
assetlocaleargtype_t type;
|
|
union {
|
|
const char_t *stringValue;
|
|
int32_t intValue;
|
|
float_t floatValue;
|
|
};
|
|
} assetlocalearg_t;
|
|
|
|
typedef struct {
|
|
assetfile_t file;
|
|
assetlocalepluraloperation_t pluralOps[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
|
|
int32_t pluralValues[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
|
|
int32_t pluralIndices[ASSET_LOCALE_FILE_PLURAL_FORM_COUNT];
|
|
uint8_t pluralStateCount;
|
|
uint8_t pluralDefaultIndex;
|
|
} assetlocalefile_t;
|
|
|
|
/**
|
|
* Initialize a locale asset file.
|
|
*
|
|
* @param localeFile The locale file to initialize.
|
|
* @param path The path to the locale file.
|
|
* @return An error code if a failure occurs.
|
|
*/
|
|
errorret_t assetLocaleFileInit(
|
|
assetlocalefile_t *localeFile,
|
|
const char_t *path
|
|
);
|
|
|
|
/**
|
|
* Dispose of a locale asset file.
|
|
*
|
|
* @param localeFile The locale file to dispose of.
|
|
* @return An error code if a failure occurs.
|
|
*/
|
|
errorret_t assetLocaleFileDispose(assetlocalefile_t *localeFile);
|
|
|
|
errorret_t assetLocaleParseHeader(
|
|
assetlocalefile_t *localeFile,
|
|
char_t *headerBuffer,
|
|
const size_t headerBufferSize
|
|
);
|
|
|
|
/**
|
|
* Skips blank lines and comment lines in the line reader.
|
|
*
|
|
* @param reader Line reader to read from.
|
|
* @param lineBuffer Buffer to use for reading lines.
|
|
* @return Any error that occurs during skipping.
|
|
*/
|
|
errorret_t assetLocaleLineSkipBlanks(
|
|
assetfilelinereader_t *reader,
|
|
uint8_t *lineBuffer
|
|
);
|
|
|
|
/**
|
|
* Unbuffers a potentially multi-line quoted string from the line reader.
|
|
*
|
|
* This will read lines until it finds a line that starts with a quote, then
|
|
* read until the closing quote.
|
|
*
|
|
* @param reader Line reader to read from.
|
|
* @param lineBuffer Buffer to use for reading lines.
|
|
* @param stringBuffer Buffer to write the unbuffered string to.
|
|
* @param stringBufferSize Size of the string buffer.
|
|
* @return Any error that occurs during unbuffering.
|
|
*/
|
|
errorret_t assetLocaleLineUnbuffer(
|
|
assetfilelinereader_t *reader,
|
|
uint8_t *lineBuffer,
|
|
uint8_t *stringBuffer,
|
|
const size_t stringBufferSize
|
|
);
|
|
|
|
/**
|
|
* Test function for locale asset loading.
|
|
*
|
|
* @param file Asset file to test loading from.
|
|
* @param messageId The message ID to retrieve.
|
|
* @param pluralCount Count for formulating the plural variant.
|
|
* @param stringBuffer Buffer to write the retrieved string to.
|
|
* @param stringBufferSize Size of the string buffer.
|
|
* @return Any error that occurs during testing.
|
|
*/
|
|
errorret_t assetLocaleGetString(
|
|
assetlocalefile_t *file,
|
|
const char_t *messageId,
|
|
const int32_t pluralCount,
|
|
char_t *stringBuffer,
|
|
const size_t stringBufferSize
|
|
);
|
|
|
|
/**
|
|
* Test function for locale asset loading with a variable argument list.
|
|
*
|
|
* @param file Asset file to test loading from.
|
|
* @param messageId The message ID to retrieve.
|
|
* @param pluralCount Count for formulating the plural variant.
|
|
* @param buffer Buffer to write the retrieved string to.
|
|
* @param bufferSize Size of the buffer.
|
|
* @param ... Additional arguments for formatting the string.
|
|
* @return Any error that occurs during testing.
|
|
*/
|
|
errorret_t assetLocaleGetStringWithVA(
|
|
assetlocalefile_t *file,
|
|
const char_t *messageId,
|
|
const int32_t pluralCount,
|
|
char_t *buffer,
|
|
const size_t bufferSize,
|
|
...
|
|
);
|
|
|
|
/**
|
|
* Test function for locale asset loading with a list of arguments.
|
|
*
|
|
* @param file Asset file to test loading from.
|
|
* @param messageId The message ID to retrieve.
|
|
* @param pluralCount Count for formulating the plural variant.
|
|
* @param buffer Buffer to write the retrieved string to.
|
|
* @param bufferSize Size of the buffer.
|
|
* @param args List of arguments for formatting the string.
|
|
* @param argCount Number of arguments in the list.
|
|
* @return Any error that occurs during testing.
|
|
*/
|
|
errorret_t assetLocaleGetStringWithArgs(
|
|
assetlocalefile_t *file,
|
|
const char_t *messageId,
|
|
const int32_t pluralCount,
|
|
char_t *buffer,
|
|
const size_t bufferSize,
|
|
const assetlocalearg_t *args,
|
|
const size_t argCount
|
|
); |