rds2cpp
Read and write RDS/RDA files in C++
Loading...
Searching...
No Matches
StringEncoding.hpp
Go to the documentation of this file.
1#ifndef RDS2CPP_STRING_ENCODING_HPP
2#define RDS2CPP_STRING_ENCODING_HPP
3
4#include <string>
5
12namespace rds2cpp {
13
17enum class StringEncoding : unsigned char {
18 NONE,
19 LATIN1,
20 UTF8,
21 ASCII
22};
23
27// The name is based on the names in ?Encoding... kinda hard to see if this is valid.
28inline StringEncoding string_encoding_from_name(const std::string& name) {
29 if (name == "UTF-8") {
30 return StringEncoding::UTF8;
31 } else if (name == "latin1") {
32 return StringEncoding::LATIN1;
33 } else if (name == "bytes") {
34 return StringEncoding::NONE;
35 } else { // be more permissive if it's none of the above, rather than forcing it to be 'unknown'.
36 return StringEncoding::ASCII;
37 }
38}
39
40inline std::string string_encoding_to_name(StringEncoding encoding) {
41 std::string name;
42 switch (encoding) {
43 case rds2cpp::StringEncoding::NONE: name = "bytes"; break;
44 case rds2cpp::StringEncoding::UTF8: name = "UTF-8"; break;
45 case rds2cpp::StringEncoding::ASCII: name = "unknown"; break;
46 case rds2cpp::StringEncoding::LATIN1: name = "latin1"; break;
47 }
48 return name;
49}
54}
55
56#endif
Parse an RDS file in C++.
Definition StringEncoding.hpp:12
StringEncoding
Definition StringEncoding.hpp:17