[commit] r1231 - in trunk/GME: Common Core
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Wed Mar 30 15:17:04 CDT 2011
Author: ksmyth
Date: Wed Mar 30 15:17:04 2011
New Revision: 1231
Log:
Use CP_UTF8 for serialization/deserialization. Use CP_ACP elsewhere
Modified:
trunk/GME/Common/CommonSmart.cpp
trunk/GME/Common/CommonSmart.h
trunk/GME/Core/CoreBinFile.cpp
Modified: trunk/GME/Common/CommonSmart.cpp
==============================================================================
--- trunk/GME/Common/CommonSmart.cpp Wed Mar 30 14:29:00 2011 (r1230)
+++ trunk/GME/Common/CommonSmart.cpp Wed Mar 30 15:17:04 2011 (r1231)
@@ -15,7 +15,7 @@
return wcsncmp(p, q, pl);
}
-void CopyTo(const char *p, int len, BSTR *b)
+void CopyTo(const char *p, int len, BSTR *b, UINT codepage)
{
ASSERT( len >= 0 );
ASSERT( b != NULL );
@@ -29,7 +29,7 @@
if( len <= 0 )
return;
- int blen = MultiByteToWideChar(CP_UTF8, 0, p, len, NULL, 0);
+ int blen = MultiByteToWideChar(codepage, 0, p, len, NULL, 0);
if( blen <= 0 )
HR_THROW(E_CONVERSION);
@@ -38,7 +38,7 @@
if( *b == NULL )
HR_THROW(E_OUTOFMEMORY);
- int tlen = MultiByteToWideChar(CP_UTF8, 0, p, len, *b, blen);
+ int tlen = MultiByteToWideChar(codepage, 0, p, len, *b, blen);
if( tlen <= 0 )
HR_THROW(E_CONVERSION);
@@ -48,14 +48,14 @@
(*b)[blen] = L'\0';
}
-int GetCharLength(const OLECHAR *p, int olelen)
+int GetCharLength(const OLECHAR *p, int olelen, UINT codepage)
{
ASSERT( olelen >= -1 );
if( olelen == 0 )
return 0;
- int charlen = WideCharToMultiByte(CP_UTF8, 0, p, olelen,
+ int charlen = WideCharToMultiByte(codepage, 0, p, olelen,
NULL, 0, NULL, NULL);
// zero if failed
@@ -64,7 +64,7 @@
return charlen;
}
-void CopyTo(const OLECHAR *p, int olelen, char *s, int charlen)
+void CopyTo(const OLECHAR *p, int olelen, char *s, int charlen, UINT codepage)
{
ASSERT( olelen >= -1 && charlen >= 0 );
ASSERT( charlen == 0 || p != NULL );
@@ -72,7 +72,7 @@
if( charlen <= 0 )
return;
- int len = WideCharToMultiByte(CP_UTF8, 0, p, olelen,
+ int len = WideCharToMultiByte(codepage, 0, p, olelen,
s, charlen, NULL, NULL);
// zero if failed
Modified: trunk/GME/Common/CommonSmart.h
==============================================================================
--- trunk/GME/Common/CommonSmart.h Wed Mar 30 14:29:00 2011 (r1230)
+++ trunk/GME/Common/CommonSmart.h Wed Mar 30 15:17:04 2011 (r1231)
@@ -210,12 +210,12 @@
// these THROW exceptions
-void CopyTo(const char *p, int len, BSTR *b);
+void CopyTo(const char *p, int len, BSTR *b, UINT codepage=CP_ACP);
// if olelen is -1, then OLECHAR is NULL terminated and the charlen includes this NULL
-int GetCharLength(const OLECHAR *p, int olelen);
+int GetCharLength(const OLECHAR *p, int olelen, UINT codepage=CP_ACP);
-void CopyTo(const OLECHAR *p, int olelen, char *s, int charlen);
+void CopyTo(const OLECHAR *p, int olelen, char *s, int charlen, UINT codepage=CP_ACP);
void CopyTo(const OLECHAR *p, GUID &guid);
void CopyTo(const GUID &guid, BSTR *p);
@@ -224,7 +224,7 @@
inline void CopyTo(const char *p, int len, CComBstrObj &b) { CopyTo(p, len, &b.p); }
inline int GetCharLength(BSTR p) { return GetCharLength(p, SysStringLen(p)); }
-inline void CopyTo(BSTR p, char *s, int charlen) { CopyTo(p, SysStringLen(p), s, charlen); }
+inline void CopyTo(BSTR p, char *s, int charlen, UINT codepage=CP_ACP) { CopyTo(p, SysStringLen(p), s, charlen, codepage); }
inline void CopyTo(const GUID &guid, CComBstrObj &b) { CopyTo(guid, &b.p); }
// --------------------------- CComBSTR
Modified: trunk/GME/Core/CoreBinFile.cpp
==============================================================================
--- trunk/GME/Core/CoreBinFile.cpp Wed Mar 30 14:29:00 2011 (r1230)
+++ trunk/GME/Core/CoreBinFile.cpp Wed Mar 30 15:17:04 2011 (r1231)
@@ -608,7 +608,7 @@
if (len > cifs_eof - cifs) {
HR_THROW(E_FILEOPEN);
}
- CopyTo(cifs, len, &ss.p);
+ CopyTo(cifs, len, &ss.p, CP_UTF8);
cifs += len;
} else {
std::string s;
@@ -633,16 +633,20 @@
{
ASSERT( ofs.is_open() );
- std::string s;
- CopyTo(ss, s);
+ int len = GetCharLength(ss, SysStringLen(ss.p), CP_UTF8);
+ char* s = NULL;
+ if (len) {
+ s = new char[len];
+ CopyTo(ss.p, s, len, CP_UTF8);
+ }
- int len = s.size();
ASSERT( len >= 0 );
write(len);
if( len > 0 )
ofs.write( (const char *) &s[0], len);
+ delete[] s;
}
// ------- Attribute
More information about the gme-commit
mailing list