2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file config_parser_data.cpp
18 * @author Lukasz Wrzosek (l.wrzosek@samsung.com)
23 #include <dpl/wrt-dao-ro/config_parser_data.h>
24 #include <dpl/log/wrt_log.h>
25 #include <libxml/xmlreader.h>
26 #include <libxml/xmlstring.h>
29 bool IsSpace(const xmlChar* str);
30 bool CopyChar(xmlChar* out, xmlChar* in);
32 bool IsSpace(const xmlChar* str)
34 int charlen = xmlUTF8Size(str);
66 unsigned char c2 = *(str + 1);
67 unsigned char c3 = *(str + 2);
68 if ((c2 == 0x9a && c3 == 0x80) || (c2 == 0xa0 && c3 == 0x8e)) {
98 if (*(str + 2) == 0x9f) {
108 if (*(str + 1) == 0x80 && *(str + 2) == 0x80) {
123 bool CopyChar(xmlChar* out,
126 int size = xmlUTF8Size(in);
147 //TODO temporary fix until commits the rewrite of this functionality.
148 void NormalizeString(DPL::String& str)
150 boost::optional<DPL::String> opt = str;
151 NormalizeString(opt);
155 void NormalizeString(boost::optional<DPL::String>& txt, bool isTrimSpace)
158 std::string tmp = DPL::ToUTF8String(*txt);
159 const xmlChar* str = reinterpret_cast<const xmlChar*>(tmp.c_str());
160 if (!xmlCheckUTF8(str)) {
161 WrtLogE("Not valid UTF8");
167 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
174 xmlChar* tmpnew = xmlUTF8Strndup(c, xmlUTF8Strlen(c) + 1);
175 if (tmpnew == NULL) {
176 WrtLogE("can't do xmlUTF*Strndup();");
182 while ((c = const_cast<xmlChar*>(xmlUTF8Strpos(str, i))) != NULL) {
190 if (first && !isTrimSpace) {
191 xmlChar space[6] = { 0x20 };
202 txt = DPL::FromUTF8String(reinterpret_cast<char*>(tmpnew));
207 void NormalizeAndTrimSpaceString(DPL::OptionalString& txt)
209 NormalizeString(txt, true);
212 #if ENABLE(ELEMENT_ATTR_MAX_LENGTH)
213 void NormalizeString(DPL::String& str, const unsigned int length,
214 #if ENABLE(ADD_ELLIPSIS)
217 bool /*showEllipsis*/
221 #if ENABLE(ADD_ELLIPSIS)
222 bool hasExceededMaxLength = false;
223 if (str.size() > length) {
224 hasExceededMaxLength = true;
228 if (str.size() > length) {
233 boost::optional<DPL::String> opt = str;
234 NormalizeString(opt);
236 #if ENABLE(ADD_ELLIPSIS)
237 if (showEllipsis && hasExceededMaxLength && (str.size() == length)) {
238 str = DPL::FromUTF8String(DPL::ToUTF8String(str).append("..."));
243 void NormalizeString(boost::optional<DPL::String>& str, const unsigned int length,
244 #if ENABLE(ADD_ELLIPSIS)
247 bool /*showEllipsis*/
251 #if ENABLE(ADD_ELLIPSIS)
252 bool hasExceededMaxLength = false;
254 if ((*str).size() > length) {
255 hasExceededMaxLength = true;
256 (*str).resize(length);
260 if ((*str).size() > length) {
261 (*str).resize(length);
265 NormalizeString(str);
266 #if ENABLE(ADD_ELLIPSIS)
267 if (showEllipsis && hasExceededMaxLength && ((*str).size() == length)) {
268 str = DPL::FromUTF8String(DPL::ToUTF8String(*str).append("..."));
274 void NormalizeAndTrimSpaceString(DPL::OptionalString& str, const unsigned int length)
277 if ((*str).size() > length) {
278 (*str).resize(length);
280 NormalizeString(str, true);
283 #endif //ELEMENT_ATTR_MAX_LENGTH
285 bool ConfigParserData::Feature::operator==(const Feature& other) const
287 return name == other.name;
290 bool ConfigParserData::Feature::operator!=(const Feature& other) const
292 return name != other.name;
295 bool ConfigParserData::Feature::operator >(const Feature& other) const
297 return name > other.name;
300 bool ConfigParserData::Feature::operator>=(const Feature& other) const
302 return name >= other.name;
305 bool ConfigParserData::Feature::operator <(const Feature& other) const
307 return name < other.name;
310 bool ConfigParserData::Feature::operator<=(const Feature& other) const
312 return name <= other.name;
315 bool ConfigParserData::Privilege::operator==(const Privilege& other) const
317 return name == other.name;
320 bool ConfigParserData::Privilege::operator!=(const Privilege& other) const
322 return name != other.name;
325 bool ConfigParserData::Privilege::operator >(const Privilege& other) const
327 return name > other.name;
330 bool ConfigParserData::Privilege::operator>=(const Privilege& other) const
332 return name >= other.name;
335 bool ConfigParserData::Privilege::operator <(const Privilege& other) const
337 return name < other.name;
340 bool ConfigParserData::Privilege::operator<=(const Privilege& other) const
342 return name <= other.name;
345 bool ConfigParserData::Icon::operator==(const Icon& other) const
347 return src == other.src && isSmall == other.isSmall;
350 bool ConfigParserData::Icon::operator!=(const Icon& other) const
352 return src != other.src || isSmall != other.isSmall;
355 bool ConfigParserData::Icon::operator >(const Icon& other) const
357 return src > other.src;
360 bool ConfigParserData::Icon::operator>=(const Icon& other) const
362 return operator >(other) || operator==(other);
365 bool ConfigParserData::Icon::operator <(const Icon& other) const
367 return src < other.src;
370 bool ConfigParserData::Icon::operator<=(const Icon& other) const
372 return operator<(other) || operator==(other);
375 bool ConfigParserData::Preference::operator==(const Preference& other) const
377 return name == other.name;
380 bool ConfigParserData::Preference::operator!=(const Preference& other) const
382 return name != other.name;
385 bool ConfigParserData::Preference::operator >(const Preference& other) const
387 return name > other.name;
390 bool ConfigParserData::Preference::operator>=(const Preference& other) const
392 return name >= other.name;
395 bool ConfigParserData::Preference::operator <(const Preference& other) const
397 return name < other.name;
400 bool ConfigParserData::Preference::operator<=(const Preference& other) const
402 return name <= other.name;
405 bool ConfigParserData::AccessInfo::operator== (const AccessInfo& info) const
407 return m_strIRI == info.m_strIRI && m_bSubDomainAccess ==
408 info.m_bSubDomainAccess;
411 bool ConfigParserData::AccessInfo::operator!= (const AccessInfo& info) const
413 return !(*this == info);
416 bool ConfigParserData::AccessInfo::operator <(const AccessInfo& info) const
418 if (m_strIRI == info.m_strIRI) {
419 return m_bSubDomainAccess < info.m_bSubDomainAccess;
421 return m_strIRI < info.m_strIRI;
425 bool ConfigParserData::Setting::operator==(const Setting& other) const
427 return m_name == other.m_name &&
428 m_value == other.m_value;
431 bool ConfigParserData::Setting::operator!=(const Setting& other) const
433 return !(*this == other);
436 bool ConfigParserData::Setting::operator >(const Setting& other) const
438 return m_name > other.m_name;
441 bool ConfigParserData::Setting::operator>=(const Setting& other) const
443 return m_name >= other.m_name;
446 bool ConfigParserData::Setting::operator <(const Setting& other) const
448 return m_name < other.m_name;
451 bool ConfigParserData::Setting::operator<=(const Setting& other) const
453 return m_name <= other.m_name;
456 bool ConfigParserData::AppControlInfo::operator== (const AppControlInfo& info) const
458 return m_src == info.m_src &&
459 m_operation == info.m_operation &&
460 m_uriList == info.m_uriList &&
461 m_mimeList == info.m_mimeList &&
462 m_reload == info.m_reload;
465 bool ConfigParserData::AppControlInfo::operator!= (const AppControlInfo& info) const
467 return !(*this == info);
470 #if USE(WEB_PROVIDER)
471 bool ConfigParserData::LiveboxInfo::operator==(const LiveboxInfo& other) const
473 return m_liveboxId == other.m_liveboxId &&
474 m_autoLaunch == other.m_autoLaunch &&
475 m_updatePeriod == other.m_updatePeriod &&
476 m_primary == other.m_primary &&
477 m_label == other.m_label &&
478 m_icon == other.m_icon;
481 bool ConfigParserData::LiveboxInfo::operator!=(const LiveboxInfo& other) const
483 return !(*this == other);
487 bool ConfigParserData::Metadata::operator== (const Metadata& other) const
489 return key == other.key && value == other.value;
492 bool ConfigParserData::Metadata::operator!= (const Metadata& other) const
494 return !(*this == other);