tetengo 1.8.1
A multipurpose library set
Loading...
Searching...
No Matches
encoder.h File Reference

An encoder. More...

#include <stddef.h>
+ Include dependency graph for encoder.h:

Go to the source code of this file.

Typedefs

typedef enum tetengo_text_encoder_encoding_tag tetengo_text_encoder_encoding_t
 

Enumerations

enum  tetengo_text_encoder_encoding_tag { tetengo_text_encoder_encoding_utf8 , tetengo_text_encoder_encoding_utf16 , tetengo_text_encoder_encoding_cp932 }
 

Functions

const tetengo_text_encoder_t * tetengo_text_encoder_instance (tetengo_text_encoder_encoding_t encoding)
 Returns the encoder instance.
 
size_t tetengo_text_encoder_encode (const tetengo_text_encoder_t *p_encoder, const char *string, char *encoded_string, size_t encoded_string_capacity)
 Encodes a string.
 
size_t tetengo_text_encoder_decode (const tetengo_text_encoder_t *p_encoder, const char *encoded_string, char *string, size_t string_capacity)
 Decodes a string.
 

Detailed Description

An encoder.

Copyright (C) 2019-2023 kaoru https://www.tetengo.org/

Typedef Documentation

◆ tetengo_text_encoder_encoding_t

Enumeration Type Documentation

◆ tetengo_text_encoder_encoding_tag

Encoding type

Enumerator
tetengo_text_encoder_encoding_utf8 

UTF-8

tetengo_text_encoder_encoding_utf16 

UTF-16

tetengo_text_encoder_encoding_cp932 

CP932

Function Documentation

◆ tetengo_text_encoder_decode()

size_t tetengo_text_encoder_decode ( const tetengo_text_encoder_t *  p_encoder,
const char *  encoded_string,
char *  string,
size_t  string_capacity 
)

Decodes a string.

When decoding from UTF-16, cast unsigned short[] to char* for encoded_string.

Parameters
p_encoderA pointer to an encoder.
encoded_stringAn encoded string.
stringThe storage for a string. Can be NULL.
string_capacityThe capacity of string including a terminator '\0'.
Returns
The length of decoded string. Or 0 when p_encoder is NULL or string is NULL.

◆ tetengo_text_encoder_encode()

size_t tetengo_text_encoder_encode ( const tetengo_text_encoder_t *  p_encoder,
const char *  string,
char *  encoded_string,
size_t  encoded_string_capacity 
)

Encodes a string.

When encoding to UTF-16, cast unsigned short[] to char* for encoded_string and the unit of encoded_string_capacity and the return value is an unsigned short character.

Parameters
p_encoderA pointer to an encoder.
stringA string.
encoded_stringThe storage for an encoded string. Can be NULL.
encoded_string_capacityThe capacity of encoded_string including a terminator '\0'.
Returns
The length of encoded string. Or 0 when p_encoder is NULL or string is NULL.

◆ tetengo_text_encoder_instance()

const tetengo_text_encoder_t * tetengo_text_encoder_instance ( tetengo_text_encoder_encoding_t  encoding)

Returns the encoder instance.

Parameters
encodingAn encoding.
Returns
A pointer to the instance. Or NULL when encoding is invalid.