11#if __DCL_HAVE_ALLOC_DEBUG
12#undef __DCL_ALLOC_LEVEL
13#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
26#if __DCL_HAVE_THIS_FILE__
42#define TEXT_LIST() ((TextList*)__textList)
43#define SUB_TEMPLATE_MAP() ((SubTemplateMap*)__subTemplateMap)
47TextTemplate::~TextTemplate()
53TextTemplate::TextTemplate()
56 __showEmptyName =
false;
65 __showEmptyName =
false;
73TextTemplate::TextTemplate(
const String& _text)
76 __showEmptyName =
false;
88 __showEmptyName = _src.__showEmptyName;
94 SubTemplateMap::ConstIterator it = srcMap.
begin();
95 for (; it != srcMap.
end(); it++) {
102void TextTemplate::parse(
const String& _text)
105 parse(_text.data(), _text.data() + _text.length());
109void TextTemplate::parse(
const String& _name,
const String& _text)
118 __DCL_TRACE1(L
"Warning - exist %ls ==> replaced\n", _name.data());
125void TextTemplate::clear()
130 (*itMap).value.clear();
135void TextTemplate::reset()
137 TextList::Iterator itList =
TEXT_LIST()->begin();
138 for( ; itList !=
TEXT_LIST()->end(); itList++) {
139 if (!(*itList).name.isEmpty()) {
143 (*itList).values.clear();
150 (*itMap).value.reset();
153void TextTemplate::erase(
const char_t* _name)
156 TextList::Iterator it =
TEXT_LIST()->begin();
158 if ((*it).name == _name)
165 TextList::Iterator it =
TEXT_LIST()->begin();
167 if (!(*it).name.isEmpty())
175int TextTemplate::append(
177 const String& _value,
bool _clearExists
181 TextList::Iterator it =
TEXT_LIST()->begin();
184 if ((*it).name == _name) {
185 if (_clearExists && !(*it).values.isEmpty())
186 (*it).values.clear();
188 (*it).values.addTail(_value);
195 if (!(*it).name.isEmpty()) {
196 if (_clearExists && !(*it).values.isEmpty())
197 (*it).values.clear();
199 (*it).values.addTail(_value);
207int TextTemplate::append(
209 const TextTemplate& _template,
bool _clearExists
217 for(TextList::Iterator it =
TEXT_LIST()->begin();
220 if ((*it).name == _name) {
221 if (_clearExists && !(*it).values.isEmpty())
222 (*it).values.clear();
224 for(TextList::ConstIterator itSrc =
228 if (!(*itSrc).values.isEmpty()) {
231 (*itSrc).values.begin(),
232 (*itSrc).values.end()
238 if (_template.__showEmptyName) {
239 String name = L
'$' + (*itSrc).name;
240 (*it).values.addTail(name);
251int TextTemplate::append(
const StringStringArray& _nameToValues,
255 for(
size_t i = 0; i < _nameToValues.size(); i++)
256 nCount += append(_nameToValues[i].key, _nameToValues[i].value, _clearExists);
261 const String& _fieldIsNullValue,
bool _clearExists)
264 for(
size_t i = 0; i < _fields.count(); i++) {
276 const String& _fieldIsNullValue)
278 if (_field.isNull() || _field.dataSize() == 0)
279 return _fieldIsNullValue;
281 return _field.asString();
285void TextTemplate::showEmptyName(
bool _show,
bool _withSubTemplate)
287 __showEmptyName = _show;
288 if (_withSubTemplate) {
291 (*itMap).value.showEmptyName(_show, _withSubTemplate);
297void TextTemplate::printTo(
Writer& out)
const
300 for(TextList::Iterator itList =
TEXT_LIST()->begin();
303 if (!(*itList).values.isEmpty()) {
304 StringList::Iterator itValues = (*itList).values.begin();
305 for(; itValues != (*itList).values.end(); itValues++)
311 if (__showEmptyName) {
313 out << L
"$" << (*itList).name;
320TextTemplate& TextTemplate::operator [] (
const String& _name)
325TextTemplate* TextTemplate::atP(
const String& _name)
const
329 return &((*itMap).value);
334bool TextTemplate::exists(
345 TextList::ConstIterator itList = pList->
begin();
346 for (; itList != pList->
end(); itList++) {
347 if ((*itList).name == _name) {
360 while(_begin < _end && re.
search(_begin, _end, results)) {
361 if (results[0].matched && results[0].first < results[0].second) {
363 if (_begin < results[0].first) {
364 String text(_begin, results[0].first);
366 node.
values.addTail(text);
371 String name(results[0].first + 1, results[0].second);
376 _begin = results[0].second;
382 String text(_begin, _end);
384 node.
values.addTail(text);
395static String __getName(
const char_t* _begin,
const char_t* _end)
397 const char_t* begin = _begin + 4;
398 while(begin < _end && *begin++ !=
__T(
'$'))
401 const char_t* end = begin;
402 while(end < _end && (iswalnum(*end) || *end ==
__T(
'_')))
405 String
r(begin, end);
414 __T(
"<!--[\t\v\f ]*\\$[a-zA-Z0-9_]+[\t\v\f ]*-->[\t\v\f \r\n]*")
418 while (_begin < _end && reBegin.
search(_begin, _end, matchBegin)) {
422 String _name = __getName(matchBegin[0].first, matchBegin[0].second);
423 String strEndPattern =
424 __T(
"<!--[\t\v\f ]*/[\t\v\f ]*\\$")
426 +
__T(
"[\t\v\f ]*-->[\t\v\f \r\n]*");
428 Regex reEnd(strEndPattern);
431 if (reEnd.
search(matchBegin[0].second, _end, matchEnd)) {
433 if (_begin < matchBegin[0].first) {
444 __T(
"Warning - exists %ls ==> replaced\n"),
457 if (matchBegin[0].second < matchEnd[0].first) {
458 sub.parse(matchBegin[0].second, matchEnd[0].first);
461 _begin = matchEnd[0].second;
465 _begin = matchBegin[0].second;
#define __DCL_TRACE1(fmt, arg1)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
HashMap< String, TextTemplate > SubTemplateMap
List< TextNode > TextList
#define SUB_TEMPLATE_MAP()
ConstIterator begin() const
ConstIterator end() const
ConstIterator end() const
ConstIterator begin() const
bool search(const wchar_t *_begin, const wchar_t *_end, unsigned int _flags=0) __DCL_THROWS1(RegexException *)
virtual String onSQLFieldValue(_CONST SQLField &_field, const String &_fieldIsNullValue)
void parseHelper(const char_t *_begin, const char_t *_end)