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
56
57
|
#include <glibmm.h>
#include <iomanip>
#include <iostream>
int
main(int, char**)
{
// Don't use the user's preferred locale. The decimal delimiter may be ','
// instead of the expected '.'.
Glib::set_init_to_users_preferred_locale(false);
Glib::init();
char carr[10] = "UÅūduotys";
char* const cptr = carr;
/*
std::wostringstream wsout;
wsout << carr;
const std::wstring& wstr = wsout.str();
const gunichar * const data = reinterpret_cast<const gunichar *>(
wstr.data());
for(int i = 0; wstr.size() > i; ++i)
std::cout << data[i] << std::endl;
*/
// Check both the const char* and char* versions.
Glib::ustring::format(carr);
// This threw an exception before we added a ustring::FormatStream::stream(char*) overload.
Glib::ustring::format(cptr);
// Test substitution of various types and I/O manipulators
Glib::ustring expected("The meaning of life is 42, or with 2 decimal places, 42.00.");
auto the = "The";
std::string meaning("meaning");
Glib::ustring life("life");
auto number = 42.0;
auto places = 2;
auto actual = Glib::ustring::format(the, ' ', meaning, " of ", life, " is ",
number,
", or with ", places, " decimal places, ",
std::fixed, std::setprecision(places), number,
'.');
if (actual != expected)
{
std::cerr << "expected (" << expected.size() << "):\n" << expected << "\n\n"
<< "actual (" << actual .size() << "):\n" << actual << "\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
|