5
5
6
6
namespace translator
7
7
{
8
+ char capitalize (char c);
9
+
10
+ wchar_t capitalize (wchar_t c);
11
+
12
+ template <typename string_t >
13
+ const string_t capitalize_string (const string_t & st)
14
+ {
15
+ string_t copy = st;
16
+ copy[0 ] = capitalize (copy[0 ]);
17
+ return copy;
18
+ }
19
+
8
20
template <typename Language>
9
21
const rule<Language>& get_random_rule (std::default_random_engine& device, typename Language::word_type wt = Language::Sentence)
10
22
{
@@ -144,23 +156,24 @@ namespace translator
144
156
}
145
157
}
146
158
147
- string_t ToString () const
159
+ string_t ToString (bool first_word= false ) const
148
160
{
149
161
switch (t)
150
162
{
151
163
case RNode::string:
152
- return st;
164
+ return first_word ? capitalize_string (st) : st;
153
165
case RNode::word:
154
166
{
155
167
const word_form<Language>& w = p_dw->find_word_form (am);
156
- return w.word ;
168
+ return first_word || Language::should_capitalize (w) ? capitalize_string (w. word ) : w.word ;
157
169
}
158
170
case RNode::node:
159
171
{
160
172
string_t stSum;
161
173
for (auto &child : children)
162
174
{
163
- stSum += child.ToString ();
175
+ stSum += child.ToString (first_word);
176
+ first_word = false ;
164
177
stSum += string_t::value_type (' ' );
165
178
}
166
179
return stSum.substr (0 , stSum.size () - 1 );
@@ -184,6 +197,6 @@ namespace translator
184
197
185
198
RNode<Language> node (r, device);
186
199
node.consolidate_attributes (device);
187
- return node.ToString ();
200
+ return node.ToString (true );
188
201
}
189
202
}
0 commit comments