mirror of
git://git.psyc.eu/libpsyc
synced 2024-08-15 03:19:02 +00:00
text: docs
This commit is contained in:
parent
259b51966c
commit
3cebf9b4c3
3 changed files with 80 additions and 25 deletions
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup parsing Parsing Functions
|
* @defgroup parser Parsing Functions
|
||||||
*
|
*
|
||||||
* This module contains all parsing functions.
|
* This module contains all parsing functions.
|
||||||
* @{
|
* @{
|
||||||
|
@ -126,9 +126,9 @@ typedef struct
|
||||||
} psycParseListState;
|
} psycParseListState;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the state struct.
|
* Initializes the state struct.
|
||||||
*
|
*
|
||||||
* @param state Pointer to the state struct that should be initiated.
|
* @param state Pointer to the state struct that should be initialized.
|
||||||
*/
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_initParseState (psycParseState* state)
|
void psyc_initParseState (psycParseState* state)
|
||||||
|
@ -137,9 +137,9 @@ void psyc_initParseState (psycParseState* state)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the state struct with flags.
|
* Initializes the state struct with flags.
|
||||||
*
|
*
|
||||||
* @param state Pointer to the state struct that should be initiated.
|
* @param state Pointer to the state struct that should be initialized.
|
||||||
* @param flags Flags to be set for the parser, see psycParseFlag.
|
* @param flags Flags to be set for the parser, see psycParseFlag.
|
||||||
*/
|
*/
|
||||||
static inline
|
static inline
|
||||||
|
@ -187,9 +187,9 @@ void psyc_setParseBuffer2 (psycParseState* state, char *buffer, size_t length)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initiates the list state struct.
|
* Initializes the list state struct.
|
||||||
*
|
*
|
||||||
* @param state Pointer to the list state struct that should be initiated.
|
* @param state Pointer to the list state struct that should be initialized.
|
||||||
*/
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_initParseListState (psycParseListState* state)
|
void psyc_initParseListState (psycParseListState* state)
|
||||||
|
@ -241,4 +241,4 @@ psycParseListRC psyc_parseList (psycParseListState* state, psycString *name, psy
|
||||||
|
|
||||||
#endif // PSYC_PARSER_H
|
#endif // PSYC_PARSER_H
|
||||||
|
|
||||||
/** @} */ // end of parsing group
|
/** @} */ // end of parser group
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup rendering Rendering Functions
|
* @defgroup render Rendering Functions
|
||||||
*
|
*
|
||||||
* This module contains all rendering functions.
|
* This module contains all rendering functions.
|
||||||
* @{
|
* @{
|
||||||
|
@ -40,4 +40,4 @@ psycRenderRC psyc_renderList (psycList *list, char *buffer, size_t buflen);
|
||||||
|
|
||||||
#endif // PSYC_RENDER_H
|
#endif // PSYC_RENDER_H
|
||||||
|
|
||||||
/** @} */ // end of rendering group
|
/** @} */ // end of render group
|
||||||
|
|
|
@ -1,18 +1,41 @@
|
||||||
/**
|
/**
|
||||||
* The return value definitions for the PSYC text parsing function.
|
* @file psyc/text.h
|
||||||
* @see psyc_text()
|
* @brief Interface for text template rendering.
|
||||||
|
*
|
||||||
|
* All text template functions and the definitions they use are
|
||||||
|
* defined in this file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup text Text template functions
|
||||||
|
*
|
||||||
|
* This module contains all text template functions.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return values for the text template parsing function.
|
||||||
|
* @see psyc_text()
|
||||||
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
/// No substitution was made, nothing was written to the buffer.
|
||||||
PSYC_TEXT_NO_SUBST = -1,
|
PSYC_TEXT_NO_SUBST = -1,
|
||||||
|
/// Text template parsing & rendering complete.
|
||||||
PSYC_TEXT_COMPLETE = 0,
|
PSYC_TEXT_COMPLETE = 0,
|
||||||
|
/// Text template parsing & rendering is incomplete, because the buffer was too small.
|
||||||
|
/// Another call is required to this function with a new buffer.
|
||||||
PSYC_TEXT_INCOMPLETE = 1,
|
PSYC_TEXT_INCOMPLETE = 1,
|
||||||
} psycTextRC;
|
} psycTextRC;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return values for psycTextCB.
|
||||||
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
/// Value not found, don't substitute anything.
|
||||||
PSYC_TEXT_VALUE_NOT_FOUND = -1,
|
PSYC_TEXT_VALUE_NOT_FOUND = -1,
|
||||||
|
/// Value found, substitute contents of the value variable.
|
||||||
PSYC_TEXT_VALUE_FOUND = 0,
|
PSYC_TEXT_VALUE_FOUND = 0,
|
||||||
} psycTextValueRC;
|
} psycTextValueRC;
|
||||||
|
|
||||||
|
@ -33,13 +56,23 @@ typedef struct
|
||||||
* Callback for psyc_text() that produces a value for a match.
|
* Callback for psyc_text() that produces a value for a match.
|
||||||
*
|
*
|
||||||
* The application looks up a match such as _fruit from [_fruit] and
|
* The application looks up a match such as _fruit from [_fruit] and
|
||||||
* if found writes its current value from its variable store into the
|
* if found sets value->ptr & value->length to point to the found value,
|
||||||
* outgoing buffer.. "Apple" for example. The template returns the
|
* "Apple" for example. 0 is a legal value for the length.
|
||||||
* number of bytes written. 0 is a legal return value. Should the
|
* The callbacks returns either PSYC_TEXT_VALUE_FOUND or
|
||||||
* callback return -1, psyc_text leaves the original template text as is.
|
* PSYC_TEXT_VALUE_NOT_FOUND if no match found in which case psyc_text
|
||||||
|
* leaves the original template text as is.
|
||||||
*/
|
*/
|
||||||
typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *value);
|
typedef psycTextValueRC (*psycTextCB)(const char *name, size_t len, psycString *value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the PSYC text state struct.
|
||||||
|
*
|
||||||
|
* @param state Pointer to the PSYC text state struct that should be initialized.
|
||||||
|
* @param template Text template to be parsed.
|
||||||
|
* @param tlen Length of template.
|
||||||
|
* @param buffer Buffer where the rendered text is going to be written.
|
||||||
|
* @param blen Length of buffer.
|
||||||
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_initTextState (psycTextState *state,
|
void psyc_initTextState (psycTextState *state,
|
||||||
char *template, size_t tlen,
|
char *template, size_t tlen,
|
||||||
|
@ -52,6 +85,19 @@ void psyc_initTextState (psycTextState *state,
|
||||||
state->close = psyc_newString("]", 1);
|
state->close = psyc_newString("]", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the PSYC text state struct with custom open & closing braces.
|
||||||
|
*
|
||||||
|
* @param state Pointer to the PSYC text state struct that should be initialized.
|
||||||
|
* @param template Text template to be parsed.
|
||||||
|
* @param tlen Length of template.
|
||||||
|
* @param buffer Buffer where the rendered text is going to be written.
|
||||||
|
* @param blen Length of buffer.
|
||||||
|
* @param open Opening brace.
|
||||||
|
* @param openlen Length of opening brace.
|
||||||
|
* @param close Closing brace.
|
||||||
|
* @param closelen Length of closing brace.
|
||||||
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_initTextState2 (psycTextState* state,
|
void psyc_initTextState2 (psycTextState* state,
|
||||||
char *template, size_t tlen,
|
char *template, size_t tlen,
|
||||||
|
@ -65,6 +111,9 @@ void psyc_initTextState2 (psycTextState* state,
|
||||||
state->close = psyc_newString(close, closelen);
|
state->close = psyc_newString(close, closelen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new buffer in the PSYC text state struct.
|
||||||
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_setTextBuffer (psycTextState* state, psycString buffer)
|
void psyc_setTextBuffer (psycTextState* state, psycString buffer)
|
||||||
{
|
{
|
||||||
|
@ -72,6 +121,9 @@ void psyc_setTextBuffer (psycTextState* state, psycString buffer)
|
||||||
state->written = 0;
|
state->written = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a new buffer in the PSYC text state struct.
|
||||||
|
*/
|
||||||
static inline
|
static inline
|
||||||
void psyc_setTextBuffer2 (psycTextState* state,
|
void psyc_setTextBuffer2 (psycTextState* state,
|
||||||
char *buffer, size_t length)
|
char *buffer, size_t length)
|
||||||
|
@ -82,15 +134,18 @@ void psyc_setTextBuffer2 (psycTextState* state,
|
||||||
/**
|
/**
|
||||||
* Fills out text templates by asking a callback for content.
|
* Fills out text templates by asking a callback for content.
|
||||||
*
|
*
|
||||||
* Copies the contents of the template into the buffer while looking
|
* Copies the contents of the template into the buffer while looking for the
|
||||||
* for braceOpen and braceClose strings and calling the callback for
|
* opening and closing brace strings and calling the callback for each enclosed
|
||||||
* each enclosed string between these braces. Should the callback
|
* string between these braces. Should the callback return
|
||||||
* return -1, the original template text is copied as is.
|
* PSYC_TEXT_VALUE_NOT_FOUND, the original template text is copied as is.
|
||||||
*
|
*
|
||||||
* By default PSYC's "[" and "]" are used but you can provide any other
|
* Before calling this function psyc_initTextState or psyc_initTextState should
|
||||||
* brace strings such as "${" and "}" or "<!--" and "-->".
|
* be called to initialze the state struct. By default PSYC's "[" and "]" are
|
||||||
|
* used but you can provide any other brace strings such as "${" and "}" or
|
||||||
|
* "<!--" and "-->".
|
||||||
*
|
*
|
||||||
* See also http://about.psyc.eu/psyctext
|
* @see http://about.psyc.eu/psyctext
|
||||||
*/
|
**/
|
||||||
|
|
||||||
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue);
|
psycTextRC psyc_text (psycTextState *state, psycTextCB getValue);
|
||||||
|
|
||||||
|
/** @} */ // end of text group
|
||||||
|
|
Loading…
Reference in a new issue