xref: /haiku/src/kits/locale/Format.cpp (revision cbe0a0c436162d78cc3f92a305b64918c839d079)
1 #include <Format.h>
2 
3 #include <new>
4 
5 #include <Autolock.h>
6 #include <Locale.h>
7 #include <LocaleRoster.h>
8 
9 
10 BFormat::BFormat(const BLocale* locale)
11 {
12 	if (locale == NULL)
13 		locale = BLocaleRoster::Default()->GetDefaultLocale();
14 
15 	if (locale == NULL) {
16 		fInitStatus = B_BAD_DATA;
17 		return;
18 	}
19 
20 	_Initialize(*locale);
21 }
22 
23 
24 BFormat::BFormat(const BLanguage& language,
25 	const BFormattingConventions& conventions)
26 {
27 	_Initialize(language, conventions);
28 }
29 
30 
31 BFormat::BFormat(const BFormat &other)
32 	:
33 	fConventions(other.fConventions),
34 	fLanguage(other.fLanguage),
35 	fInitStatus(other.fInitStatus)
36 {
37 }
38 
39 
40 BFormat::~BFormat()
41 {
42 }
43 
44 
45 status_t
46 BFormat::InitCheck() const
47 {
48 	return fInitStatus;
49 }
50 
51 
52 status_t
53 BFormat::_Initialize(const BLocale& locale)
54 {
55 	BFormattingConventions conventions;
56 	BLanguage language;
57 
58 	fInitStatus = locale.GetFormattingConventions(&conventions);
59 	if (fInitStatus != B_OK)
60 		return fInitStatus;
61 
62 	fInitStatus = locale.GetLanguage(&language);
63 	if (fInitStatus != B_OK)
64 		return fInitStatus;
65 
66 	return _Initialize(language, conventions);
67 }
68 
69 
70 status_t
71 BFormat::_Initialize(const BLanguage& language,
72 	const BFormattingConventions& conventions)
73 {
74 	fConventions = conventions;
75 	fLanguage = language;
76 	fInitStatus = B_OK;
77 	return fInitStatus;
78 }
79