2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
18 TextSpan::TextSpan(const BString
& text
, const CharacterStyle
& style
)
21 fCharCount(text
.CountChars()),
27 TextSpan::TextSpan(const TextSpan
& other
)
30 fCharCount(other
.fCharCount
),
37 TextSpan::operator=(const TextSpan
& other
)
40 fCharCount
= other
.fCharCount
;
41 fStyle
= other
.fStyle
;
48 TextSpan::operator==(const TextSpan
& other
) const
50 return fCharCount
== other
.fCharCount
51 && fStyle
== other
.fStyle
52 && fText
== other
.fText
;
57 TextSpan::operator!=(const TextSpan
& other
) const
59 return !(*this == other
);
64 TextSpan::SetText(const BString
& text
)
67 fCharCount
= fText
.CountChars();
72 TextSpan::SetStyle(const CharacterStyle
& style
)
79 TextSpan::Append(const BString
& text
)
81 return Insert(fCharCount
, text
);
86 TextSpan::Insert(int32 offset
, const BString
& text
)
88 _TruncateInsert(offset
);
90 fText
.InsertChars(text
, offset
);
92 int32 charCount
= fText
.CountChars();
93 bool success
= charCount
> fCharCount
;
94 fCharCount
= charCount
;
101 TextSpan::Remove(int32 start
, int32 count
)
103 _TruncateRemove(start
, count
);
106 fText
.RemoveChars(start
, count
);
108 int32 charCount
= fText
.CountChars();
109 bool success
= charCount
< fCharCount
;
110 fCharCount
= charCount
;
119 TextSpan::SubSpan(int32 start
, int32 count
) const
121 _TruncateRemove(start
, count
);
125 fText
.CopyCharsInto(subString
, start
, count
);
127 return TextSpan(subString
, fStyle
);
131 // #pragma mark - private
135 TextSpan::_TruncateInsert(int32
& start
) const
140 if (start
>= fCharCount
)
146 TextSpan::_TruncateRemove(int32
& start
, int32
& count
) const
158 if (start
< fCharCount
) {
159 if (start
+ count
> fCharCount
)
160 count
= fCharCount
- start
;