本文整理汇总了C++中wxString::GetWriteBuf方法的典型用法代码示例。如果您正苦于以下问题:C++ wxString::GetWriteBuf方法的具体用法?C++ wxString::GetWriteBuf怎么用?C++ wxString::GetWriteBuf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wxString
的用法示例。
在下文中一共展示了wxString::GetWriteBuf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wxExtractSubString
/// Extracts the nth substring from a delimited string
/// This is a wxWidgets port of MFC's AfxExtractSubString
/// @param string Holds the returned substring
/// @param fullString String to extract the substring from
/// @param subString Zero-based index of the substring to extract
/// @param separator Character used to separator the substrings
/// @return True if the substring was extracted, false if not
bool wxExtractSubString(wxString& string, const wxChar* fullString,
wxUint32 subString, wxChar separator)
{
//------Last Verified------//
// - Nov 27, 2004
wxCHECK(fullString != (wxChar*)NULL, false);
string.Clear();
while (subString--)
{
fullString = wxStrchr(fullString, separator);
if (fullString == NULL)
{
string.Clear(); // return empty string as well
return (false);
}
fullString++; // point past the separator
}
const wxChar* end = wxStrchr(fullString, separator);
wxInt32 length = (end == NULL) ? wxStrlen_(fullString) :
(wxInt32)(end - fullString);
wxASSERT(length >= 0);
memcpy(string.GetWriteBuf(length), fullString, length * sizeof(wxChar));
string.UngetWriteBuf(); // Need to call ReleaseBuffer
// after calling GetBufferSetLength
return (true);
}
示例2:
size_t ConvertFromUTF8toString(const wxCharBuffer& utf8_buff, size_t utf8_buff_len, wxString& text) { // static
// The length can never be longer in widechars than the bytecount in the uft8 (plus trailing null byte)
wxChar* buff = text.GetWriteBuf(utf8_buff_len+1);
// Convert to widechar
const size_t wchar_len = UTF8ToWChar(buff, utf8_buff_len, utf8_buff, utf8_buff_len);
if (wchar_len == wxCONV_FAILED) { // invalid conversion
text.UngetWriteBuf(0);
return wxCONV_FAILED;
}
text.UngetWriteBuf(wchar_len);
return wchar_len;
}