Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

charset.h
Go to the documentation of this file.
1 /*
2 * Character Set Handling
3 * (C) 1999-2007 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #ifndef BOTAN_CHARSET_H_
9 #define BOTAN_CHARSET_H_
10
11 #include <botan/types.h>
12 #include <string>
13
14 BOTAN_FUTURE_INTERNAL_HEADER(charset.h)
15
16 namespace Botan {
17
18 /**
19 * Convert a sequence of UCS-2 (big endian) characters to a UTF-8 string
20 * This is used for ASN.1 BMPString type
21 * @param ucs2 the sequence of UCS-2 characters
22 * @param len length of ucs2 in bytes, must be a multiple of 2
23 */
24 std::string BOTAN_UNSTABLE_API ucs2_to_utf8(const uint8_t ucs2[], size_t len);
25
26 /**
27 * Convert a sequence of UCS-4 (big endian) characters to a UTF-8 string
28 * This is used for ASN.1 UniversalString type
29 * @param ucs4 the sequence of UCS-4 characters
30 * @param len length of ucs4 in bytes, must be a multiple of 4
31 */
32 std::string BOTAN_UNSTABLE_API ucs4_to_utf8(const uint8_t ucs4[], size_t len);
33
34 /**
35 * Convert a UTF-8 string to Latin-1
36 * If a character outside the Latin-1 range is encountered, an exception is thrown.
37 */
38 std::string BOTAN_UNSTABLE_API utf8_to_latin1(const std::string& utf8);
39
40 /**
41 * The different charsets (nominally) supported by Botan.
42 */
43 enum Character_Set {
44 LOCAL_CHARSET,
45 UCS2_CHARSET,
46 UTF8_CHARSET,
47 LATIN1_CHARSET
48 };
49
50 namespace Charset {
51
52 /*
53 * Character set conversion - avoid this.
54 * For specific conversions, use the functions above like
55 * ucs2_to_utf8 and utf8_to_latin1
56 *
57 * If you need something more complex than that, use a real library
58 * such as iconv, Boost.Locale, or ICU
59 */
60 std::string BOTAN_PUBLIC_API(2,0)
61 BOTAN_DEPRECATED("Avoid. See comment in header.")
62 transcode(const std::string& str,
63 Character_Set to,
64 Character_Set from);
65
66 /*
67 * Simple character classifier functions
68 */
69 bool BOTAN_PUBLIC_API(2,0) is_digit(char c);
70 bool BOTAN_PUBLIC_API(2,0) is_space(char c);
71 bool BOTAN_PUBLIC_API(2,0) caseless_cmp(char x, char y);
72
73 uint8_t BOTAN_PUBLIC_API(2,0) char2digit(char c);
74 char BOTAN_PUBLIC_API(2,0) digit2char(uint8_t b);
75
76 }
77
78 }
79
80 #endif
BOTAN_UNSTABLE_API
#define BOTAN_UNSTABLE_API
Definition: compiler.h:38
Botan::Charset::transcode
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:185
Botan::UTF8_CHARSET
Definition: charset.h:46
Botan::ucs4_to_utf8
std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)
Definition: charset.cpp:78
Botan::Charset::char2digit
uint8_t char2digit(char c)
Definition: charset.cpp:231
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::utf8_to_latin1
std::string utf8_to_latin1(const std::string &utf8)
Definition: charset.cpp:98
Botan::ucs2_to_utf8
std::string ucs2_to_utf8(const uint8_t ucs2[], size_t len)
Definition: charset.cpp:61
Botan::Character_Set
Character_Set
Definition: charset.h:43
Botan::Charset::caseless_cmp
bool caseless_cmp(char a, char b)
Definition: charset.cpp:275
Botan::Charset::is_space
bool is_space(char c)
Definition: charset.cpp:221
Botan::LATIN1_CHARSET
Definition: charset.h:47
Botan
Definition: alg_id.cpp:13
Botan::LOCAL_CHARSET
Definition: charset.h:44
Botan::Charset::digit2char
char digit2char(uint8_t b)
Definition: charset.cpp:253
Botan::Charset::is_digit
bool is_digit(char c)
Definition: charset.cpp:210
Botan::UCS2_CHARSET
Definition: charset.h:45
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139