Board index » cppbuilder » TStringList of WideString
Jorg
![]() CBuilder Developer |
Jorg
![]() CBuilder Developer |
TStringList of WideString2005-07-29 04:23:30 AM cppbuilder71 Hi guys, is there anybody who already implement a StringList of WideStrings? I would need for my application. If not, I will develop myself, but I do not know where and how to start. I only need the Add and Clear function and the Text property. That would be all. How would you start building such a class? Greetings Jorg |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2005-07-29 04:35:16 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
Quoteis there anybody who already implement a StringList of WideStrings? Gambit |
Jorg
![]() CBuilder Developer |
2005-07-29 05:41:40 AM
Re:TStringList of WideStringQuoteWhich version of BCB are you actually using? BCB6 has a TWideStrings so i need to write my own class. could you explain me how and where to start? greetingsd jorg {smallsort} |
Jonathan Benedicto
![]() CBuilder Developer |
2005-07-29 05:58:08 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
Quoteso i need to write my own class. could you explain me how and where to Jonathan |
Jorg
![]() CBuilder Developer |
2005-07-29 06:13:46 AM
Re:TStringList of WideStringQuoteUse a std::vector of WideStrings. Do you need to read / write the Text also very interested. Jorg |
JD
![]() CBuilder Developer |
2005-07-29 06:15:22 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote:
Quote
~ JD |
Jonathan Benedicto
![]() CBuilder Developer |
2005-07-29 06:24:49 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
Quoteat the moment i also need to read the text property, but to write would // Untested. class TWideStringList { private: std::vector<WideString>Strings; WideString __fastcall GetText() { WideString Temp; for( unsigned int i = 0; i < Strings.size(); ++i ) Temp += Strings[i] + "\r\n"; return Temp; }; public: TWideStringList() { }; void __fastcall Add( WideString Str ) { Strings.push_back( Str ); }; void __fastcall Clear() { Strings.clear(); }; __property WideString Text = { read = GetText }; }; Jonathan |
Jorg
![]() CBuilder Developer |
2005-07-29 06:31:45 AM
Re:TStringList of WideString
Hi Jonathan,
this looks very good. three more chanages and the class would be perfekt for me. 1. a write possibility for the text property 2. Count the number of lines 2. a functionality to get each line like WideString test; for (int i = 0; i < widestringlist->Count; i++) test = widestringlist->Strings[i]; i have no experience with std::vector. i hope you can help me there. Jorg "Jonathan Benedicto" < XXXX@XXXXX.COM >schrieb im Newsbeitrag Quote"Jorg" < XXXX@XXXXX.COM >wrote in message |
Giuliano
![]() CBuilder Developer |
2005-07-29 06:41:20 AM
Re:TStringList of WideString
On Thu, 28 Jul 2005 22:23:30 +0200, "Jorg" < XXXX@XXXXX.COM >wrote:
QuoteHi guys, www.tntware.com/delphicontrols/unicode/ They have a TTntWideStrings class. |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2005-07-29 06:44:38 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
Quote1. a write possibility for the text property private: std::vector<WideString>FStrings; unsigned int __fastcall GetCount() { return FStrings.size(); } WideString __fastcall GetString(unsigned int Index) { return FStrings[Index]; } void __fastcall SetString(unsigned int Index, const WideString &Value) { FStrings[Index] = Value; } WideString __fastcall GetText() { WideString Temp; int Len = 0; for(unsigned int i = 0; i < FStrings.size(); ++i) Len += (FStrings[i].Length() + 2); Temp.SetLength(Len); wchar_t *ptr = Temp.c_bstr(); for(unsigned int i = 0; i < FStrings.size(); ++i) { WideString &w = FStrings[i]; memcpy(ptr, w.c_bstr(), w.Length() * 2); ptr += w.Length(); memcpy(ptr, L"\r\n", 4); ptr += 2; } return Temp; } void __fastcall SetText(const WideString &Value) { Clear(); wchar_t *ptr = Value.c_bstr(); if( ptr != NULL ) { while( *ptr != 0 ) { wchar_t *start = ptr; while( (*ptr != 0) && (*ptr != 10) && (*ptr != 13) ) ++ptr; Add(WideString(start, (ptr - start) / 2)); if( *ptr == 13 ) ++ptr; if( *ptr == 10 ) ++ptr; } } } public: TWideStringList() { } void __fastcall Add(const WideString &Str) { FStrings.push_back(Str); } void __fastcall Clear() { FStrings.clear(); } __property unsigned int Count = { read = GetCount }; __property WideString Strings[unsigned int Index] = { read = GetString, write = SetString }; __property WideString Text = { read = GetText, write = SetText }; }; Gambit |
Jonathan Benedicto
![]() CBuilder Developer |
2005-07-29 06:55:17 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
QuoteHi Jonathan, { private: std::vector<WideString>FStrings; WideString __fastcall GetText() { WideString Temp; for( unsigned int i = 0; i < FStrings.size(); ++i ) Temp += FStrings[i] + "\r\n"; return Temp; }; void __fastcall SetText( WideString value ) { wchar_t *valuePtr = value.c_bstr(); wchar_t *tempPtr = NULL; WideString Newline = "\r\n"; while( valuePtr ) { tempPtr = wcsstr( valuePtr, Newline.c_bstr() ); if( tempPtr == NULL ) break; Add( WideString( valuePtr, tempPtr - valuePtr ) ); valuePtr = tempPtr + 1; }; if( valuePtr ) Add( WideString( valuePtr ) ); }; int __fastcall GetCount() { return FStrings.size(); }; public: TWideStringList() { }; void __fastcall Add( WideString Str ) { FStrings.push_back( Str ); }; void __fastcall Clear() { FStrings.clear(); }; __property WideString Text = { read = GetText, write = SetText }; __property int Count = { read = GetCount }; __property std::vector<WideString>Strings = { read = FStrings }; }; Jonathan |
Jonathan Benedicto
![]() CBuilder Developer |
2005-07-29 06:57:19 AM
Re:TStringList of WideString
"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote in message
Quote>1. a write possibility for the text property WideStringList->Strings[8] = "Test"; Jonathan |
Jorg
![]() CBuilder Developer |
2005-07-29 07:33:17 AM
Re:TStringList of WideString
Hi gambit,
before i start i already installed the tntware unicode compontents: www.tntware.com/delphicontrols/unicode/ I load a XML file into the TntRichEdit. From there I load the text into the text property of the TWideStringList class. widestringlist->Text = tntrichedit->Text; When I traverse the TWideStringList now for (int i = 0; i < widestringlist->Count; i++) ShowMessage(widestringlist->Strings[i]); i do not always get the full line. Sometimes there are some letters or words missing. In this example there was only an easy ansi text. could this be a problem with the TntRichEdit->LoadFromFile method. perhabs it is besser to implement a LoadFromFile and also SaveToFile method to the TWideStringList Jorg "Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >schrieb im Newsbeitrag Quote
|
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2005-07-29 08:20:58 AM
Re:TStringList of WideString
"Jorg" < XXXX@XXXXX.COM >wrote in message
QuoteI load a XML file into the TntRichEdit. From there I load the text into control to perform a non-visual operation. It would be a lot easier to just add a LoadFromFile() method to the TWideStringList class instead. Also, I should mention that XML is typically not encoded in Unicode to begin with. The default encoding is UTF-8 instead, which is compatible with ASCII. You can use a normal TStringList to load a UTF-8 encoded XML file. Gambit |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2005-07-29 08:25:49 AM
Re:TStringList of WideString
"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote in message
QuoteWideString __fastcall GetText() calculate the needed size so that a single memory allocation is performed. Quotevoid __fastcall SetText( WideString value ) time you pass WideString around, a copy is made. By passing the value by const reference instead (also shown in my previous reply), the original WideString value can be used directly without any copy made. Quotevoid __fastcall Add( WideString Str ) { FStrings.push_back( Str ); }; |