Add writeWString for std::string

This commit is contained in:
Henrik Rydgard
2012-07-15 17:38:03 +02:00
parent 5a6622eb37
commit 5819c79463
3 changed files with 26 additions and 3 deletions
+1
View File
@@ -380,6 +380,7 @@ void String::toUnicode(wchar_t *dest)
{
for (int i=0; i<length(); i++)
dest[i]=(wchar_t)CString[i];
}
+23 -2
View File
@@ -194,18 +194,39 @@ void ChunkFile::writeWString(String str) {
wchar_t *text;
int len=str.length();
#ifdef UNICODE
#error
text = str.getPointer();
#else
text=new wchar_t[len+1];
text = new wchar_t[len+1];
str.toUnicode(text);
#endif
writeInt(len);
writeData((char *)text,len*sizeof(wchar_t));
writeData((char *)text, len * sizeof(wchar_t));
#ifndef UNICODE
delete [] text;
#endif
}
void ChunkFile::writeWString(const std::string &str) {
unsigned short *text;
int len=str.length();
#ifdef UNICODE
#error
text = str.c_str();
#else
text = new unsigned short[len+1];
for (int i=0; i<len; i++)
text[i]=str[i];
text[len]=0;
#endif
writeInt(len);
writeData((char *)text, len * sizeof(unsigned short));
#ifndef UNICODE
delete [] text;
#endif
}
String ChunkFile::readWString() {
int len=readInt();
wchar_t *text = new wchar_t[len+1];
+2 -1
View File
@@ -6,7 +6,7 @@
// EITHER a chunk contains ONLY data
// OR it contains ONLY other chunks
// otherwise the scheme breakes.
// otherwise the scheme breaks.
#include <string>
@@ -36,6 +36,7 @@ public:
void writeInt(int i);
void writeWString(String str);
void writeWString(const std::string &str);
void writeData(const void *data, int count);
int getCurrentChunkSize();