本文整理汇总了C++中wxMBConv类的典型用法代码示例。如果您正苦于以下问题:C++ wxMBConv类的具体用法?C++ wxMBConv怎么用?C++ wxMBConv使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wxMBConv类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ConvertFromUTF8
size_t ConvertFromUTF8(const wxCharBuffer& utf8_buff, const wxMBConv& conv, wxWCharBuffer& wchar_buff,
size_t& wchar_buff_len, wxCharBuffer& dest_buff, size_t& dest_buff_len,
size_t char_len) { // static
// Calculate length of conversion to widechar
size_t wchar_len = wxConvUTF8.MB2WC(NULL, utf8_buff, 0);
if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Extend widechar buffer if needed
if (wchar_buff_len < wchar_len + sizeof(wxChar)) {
wchar_buff_len = wchar_len + sizeof(wxChar);
wchar_buff = wxWCharBuffer(wchar_buff_len);
}
// Convert to widechar
wchar_len = wxConvUTF8.MB2WC(wchar_buff.data(), utf8_buff, wchar_buff_len);
if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Calculate length of conversion to dest encoding
size_t dest_len = conv.WC2MB(NULL, wchar_buff, 0);
if (dest_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Extend dest buffer if needed
if (dest_buff_len < dest_len + char_len) {
dest_buff_len = dest_len + char_len;
dest_buff = wxCharBuffer(dest_buff_len);
}
// Convert to dest encoding
dest_len = conv.WC2MB(dest_buff.data(), wchar_buff, dest_buff_len);
if (dest_len == (size_t)-1) return (size_t)-1; // invalid conversion
return dest_len;
}
开发者ID:BBkBlade,项目名称:e,代码行数:33,代码来源:Utf.cpp
示例2: Test
// test that the conversion between str and wcs (subject to flags) succeeds
//
// the first argument is the index in the test array and is used solely for
// diagnostics
void Test(size_t n, wxMBConv& conv) const
{
if ( str )
{
wxWCharBuffer wbuf = conv.cMB2WC(str);
if ( wcs )
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC failed"),
wbuf.data()
);
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC", wbuf, wcs),
wxStrcmp(wbuf, wcs) == 0
);
}
else // conversion is supposed to fail
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "MB2WC succeeded"),
!wbuf.data()
);
}
}
if ( wcs && !(flags & ONLY_MB2WC) )
{
wxCharBuffer buf = conv.cWC2MB(wcs);
if ( str )
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB failed"),
buf.data()
);
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB", buf, str),
strcmp(buf, str) == 0
);
}
else
{
CPPUNIT_ASSERT_MESSAGE
(
Message(n, "WC2MB succeeded"),
!buf.data()
);
}
}
}
开发者ID:AaronDP,项目名称:wxWidgets,代码行数:62,代码来源:unicode.cpp
示例3: memset
wxTextInputStream::wxTextInputStream(wxInputStream &s,
const wxString &sep,
const wxMBConv& conv)
: m_input(s), m_separators(sep), m_conv(conv.Clone())
{
memset((void*)m_lastBytes, 0, 10);
}
开发者ID:erwincoumans,项目名称:wxWidgets,代码行数:7,代码来源:txtstrm.cpp
示例4: DoRoundTripTest
void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
{
TestFile tf;
const wxString data = "Hello\0UTF";
{
wxFile fout(tf.GetName(), wxFile::write);
CPPUNIT_ASSERT( fout.IsOpened() );
CPPUNIT_ASSERT( fout.Write(data, conv) );
}
{
wxFile fin(tf.GetName(), wxFile::read);
CPPUNIT_ASSERT( fin.IsOpened() );
const ssize_t len = fin.Length();
wxCharBuffer buf(len);
CPPUNIT_ASSERT_EQUAL( len, fin.Read(buf.data(), len) );
wxWCharBuffer wbuf(conv.cMB2WC(buf));
#if wxUSE_UNICODE
CPPUNIT_ASSERT_EQUAL( data, wbuf );
#else // !wxUSE_UNICODE
CPPUNIT_ASSERT
(
memcmp(wbuf, L"Hello\0UTF", data.length()*sizeof(wchar_t)) == 0
);
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
}
}
开发者ID:euler0,项目名称:Helium,代码行数:32,代码来源:filetest.cpp
示例5: ConvertToUTF8
size_t ConvertToUTF8(const char* source, const size_t source_len, const wxMBConv& conv, wxCharBuffer& temp_buff,
size_t& temp_buff_len, wxWCharBuffer& wchar_buff, size_t& wchar_buff_len,
wxCharBuffer& utf8_buff, size_t& utf8_buff_len, size_t char_len) { // static
// We have to copy the source string to a temporary buffer so that we can
// make it null terminated.
if (temp_buff_len < source_len+char_len) {
temp_buff_len = source_len+char_len;
temp_buff = wxCharBuffer(temp_buff_len);
}
memcpy(temp_buff.data(), source, source_len);
for (unsigned int i = 0; i < char_len; ++i) temp_buff.data()[source_len+i] = '\0';
// Calculate length of conversion to widechar
size_t wchar_len = conv.MB2WC(NULL, temp_buff, 0);
if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Extend widechar buffer if needed
if (wchar_buff_len < wchar_len + sizeof(wxChar)) {
wchar_buff_len = wchar_len + sizeof(wxChar);
wchar_buff = wxWCharBuffer(wchar_buff_len);
}
// Convert to widechar
wchar_len = conv.MB2WC(wchar_buff.data(), temp_buff, wchar_buff_len);
if (wchar_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Calculate length of conversion to UTF-8
size_t utf8_len = wxConvUTF8.WC2MB(NULL, wchar_buff, 0);
if (utf8_len == (size_t)-1) return (size_t)-1; // invalid conversion
// Extend UTF-8 buffer if needed
if (utf8_buff_len < utf8_len) {
utf8_buff_len = utf8_len + 1;
utf8_buff = wxCharBuffer(utf8_buff_len);
}
// Convert to UTF-8
utf8_len = wxConvUTF8.WC2MB(utf8_buff.data(), wchar_buff, utf8_buff_len);
if (utf8_len == (size_t)-1) return (size_t)-1; // invalid conversion
return utf8_len;
}
开发者ID:BBkBlade,项目名称:e,代码行数:42,代码来源:Utf.cpp
示例6: m_input
wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv)
: m_input(&s), m_be_order(false), m_conv(conv.Clone())
#else
wxDataInputStream::wxDataInputStream(wxInputStream& s)
: m_input(&s), m_be_order(false)
#endif
{
}
wxDataInputStream::~wxDataInputStream()
{
#if wxUSE_UNICODE
delete m_conv;
#endif // wxUSE_UNICODE
}
#if wxUSE_UNICODE
void wxDataInputStream::SetConv( const wxMBConv &conv )
{
delete m_conv;
m_conv = conv.Clone();
}
开发者ID:ahlekoofe,项目名称:gamekit,代码行数:22,代码来源:datstrm.cpp
示例7: filename
wxGzipOutputStream::wxGzipOutputStream(
wxOutputStream& stream,
const wxString& originalName /*=wxEmptyString*/,
#if wxUSE_DATETIME
const wxDateTime& originalTime /*=wxDateTime::Now()*/,
#endif
int level /*=-1*/,
wxMBConv& conv /*=wxConvFile*/)
: wxFilterOutputStream(stream)
{
m_comp = NULL;
m_crc = crc32(0, Z_NULL, 0);
wxFileName filename(originalName);
wxUint32 timestamp = 0;
#if wxUSE_DATETIME
if (originalTime.IsValid())
timestamp = (originalTime.GetValue() / 1000L).GetLo();
#endif
// RFC-1952 specifies ISO-8859-1 for the name. Also it should be just the
// name part, no directory, folded to lowercase if case insensitive
wxString name = filename.GetFullName();
const wxWX2MBbuf mbName = conv.cWX2MB(name);
wxDataOutputStream ds(*m_parent_o_stream);
// write signature, method, flags, timestamp, extra flags and OS-code
ds.Write16(GZ_MAGIC);
ds.Write8(Z_DEFLATED);
ds.Write8(mbName && *mbName ? GZ_ORIG_NAME : 0);
ds.Write32(timestamp);
ds.Write8(level == 1 ? GZ_FASTEST : level == 9 ? GZ_SLOWEST : 0);
ds.Write8(255);
if (mbName && *mbName)
m_parent_o_stream->Write(mbName, strlen(mbName) + 1);
m_lasterror = wxSTREAM_WRITE_ERROR;
if (!*m_parent_o_stream) {
wxLogDebug(wxT("Error writing Gzip header"));
return;
}
m_comp = new wxZlibOutputStream(*m_parent_o_stream, level, wxZLIB_NO_HEADER);
if (m_comp)
m_lasterror = m_comp->GetLastError();
}
开发者ID:stahta01,项目名称:wxCode_components,代码行数:50,代码来源:gzstream.cpp
示例8: wxUnusedVar
wxDataStreamBase::wxDataStreamBase(const wxMBConv& conv)
#if wxUSE_UNICODE
: m_conv(conv.Clone())
#endif // wxUSE_UNICODE
{
// It is unused in non-Unicode build, so suppress a warning there.
wxUnusedVar(conv);
m_be_order = false;
// For compatibility with the existing data files, we use extended
// precision if it is available, i.e. if wxUSE_APPLE_IEEE is on.
#if wxUSE_APPLE_IEEE
m_useExtendedPrecision = true;
#endif // wxUSE_APPLE_IEEE
}
开发者ID:CodeSmithyIDE,项目名称:wxWidgets,代码行数:16,代码来源:datstrm.cpp
示例9: GetNextLine
wxString CTextFile::GetNextLine(const wxMBConv& conv)
{
wxCHECK_MSG(m_file.IsOpened(), wxEmptyString, wxT("Trying to read from closed file."));
wxCHECK_MSG(!m_file.Eof(), wxEmptyString, wxT("Trying to read past EOF"));
wxCHECK_MSG((m_mode == read), wxEmptyString, wxT("Trying to read from non-readable file."));
wxString line;
char buffer[TXTBUF_SIZE];
// Loop until EOF (fgets will then return NULL) or a newline is read.
while (fgets(buffer, TXTBUF_SIZE, m_file.fp())) {
// NB: The majority of the time spent by this function is
// spent converting the multibyte string to wide-char.
line += conv.cMB2WC(buffer);
// Remove any newlines, carriage returns, etc.
if (line.Length() && (line.Last() == wxT('\n'))) {
if ((line.Length() > 1)) {
if (line[line.Length() - 2] == wxT('\r')) {
// Carriage return + newline
line.RemoveLast(2);
} else {
// Only a newline.
line.RemoveLast(1);
}
} else {
// Empty line
line.Clear();
}
// We've read an entire line.
break;
}
}
return line;
}
开发者ID:dreamerc,项目名称:amule,代码行数:38,代码来源:TextFile.cpp
示例10: WriteLine
bool CTextFile::WriteLine(const wxString& line, const wxMBConv& conv)
{
wxCHECK_MSG(m_file.IsOpened(), false, wxT("Trying to read from closed file."));
wxCHECK_MSG((m_mode == write), false, wxT("Trying to read from non-readable file."));
// Ensures that use of newlines/carriage-returns matches the OS
wxString result = wxTextBuffer::Translate(line);
// Only add line-breaks between lines, as otherwise the number of
// lines would grow as the result of the addition of an empty line,
// at the end of the file.
if (m_file.Tell() > 0) {
result = wxTextBuffer::GetEOL() + result;
}
wxCharBuffer strBuffer = conv.cWC2MB(result);
if (strBuffer) {
const size_t length = strlen(strBuffer);
return (m_file.Write(strBuffer, length) == length);
}
return false;
}
开发者ID:dreamerc,项目名称:amule,代码行数:24,代码来源:TextFile.cpp
示例11: ReadDouble
wxDataInputStream::wxDataInputStream(wxInputStream& s, const wxMBConv& conv)
: m_input(&s), m_be_order(false), m_conv(conv.Clone())
#else
wxDataInputStream::wxDataInputStream(wxInputStream& s)
: m_input(&s), m_be_order(false)
#endif
{
}
wxDataInputStream::~wxDataInputStream()
{
#if wxUSE_UNICODE
delete m_conv;
#endif // wxUSE_UNICODE
}
#if wxHAS_INT64
wxUint64 wxDataInputStream::Read64()
{
wxUint64 tmp;
Read64(&tmp, 1);
return tmp;
}
#endif // wxHAS_INT64
wxUint32 wxDataInputStream::Read32()
{
wxUint32 i32;
m_input->Read(&i32, 4);
if (m_be_order)
return wxUINT32_SWAP_ON_LE(i32);
else
return wxUINT32_SWAP_ON_BE(i32);
}
wxUint16 wxDataInputStream::Read16()
{
wxUint16 i16;
m_input->Read(&i16, 2);
if (m_be_order)
return wxUINT16_SWAP_ON_LE(i16);
else
return wxUINT16_SWAP_ON_BE(i16);
}
wxUint8 wxDataInputStream::Read8()
{
wxUint8 buf;
m_input->Read(&buf, 1);
return (wxUint8)buf;
}
double wxDataInputStream::ReadDouble()
{
#if wxUSE_APPLE_IEEE
char buf[10];
m_input->Read(buf, 10);
return ConvertFromIeeeExtended((const wxInt8 *)buf);
#else
return 0.0;
#endif
}
开发者ID:czxxjtu,项目名称:wxPython-1,代码行数:68,代码来源:datstrm.cpp
示例12: SetConv
void wxDataStreamBase::SetConv( const wxMBConv &conv )
{
delete m_conv;
m_conv = conv.Clone();
}
开发者ID:CodeSmithyIDE,项目名称:wxWidgets,代码行数:5,代码来源:datstrm.cpp
注:本文中的wxMBConv类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论