Freeciv21
Develop your civilization from humble roots to a global empire
fciconv.h
Go to the documentation of this file.
1 /**************************************************************************
2  ____ Copyright (c) 1996-2020 Freeciv21 and Freeciv
3  / \__ contributors. This file is part of Freeciv21.
4 |\ / @ \ Freeciv21 is free software: you can redistribute it
5 \ \_______| \ .:|> and/or modify it under the terms of the GNU
6  \ ##| | \__/ General Public License as published by the Free
7  | ####\__/ \ Software Foundation, either version 3 of the License,
8  / / ## \| or (at your option) any later version.
9  / /__________\ \ You should have received a copy of the
10  L_JJ \__JJ GNU General Public License along with Freeciv21.
11  If not, see https://www.gnu.org/licenses/.
12 **************************************************************************/
13 #pragma once
14 
15 #include "support.h"
16 
17 #include <stdio.h>
18 
19 /*
20  Technical details:
21 
22  - There are three encodings used by freeciv: the data encoding, the
23  internal encoding, and the local encoding. Each is a character set
24  (like utf-8 or latin1). Each string in the code must be in one of these
25  three encodings; to cut down on bugs always document whenever you have
26  a string in anything other than the internal encoding and never make
27  global variables hold anything other than the internal encoding; the
28  local and data encodings should only be used locally within the code
29  and always documented as such.
30 
31  - The data_encoding is used in all data files and network transactions.
32  This is always UTF-8.
33 
34  - The internal_encoding is used internally within freeciv. This is always
35  UTF-8.
36 
37  - The local_encoding is the one supported on the command line, which is
38  generally the value listed in the $LANG environment variable. This is
39  not under freeciv control; all output to the command line must be
40  converted or it will not display correctly.
41 
42  Practical details:
43 
44  - Translation files are not controlled by freeciv iconv. The .po files
45  can be in any character set, as set at the top of the file.
46 
47  - All translatable texts should be American English ASCII. In the past,
48  gettext documentation has always said to stick to ASCII for the gettext
49  input (pre-translated texts) and rely on translations to supply the
50  needed non-ASCII characters.
51 
52  - All other texts, including rulesets, nations, and code files must be in
53  UTF-8 (ASCII is a subset of UTF-8, and is fine for use here).
54 
55  - The server uses UTF-8 for everything; UTF-8 is the server's "internal
56  encoding".
57 
58  - Everything sent over the network is always in UTF-8.
59 
60  - Everything in the client is also in UTF-8.
61 
62  - Everything printed to the command line must be converted into the
63  "local encoding" which may be anything as defined by the system. Using
64  fc_fprintf is generally the easiest way to print to the command line
65  in which case all strings passed to it should be in the internal
66  encoding.
67 */
68 
69 #define FC_DEFAULT_DATA_ENCODING "UTF-8"
70 
72  bool use_transliteration);
73 
74 const char *get_internal_encoding();
75 
76 char *data_to_internal_string_malloc(const char *text);
77 char *internal_to_data_string_malloc(const char *text);
78 char *internal_to_local_string_malloc(const char *text);
79 char *local_to_internal_string_malloc(const char *text);
80 
81 char *local_to_internal_string_buffer(const char *text, char *buf,
82  size_t bufsz);
83 
84 #define fc_printf(...) fc_fprintf(stdout, __VA_ARGS__)
85 void fc_fprintf(FILE *stream, const char *format, ...)
86  fc__attribute((__format__(__printf__, 2, 3)));
87 
88 size_t get_internal_string_length(const char *text);
static const char * internal_encoding
Definition: fciconv.cpp:31
char * internal_to_data_string_malloc(const char *text)
Definition: fciconv.cpp:99
void size_t get_internal_string_length(const char *text)
Return the length, in characters, of the string.
Definition: fciconv.cpp:153
char * local_to_internal_string_malloc(const char *text)
Definition: fciconv.cpp:113
void init_character_encodings(const char *internal_encoding, bool use_transliteration)
Must be called during the initialization phase of server and client to initialize the character encod...
Definition: fciconv.cpp:39
char * local_to_internal_string_buffer(const char *text, char *buf, size_t bufsz)
Definition: fciconv.cpp:120
char * internal_to_local_string_malloc(const char *text)
Definition: fciconv.cpp:106
const char * get_internal_encoding()
Return the internal encoding.
Definition: fciconv.cpp:90
void fc_fprintf(FILE *stream, const char *format,...) fc__attribute((__format__(__printf__
char * data_to_internal_string_malloc(const char *text)
Definition: fciconv.cpp:92
int fc__attribute((nonnull(1, 3)))