2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file ContactUtility.cpp
20 * @author Kisub Song (kisubs.song@samsung.com)
25 #include "ContactUtility.h"
31 #include <Commons/Exception.h>
32 #include <Commons/Regex.h>
38 using namespace WrtDeviceApis::Commons;
40 ContactUtility::ContactUtility()
44 ContactUtility::~ContactUtility()
48 bool ContactUtility::strToBool(const char *str)
55 if (boolStr == "true" || boolStr == "TRUE")
61 int ContactUtility::strToInt(const char* str)
68 istringstream iss(str);
74 int ContactUtility::strToInt(const string &str)
78 istringstream iss(str);
84 string ContactUtility::intToStr(const int value)
91 int ContactUtility::toDateDbInt(const tm &date)
93 return strToInt(toDateDbStr(date));
96 string ContactUtility::toDateDbStr(const tm &date)
99 ss << setfill('0') << setiosflags(ios::right) << setw(4) << (date.tm_year + 1900);
100 ss << setfill('0') << setiosflags(ios::right) << setw(2) << (date.tm_mon + 1);
101 ss << setfill('0') << setiosflags(ios::right) << setw(2) << date.tm_mday;
106 tm ContactUtility::toDateTmFromDateDbInt(int arg)
109 memset(&date, 0, sizeof(tm));
112 ThrowMsg(InvalidArgumentException, "Invalid Date type");
115 int section0to3 = arg / 10000;
116 int section4to5 = (arg / 100) % 100;
117 int section6to7 = arg % 100;
119 date.tm_year = section0to3 - 1900;
120 date.tm_mon = section4to5 - 1;
121 date.tm_mday = section6to7;
126 tm ContactUtility::toDateTmFromDateDbStr(const char* arg)
129 ThrowMsg(InvalidArgumentException, "Invalid Date type");
133 stringstream ss(arg);
136 return toDateTmFromDateDbInt(dateDb);
139 string ContactUtility::convertUriToPath(const string str)
143 std::string schema ("file://");
144 unsigned found = str.find(schema);
145 if(found != std::string::npos)
146 result = str.substr(schema.size());
153 string ContactUtility::convertPathToUri(const string str)
157 std::string schema ("file://");
158 unsigned found = str.find(schema);
159 if(found != std::string::npos)
162 result = schema + str;
167 bool ContactUtility::checkStrIsInt(const std::string &str)
169 return validate("^[\\-]?[0-9]+$", str, VALIDATE_MATCH_CASELESS);
172 bool ContactUtility::checkStrIsUInt(const std::string &str)
174 return validate("^[0-9]+$", str, VALIDATE_MATCH_CASELESS);