blob: 0a77e99170a1041a3f5f29b9b9a04b7dac414831 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
#include "utf8string.h"
#include <stfl.h>
#include <wctype.h>
#include "cxx.h"
#include "utils.h"
namespace newsboat {
Utf8String::Utf8String(const rust::String& input)
{
inner = std::string(input);
}
Utf8String::Utf8String(std::string input)
{
inner = std::move(input);
}
Utf8String Utf8String::from_utf8(std::string input)
{
return Utf8String(std::move(input));
}
Utf8String Utf8String::from_locale_charset(std::string input)
{
return Utf8String(utils::locale_to_utf8(std::move(input)));
}
std::string Utf8String::to_locale_charset() const
{
return utils::utf8_to_locale(inner);
}
Utf8String Utf8String::to_lowercase() const
{
struct stfl_ipool* ipool = stfl_ipool_create("UTF-8");
std::wstring widestr = stfl_ipool_towc(ipool, inner.c_str());
stfl_ipool_destroy(ipool);
std::transform(widestr.begin(),
widestr.end(),
widestr.begin(),
::towlower);
ipool = stfl_ipool_create("UTF-8");
const std::string result = stfl_ipool_fromwc(ipool, widestr.c_str());
stfl_ipool_destroy(ipool);
return Utf8String::from_utf8(result);
}
} // namespace newsboat
|