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