Freeciv-3.2
Loading...
Searching...
No Matches
Macros | Functions | Variables
fciconv.c File Reference
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "fciconv.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "support.h"

Go to the source code of this file.

Macros

#define local_encoding   get_local_encoding()
 
#define data_encoding   get_local_encoding()
 
#define internal_encoding   get_local_encoding()
 
#define CONV_FUNC_MALLOC(src, dst)
 
#define CONV_FUNC_BUFFER(src, dst)
 
#define CONV_FUNC_STATIC(src, dst)
 

Functions

static charconvert_string (const char *text, const char *from, const char *to, char *buf, size_t bufsz) fc__attribute((nonnull(1
 
static char void init_character_encodings (const char *my_internal_encoding, bool my_use_transliteration)
 
const charget_data_encoding (void)
 
const charget_local_encoding (void)
 
const charget_internal_encoding (void)
 
static CONV_FUNC_STATIC (internal, local)
 
size_t get_internal_string_length (const char *text)
 
void fc_iconv_close (void)
 

Variables

static bool is_init = FALSE
 
static char convert_buffer [4096]
 
static const chartransliteration_string
 
static charsaved_from = NULL
 
static charsaved_to = NULL
 

Macro Definition Documentation

◆ CONV_FUNC_BUFFER

#define CONV_FUNC_BUFFER (   src,
  dst 
)
Value:
char *src ## _to_ ## dst ## _string_buffer(const char *text, \
char *buf, size_t bufsz) \
{ \
const char *encoding1 = (dst ## _encoding); \
return convert_string(text, (src ## _encoding), \
}
char * incite_cost
Definition comments.c:75
static const char * transliteration_string
Definition fciconv.c:44
static char * convert_string(const char *text, const char *from, const char *to, char *buf, size_t bufsz) fc__attribute((nonnull(1
Definition fciconv.c:196
static const int bufsz
Definition helpdlg.c:70

Definition at line 319 of file fciconv.c.

◆ CONV_FUNC_MALLOC

#define CONV_FUNC_MALLOC (   src,
  dst 
)
Value:
char *src ## _to_ ## dst ## _string_malloc(const char *text) \
{ \
const char *encoding1 = (dst ## _encoding); \
return convert_string(text, (src ## _encoding), \
(encoding), NULL, 0); \
}

Definition at line 307 of file fciconv.c.

◆ CONV_FUNC_STATIC

#define CONV_FUNC_STATIC (   src,
  dst 
)
Value:
char *src ## _to_ ## dst ## _string_static(const char *text) \
{ \
(src ## _to_ ## dst ## _string_buffer)(text, \
sizeof(convert_buffer)); \
return convert_buffer; \
}
static char convert_buffer[4096]
Definition fciconv.c:43

Definition at line 332 of file fciconv.c.

◆ data_encoding

#define data_encoding   get_local_encoding()

Definition at line 51 of file fciconv.c.

◆ internal_encoding

#define internal_encoding   get_local_encoding()

Definition at line 52 of file fciconv.c.

◆ local_encoding

#define local_encoding   get_local_encoding()

Definition at line 50 of file fciconv.c.

Function Documentation

◆ CONV_FUNC_STATIC()

static CONV_FUNC_STATIC ( internal  ,
local   
)
static

Definition at line 349 of file fciconv.c.

◆ convert_string()

static char * convert_string ( const char text,
const char from,
const char to,
char buf,
size_t  bufsz 
)
static

Convert the text. Both 'from' and 'to' must be 8-bit charsets. The result will be put into the buf buffer unless it is NULL, in which case it will be allocated on demand.

Don't use this function if you can avoid it. Use one of the xxx_to_yyy_string functions.

Definition at line 196 of file fciconv.c.

Referenced by get_internal_string_length().

◆ fc_iconv_close()

void fc_iconv_close ( void  )

Free resources allocated by the iconv system

Definition at line 417 of file fciconv.c.

Referenced by libfreeciv_free().

◆ get_data_encoding()

const char * get_data_encoding ( void  )

Return the data encoding (usually UTF-8).

Definition at line 151 of file fciconv.c.

◆ get_internal_encoding()

const char * get_internal_encoding ( void  )

Return the internal encoding. This depends on the server or GUI being used.

Definition at line 182 of file fciconv.c.

Referenced by client_main(), main(), and srv_init().

◆ get_internal_string_length()

size_t get_internal_string_length ( const char text)

Return the length, in characters, of the string. This can be used in place of strlen() in some places because it returns the number of characters not the number of bytes (with multi-byte characters in UTF-8, the two may not be the same).

Use of this function outside of GUI layout code is probably a hack. For instance the demographics code uses it, but this should instead pass the data directly to the GUI library for formatting.

Definition at line 395 of file fciconv.c.

Referenced by cmafec_get_result_descr(), dem_line_item(), helptext_extra(), insert_generated_text(), insert_veteran_help(), and report_demographics().

◆ get_local_encoding()

const char * get_local_encoding ( void  )

Return the local encoding (dependent on the system).

Definition at line 160 of file fciconv.c.

◆ init_character_encodings()

static char void init_character_encodings ( const char my_internal_encoding,
bool  my_use_transliteration 
)

Must be called during the initialization phase of server and client to initialize the character encodings to be used.

Pass an internal encoding of NULL to use the local encoding internally.

Definition at line 70 of file fciconv.c.

Referenced by client_main(), fcmp_init(), main(), and srv_init().

Variable Documentation

◆ convert_buffer

char convert_buffer[4096]
static

Definition at line 43 of file fciconv.c.

◆ is_init

bool is_init = FALSE
static

◆ saved_from

char* saved_from = NULL
static

Definition at line 55 of file fciconv.c.

Referenced by convert_string(), and fc_iconv_close().

◆ saved_to

char* saved_to = NULL
static

Definition at line 56 of file fciconv.c.

Referenced by convert_string(), and fc_iconv_close().

◆ transliteration_string

const char* transliteration_string
static

Definition at line 44 of file fciconv.c.

Referenced by init_character_encodings().