summaryrefslogtreecommitdiff
path: root/lib/dialer/Search/Result.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/dialer/Search/Result.cpp')
-rw-r--r--lib/dialer/Search/Result.cpp113
1 files changed, 113 insertions, 0 deletions
diff --git a/lib/dialer/Search/Result.cpp b/lib/dialer/Search/Result.cpp
new file mode 100644
index 0000000..60a565a
--- /dev/null
+++ b/lib/dialer/Search/Result.cpp
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2012-2013 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Search/Result.h"
+
+namespace Phone
+{
+ namespace Dialer
+ {
+ namespace Search
+ {
+ Result::Result()
+ : m_MatchType(ByNumber), m_MatchPos(0), m_MatchLength(0)
+ {
+ PH_TRACE;
+ }
+
+ Result::Result(const Result &result)
+ {
+ PH_TRACE;
+ *this = result;
+ }
+
+ Result::Result(const ContactPtr &contact, MatchType matchType,
+ size_t matchPos, size_t matchLength)
+ : m_Contact(contact), m_MatchType(matchType),
+ m_MatchPos(matchPos), m_MatchLength(matchLength)
+ {
+ PH_TRACE;
+ }
+
+ Result::MatchType Result::getMatchType() const
+ {
+ return m_MatchType;
+ }
+
+ const ContactPtr & Result::getContact() const
+ {
+ return m_Contact;
+ }
+
+ size_t Result::getMatchPos() const
+ {
+ return m_MatchPos;
+ }
+
+ size_t Result::getMatchLength() const
+ {
+ return m_MatchLength;
+ }
+
+ bool Result::formatMatch(std::string &formattedMatch,
+ const std::string &matchBegin,
+ const std::string &matchEnd) const
+ {
+ PH_TRACE;
+ const std::string *match = NULL;
+ if(m_MatchType == ByNumber)
+ {
+ match = &getContact()->getNumber();
+ }
+ else
+ {
+ match = &getContact()->getName();
+ }
+
+ if(match && match->length() >= m_MatchPos + m_MatchLength)
+ {
+ formattedMatch.clear();
+ if(m_MatchPos > 0)
+ {
+ formattedMatch.append(match->c_str(), m_MatchPos);
+ }
+
+ formattedMatch
+ .append(matchBegin)
+ .append(match->c_str() + m_MatchPos, m_MatchLength)
+ .append(matchEnd)
+ .append(match->c_str() + m_MatchPos + m_MatchLength);
+
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ Result & Result::operator=(const Result &result)
+ {
+ PH_TRACE;
+ m_MatchType = result.m_MatchType;
+ m_Contact = result.m_Contact;
+ m_MatchPos = result.m_MatchPos;
+ m_MatchLength = result.m_MatchLength;
+ return *this;
+ }
+ }
+ }
+}