35 #include <boost/algorithm/string.hpp>
44 string translated_text;
45 string translated_value;
46 size_t offset = m_text.find_first_of(
"role:");
47 if (offset == string::npos)
49 (
int)m_lineno, m_fname.c_str());
50 const char *ptr = m_text.c_str() + offset + 5;
52 while (*ptr && isspace(*ptr))
55 const char *base = ptr;
56 if (*ptr == 0 || !isalpha(*ptr))
58 (
int)m_lineno, m_fname.c_str());
59 while (*ptr && (isalnum(*ptr) || *ptr ==
'_'))
62 string name(base, ptr-base);
64 if (name.compare(
"all") == 0)
66 (
int)m_lineno, m_fname.c_str());
68 if (*ptr == 0 || !isspace(*ptr))
70 "Invalid role specification for '%s' on line %d of '%s'",
71 name.c_str(), (int)m_lineno, m_fname.c_str());
73 while (*ptr && isspace(*ptr))
78 if (base == 0 && *ptr ==
'-') {
79 translated_value.append(1, *ptr);
81 else if (isalnum(*ptr) || *ptr ==
'_' || *ptr ==
'-' || *ptr ==
'.') {
85 else if (isspace(*ptr) || *ptr ==
'+' ||
86 *ptr ==
',' || *ptr ==
'(' || *ptr ==
')') {
88 string name(base, ptr-base);
89 if (context.
roles.count(name) > 0) {
90 translated_value.append(
"${ROLE_");
91 translated_value.append(name);
92 translated_value.append(
"}");
95 translated_value.append(name);
99 if (!isspace(translated_value[translated_value.length()-1]))
100 translated_value.append(1,
' ');
103 translated_value.append(1, *ptr);
105 else if (*ptr ==
'[' || *ptr ==
']') {
107 translated_value.append(base, ptr-base);
110 translated_value.append(1, *ptr);
114 "definition on line %d of '%s'",
115 *ptr, (
int)m_lineno, m_fname.c_str());
119 boost::trim_right_if(translated_value, boost::is_any_of(
" \t\n\r"));
121 translated_text.append(
"ROLE_");
122 translated_text.append(name);
123 translated_text.append(
"=\"");
124 translated_text.append(translated_value);
125 translated_text.append(
"\"\n");
127 context.
roles.insert(name);
128 context.
symbols[
"ROLE_"+name] = translated_value;
130 return translated_text;
const string translate(TranslationContext &context) override
Translates a role definition.
set< string > roles
Set of role names.
Declarations for TranslatorRole.
Logging routines and macros.
Compatibility Macros for C/C++.
map< string, string > symbols
Map of variable names to default values.
#define HT_THROWF(_code_, _fmt_,...)
A String class based on std::string.
Context used to translate cluster definition statements.
Cluster definition file translation definitions.
Error codes, Exception handling, error logging.