Botan 2.19.1
Crypto and TLS for C&
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
15
16namespace 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*/
24std::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*/
32std::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*/
38std::string BOTAN_UNSTABLE_API utf8_to_latin1(const std::string& utf8);
39
40/**
41* The different charsets (nominally) supported by Botan.
42*/
48};
49
50namespace 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*/
60std::string BOTAN_PUBLIC_API(2,0)
61 BOTAN_DEPRECATED("Avoid. See comment in header.")
62 transcode(const std::string& str,
64 Character_Set from);
65
66/*
67* Simple character classifier functions
68*/
69bool BOTAN_PUBLIC_API(2,0) is_digit(char c);
70bool BOTAN_PUBLIC_API(2,0) is_space(char c);
71bool BOTAN_PUBLIC_API(2,0) caseless_cmp(char x, char y);
72
73uint8_t BOTAN_PUBLIC_API(2,0) char2digit(char c);
74char BOTAN_PUBLIC_API(2,0) digit2char(uint8_t b);
75
76}
77
78}
79
80#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:136
#define BOTAN_UNSTABLE_API
Definition: compiler.h:44
bool is_digit(char c)
Definition: charset.cpp:210
std::string transcode(const std::string &str, Character_Set to, Character_Set from)
Definition: charset.cpp:185
bool is_space(char c)
Definition: charset.cpp:221
bool caseless_cmp(char a, char b)
Definition: charset.cpp:275
uint8_t char2digit(char c)
Definition: charset.cpp:231
char digit2char(uint8_t b)
Definition: charset.cpp:253
Definition: alg_id.cpp:13
std::string ucs4_to_utf8(const uint8_t ucs4[], size_t len)
Definition: charset.cpp:78
std::string ucs2_to_utf8(const uint8_t ucs2[], size_t len)
Definition: charset.cpp:61
Character_Set
Definition: charset.h:43
@ UCS2_CHARSET
Definition: charset.h:45
@ LOCAL_CHARSET
Definition: charset.h:44
@ LATIN1_CHARSET
Definition: charset.h:47
@ UTF8_CHARSET
Definition: charset.h:46
std::string utf8_to_latin1(const std::string &utf8)
Definition: charset.cpp:98