mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-05-29 16:09:13 +00:00
Document iconv functions + add testautomation (#10131)
* stdinc: document SDL_iconv* functions * iconv: add automation tests * iconv: don't potentially crash on invalid inputs
This commit is contained in:
parent
75d89f8e12
commit
0fa2049fef
3 changed files with 204 additions and 5 deletions
include/SDL3
|
@ -2899,14 +2899,70 @@ extern SDL_DECLSPEC float SDLCALL SDL_tanf(float x);
|
|||
#define SDL_ICONV_EILSEQ (size_t)-3
|
||||
#define SDL_ICONV_EINVAL (size_t)-4
|
||||
|
||||
/* SDL_iconv_* are now always real symbols/types, not macros or inlined. */
|
||||
typedef struct SDL_iconv_data_t *SDL_iconv_t;
|
||||
|
||||
/**
|
||||
* This function allocates a context for the specified character set conversion.
|
||||
*
|
||||
* \param tocode The target character encoding, must not be NULL.
|
||||
* \param fromcode The source character encoding, must not be NULL.
|
||||
* \returns a handle that must be freed with SDL_iconv_close,
|
||||
* or SDL_ICONV_ERROR on failure.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_iconv
|
||||
* \sa SDL_iconv_close
|
||||
* \sa SDL_iconv_string
|
||||
*/
|
||||
extern SDL_DECLSPEC SDL_iconv_t SDLCALL SDL_iconv_open(const char *tocode,
|
||||
const char *fromcode);
|
||||
|
||||
/**
|
||||
* This function frees a context used for character set conversion.
|
||||
*
|
||||
* \param cd The character set conversion handle.
|
||||
* \returns 0 on success, or -1 on failure.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_iconv
|
||||
* \sa SDL_iconv_open
|
||||
* \sa SDL_iconv_string
|
||||
*/
|
||||
extern SDL_DECLSPEC int SDLCALL SDL_iconv_close(SDL_iconv_t cd);
|
||||
|
||||
/**
|
||||
* This function converts text between encodings, reading from and writing to a buffer.
|
||||
* It returns the number of succesful conversions.
|
||||
*
|
||||
* \param cd The character set conversion context, created in SDL_iconv_open().
|
||||
* \param inbuf Address of variable that points to the first character of the input sequence.
|
||||
* \param inbytesleft The number of bytes in the input buffer.
|
||||
* \param outbuf Address of variable that points to the output buffer.
|
||||
* \param outbytesleft The number of bytes in the output buffer.
|
||||
* \returns the number of conversions on success, else
|
||||
* SDL_ICONV_E2BIG is returned when the output buffer is too small, or
|
||||
* SDL_ICONV_EILSEQ is returned when an invalid input sequence is encountered, or
|
||||
* SDL_ICONV_EINVAL is returned when an incomplete input sequence is encountered.
|
||||
*
|
||||
* On exit:
|
||||
* - inbuf will point to the beginning of the next multibyte sequence.
|
||||
* On error, this is the location of the problematic input sequence.
|
||||
* On success, this is the end of the input sequence.
|
||||
* - inbytesleft will be set to the number of bytes left to convert, which will be 0 on success.
|
||||
* - outbuf will point to the location where to store the next output byte.
|
||||
* - outbytesleft will be set to the number of bytes left in the output buffer.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_iconv_open
|
||||
* \sa SDL_iconv_close
|
||||
* \sa SDL_iconv_string
|
||||
*/
|
||||
extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
|
||||
size_t * inbytesleft, char **outbuf,
|
||||
size_t * outbytesleft);
|
||||
size_t *inbytesleft, char **outbuf,
|
||||
size_t *outbytesleft);
|
||||
|
||||
/**
|
||||
* Helper function to convert a string's encoding in one call.
|
||||
|
@ -2928,6 +2984,10 @@ extern SDL_DECLSPEC size_t SDLCALL SDL_iconv(SDL_iconv_t cd, const char **inbuf,
|
|||
* \returns a new string, converted to the new encoding, or NULL on error.
|
||||
*
|
||||
* \since This function is available since SDL 3.0.0.
|
||||
*
|
||||
* \sa SDL_iconv_open
|
||||
* \sa SDL_iconv_close
|
||||
* \sa SDL_iconv
|
||||
*/
|
||||
extern SDL_DECLSPEC char * SDLCALL SDL_iconv_string(const char *tocode,
|
||||
const char *fromcode,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue