Woopsi 1.3
Nintendo DS Gui Framework
libwoopsi/include/woopsistring.h
00001 #ifndef _WOOPSI_STRING_H_
00002 #define _WOOPSI_STRING_H_
00003 
00004 #include <stdarg.h>
00005 #include <nds.h>
00006 #include "woopsiarray.h"
00007 
00008 namespace WoopsiUI {
00009     
00010     class StringIterator;
00011 
00032     class WoopsiString {
00033     public:
00034 
00038         WoopsiString();
00039 
00045         WoopsiString(const char* text);
00046         
00051         WoopsiString(const u32 letter);
00052 
00057         WoopsiString(const WoopsiString& string);
00058 
00065         WoopsiString(const WoopsiString& string, const s32 startIndex);
00066 
00074         WoopsiString(const WoopsiString& string, const s32 startIndex, const s32 length);
00075 
00079         virtual inline ~WoopsiString() {
00080             delete[] _text;
00081             _text = NULL;
00082         };
00083         
00090         StringIterator* newStringIterator() const;
00091 
00101         virtual void copyToCharArray(char* buffer) const;
00102 
00109         virtual void setText(const WoopsiString& text, const s32 startIndex, const s32 length);
00110         
00115         virtual void setText(const WoopsiString& text);
00116 
00121         virtual void setText(const char* text);
00122 
00127         virtual void setText(const u32 text);
00128 
00133         virtual void append(const WoopsiString& text);
00134 
00140         virtual void insert(const WoopsiString& text, const s32 index);
00141 
00146         virtual void remove(const s32 startIndex);
00147 
00154         virtual void remove(const s32 startIndex, const s32 count);
00155 
00160         virtual const s32 getLength() const { return _stringLength; };
00161 
00166         virtual const s32 getByteCount() const { return _dataLength; };
00167 
00177         virtual const u32 getCharAt(s32 index) const;
00178 
00185         const s32 indexOf(u32 letter) const;
00186 
00195         const s32 indexOf(u32 letter, s32 startIndex) const;
00196 
00207         virtual const s32 indexOf(u32 letter, s32 startIndex, s32 count) const;
00208 
00215         const s32 lastIndexOf(u32 letter) const;
00216 
00226         const s32 lastIndexOf(u32 letter, s32 startIndex) const;
00227 
00238         virtual const s32 lastIndexOf(u32 letter, s32 startIndex, s32 count) const;
00239 
00245         WoopsiString subString(s32 startIndex) const;
00246 
00253         WoopsiString subString(s32 startIndex, s32 length) const;
00254         
00261         WoopsiString& operator=(const WoopsiString& string);
00262 
00269         WoopsiString& operator=(const char* string);
00270 
00277         WoopsiString& operator=(u32 letter);
00278 
00285         WoopsiString operator+(const WoopsiString& string);
00286 
00293         WoopsiString& operator+=(const WoopsiString& string);
00294 
00301         bool operator==(const WoopsiString& string) { return compareTo(string) == 0; };
00302 
00309         bool operator!=(const WoopsiString& string) { return compareTo(string) != 0; };
00310 
00321         virtual s8 compareTo(const WoopsiString& string, bool caseSensitive = false) const;
00322 
00331         s32 indexOf(const char* text) const;
00332 
00342         s32 indexOf(const char* text, s32 startIndex) const;
00343 
00355         s32 indexOf(const WoopsiString& text, s32 startIndex, s32 count) const;
00356 
00365         s32 lastIndexOf(const char* text) const;
00366 
00376         s32 lastIndexOf(const char* text, s32 startIndex) const;
00377 
00389         s32 lastIndexOf(const WoopsiString& text, s32 startIndex, s32 count) const;
00390 
00397         void format(const char *format, ...);
00398 
00414         void format(const char *format, va_list args);
00415 
00422         void replace(const WoopsiString& oldText, const WoopsiString& newText);
00423 
00431         void replace(const WoopsiString& oldText, const WoopsiString& newText,  const s32 startIndex);
00432 
00440         void replace(const s32 startIndex, const s32 count, const WoopsiString& newText);
00441 
00450         void replace(const WoopsiString& oldText, const WoopsiString& newText, const s32 startIndex, const s32 replaceCount);
00451 
00459         void split(const WoopsiString& separator, WoopsiArray<WoopsiString>& result) const;
00460 
00471         void split(const WoopsiString& separator, bool allowEmptyEntries, WoopsiArray<WoopsiString>& result) const;
00472 
00473     protected:
00474         char* _text;                            
00479         virtual void init();
00480 
00487         virtual void allocateMemory(s32 chars, bool preserve);
00488 
00494         virtual inline bool hasData() const { return _dataLength > 0; };
00495 
00500         virtual inline s32 getAllocatedSize() const { return _allocatedSize; };
00501 
00512         s32 filterString(char* dest, const char* src, s32 sourceBytes, s32* totalUnicodeChars) const;
00513 
00518         virtual inline const char* getCharArray() const { return _text; };
00519 
00524         virtual char* getToken(const s32 index) const;
00525 
00534         u32 getCodePoint(const char* string, u8* numChars = NULL) const;
00535 
00536     private:
00537         friend class StringIterator;
00538         
00539         s32 _dataLength;    
00540         s32 _stringLength;  
00541         s32 _allocatedSize; 
00542         s32 _growAmount;    
00555          const char* encodeCodePoint(u32 codePoint, u8* numBytes = NULL) const;
00556     };
00557 }
00558 
00559 #endif
 All Classes Functions Variables Enumerations Enumerator