11#if __DCL_HAVE_ALLOC_DEBUG
12#undef __DCL_ALLOC_LEVEL
13#define __DCL_ALLOC_LEVEL __DCL_ALLOC_INTERNAL
43#define TEXT_LIST() ((TextList*)__textList)
44#define SUB_TEMPLATE_MAP() ((SubTemplateMap*)__subTemplateMap)
48TextTemplate::~TextTemplate()
54TextTemplate::TextTemplate()
57 __showEmptyName =
false;
66 __showEmptyName =
false;
74TextTemplate::TextTemplate(
const String& _text)
77 __showEmptyName =
false;
89 __showEmptyName = _src.__showEmptyName;
95 SubTemplateMap::ConstIterator it = srcMap.
begin();
96 for (; it != srcMap.
end(); it++) {
103void TextTemplate::parse(
const String& _text)
106 parse(_text.data(), _text.data() + _text.length());
110void TextTemplate::parse(
const String& _name,
const String& _text)
119 __DCL_TRACE1(L
"Warning - exist %ls ==> replaced\n", _name.data());
126void TextTemplate::clear()
131 (*itMap).value.clear();
136void TextTemplate::reset()
138 TextList::Iterator itList =
TEXT_LIST()->begin();
139 for( ; itList !=
TEXT_LIST()->end(); itList++)
141 if (!(*itList).name.isEmpty())
146 (*itList).values.clear();
153 (*itMap).value.reset();
156void TextTemplate::erase(
const char_t* _name)
160 TextList::Iterator it =
TEXT_LIST()->begin();
163 if ((*it).name == _name)
171 TextList::Iterator it =
TEXT_LIST()->begin();
174 if (!(*it).name.isEmpty())
182int TextTemplate::append(
const char_t* _name,
183 const String& _value,
bool _clearExists)
186 TextList::Iterator it =
TEXT_LIST()->begin();
191 if ((*it).name == _name)
193 if (_clearExists && !(*it).values.isEmpty())
194 (*it).values.clear();
196 (*it).values.addTail(_value);
205 if (!(*it).name.isEmpty())
207 if (_clearExists && !(*it).values.isEmpty())
208 (*it).values.clear();
210 (*it).values.addTail(_value);
218int TextTemplate::append(
const char_t* _name,
219 const TextTemplate& _template,
bool _clearExists)
225 TextList::Iterator it =
TEXT_LIST()->begin();
228 if ((*it).name == _name)
230 if (_clearExists && !(*it).values.isEmpty())
231 (*it).values.clear();
233 TextList::ConstIterator itSrc =
237 if (!(*itSrc).values.isEmpty())
241 (*itSrc).values.begin(),
242 (*itSrc).values.end()
249 if (_template.__showEmptyName)
251 String name = L
'$' + (*itSrc).name;
252 (*it).values.addTail(name);
263int TextTemplate::append(
const StringStringArray& _nameToValues,
267 for(
size_t i = 0; i < _nameToValues.size(); i++)
268 nCount += append(_nameToValues[i].key, _nameToValues[i].value, _clearExists);
273 const String& _fieldIsNullValue,
bool _clearExists)
276 for(
size_t i = 0; i < _fields.count(); i++)
289 const String& _fieldIsNullValue)
291 if (_field.isNull() || _field.dataSize() == 0)
292 return _fieldIsNullValue;
294 return _field.asString();
298void TextTemplate::showEmptyName(
bool _show,
bool _withSubTemplate)
300 __showEmptyName = _show;
301 if (_withSubTemplate)
305 (*itMap).value.showEmptyName(_show, _withSubTemplate);
311void TextTemplate::printTo(
Writer& out)
const
314 TextList::Iterator itList =
TEXT_LIST()->begin();
315 for(; itList !=
TEXT_LIST()->end(); itList++)
317 if (!(*itList).values.isEmpty())
319 StringList::Iterator itValues = (*itList).values.begin();
320 for(; itValues != (*itList).values.end(); itValues++)
330 out << L
"$" << (*itList).name;
337TextTemplate& TextTemplate::operator [] (
const String& _name)
342TextTemplate* TextTemplate::atP(
const String& _name)
const
346 return &((*itMap).value);
351bool TextTemplate::exists(
362 TextList::ConstIterator itList = pList->
begin();
363 for (; itList != pList->
end(); itList++) {
364 if ((*itList).name == _name) {
377 while(_begin < _end && re.
search(_begin, _end, results)) {
378 if (results[0].matched && results[0].first < results[0].second) {
380 if (_begin < results[0].first) {
381 String text(_begin, results[0].first);
383 node.
values.addTail(text);
388 String name(results[0].first + 1, results[0].second);
393 _begin = results[0].second;
399 String text(_begin, _end);
401 node.
values.addTail(text);
412static String __getName(
const char_t* _begin,
const char_t* _end)
414 const char_t* begin = _begin + 4;
415 while(begin < _end && *begin++ !=
__T(
'$'))
418 const char_t* end = begin;
419 while(end < _end && iswalnum(*end) || *end ==
__T(
'_'))
422 String
r(begin, end);
431 __T(
"<!--[\t\v\f ]*\\$[a-zA-Z0-9_]+[\t\v\f ]*-->[\t\v\f \r\n]*")
435 while (_begin < _end && reBegin.
search(_begin, _end, matchBegin)) {
439 String _name = __getName(matchBegin[0].first, matchBegin[0].second);
440 String strEndPattern =
441 __T(
"<!--[\t\v\f ]*/[\t\v\f ]*\\$")
443 +
__T(
"[\t\v\f ]*-->[\t\v\f \r\n]*");
445 Regex reEnd(strEndPattern);
448 if (reEnd.
search(matchBegin[0].second, _end, matchEnd)) {
450 if (_begin < matchBegin[0].first) {
461 __T(
"Warning - exists %ls ==> replaced\n"),
474 if (matchBegin[0].second < matchEnd[0].first) {
475 sub.parse(matchBegin[0].second, matchEnd[0].first);
478 _begin = matchEnd[0].second;
482 _begin = matchBegin[0].second;
#define __DCL_TRACE1(fmt, arg1)
#define __DCL_ASSERT(expr)
#define IMPLEMENT_CLASSINFO(class_name, base_class_name)
void CharsetConvertException *__fields clear()
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)