示例#1
0
/// 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
0
文件: Utf.cpp 项目: BBkBlade/e
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;
}