1 /* 2 * Copyright 2013, Stephan Aßmus <superstippi@gmx.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef TEXT_SPAN_H 6 #define TEXT_SPAN_H 7 8 9 #include <String.h> 10 11 #include "CharacterStyle.h" 12 13 14 class TextSpan { 15 public: 16 TextSpan(); 17 TextSpan(const BString& text, 18 const CharacterStyle& style); 19 TextSpan(const TextSpan& other); 20 21 TextSpan& operator=(const TextSpan& other); 22 bool operator==(const TextSpan& other) const; 23 bool operator!=(const TextSpan& other) const; 24 25 void SetText(const BString& text); 26 inline const BString& Text() const 27 { return fText; } 28 29 void SetStyle(const CharacterStyle& style); 30 inline const CharacterStyle& Style() const 31 { return fStyle; } 32 33 inline int32 CountChars() const 34 { return fCharCount; } 35 36 bool Append(const BString& text); 37 bool Insert(int32 offset, const BString& text); 38 bool Remove(int32 start, int32 count); 39 40 TextSpan SubSpan(int32 start, int32 count) const; 41 42 private: 43 void _TruncateInsert(int32& start) const; 44 void _TruncateRemove(int32& start, 45 int32& count) const; 46 47 private: 48 BString fText; 49 int32 fCharCount; 50 CharacterStyle fStyle; 51 }; 52 53 54 #endif // TEXT_SPAN_H 55