Spannable-Core: Add SpannableString and ForegroundColorSpan
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / string-text / range-impl.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/text/string-text/range-impl.h>
20
21 namespace Dali
22 {
23 namespace Toolkit
24 {
25 namespace Text
26 {
27 namespace Internal
28 {
29 struct Range::Impl
30 {
31   u_int32_t mStartIndex; /// The start index of range
32   u_int32_t mEndIndex;   /// The end index of range
33 };
34
35 Dali::Toolkit::Text::Range Range::New(u_int32_t startIndex, u_int32_t endIndex)
36 {
37   RangePtr object = new Range(startIndex, endIndex);
38
39   Dali::Toolkit::Text::Range handle = Dali::Toolkit::Text::Range(object.Get());
40
41   return handle;
42 }
43
44 Range::Range(u_int32_t startIndex, u_int32_t endIndex)
45 {
46   mImpl = std::make_unique<Impl>();
47
48   mImpl->mStartIndex = startIndex <= endIndex ? startIndex : endIndex;
49   mImpl->mEndIndex   = startIndex >= endIndex ? startIndex : endIndex;
50 }
51
52 Range::~Range()
53 {
54 }
55
56 u_int32_t Range::GetStartIndex() const
57 {
58   return mImpl->mStartIndex;
59 }
60
61 u_int32_t Range::GetEndIndex() const
62 {
63   return mImpl->mEndIndex;
64 }
65
66 u_int32_t Range::GetNumberOfIndices() const
67 {
68   return 1u + ((mImpl->mStartIndex <= mImpl->mEndIndex) ? (mImpl->mEndIndex - mImpl->mStartIndex) : (mImpl->mStartIndex - mImpl->mEndIndex));
69 }
70
71 } // namespace Internal
72
73 } // namespace Text
74
75 } // namespace Toolkit
76
77 } // namespace Dali