本文整理汇总了C++中wstring::data方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::data方法的具体用法?C++ wstring::data怎么用?C++ wstring::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wstring
的用法示例。
在下文中一共展示了wstring::data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getUnicodeWstringConverter
string
IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter)
{
string target;
if(!v.empty())
{
const WstringConverterPtr& wConverterWithDefault = wConverter ? wConverter : getUnicodeWstringConverter();
//
// First convert to UTF-8 narrow string.
//
UTF8BufferI buffer;
Byte* last = wConverterWithDefault->toUTF8(v.data(), v.data() + v.size(), buffer);
buffer.swap(target, last);
//
// If narrow string converter is present convert to the native narrow string encoding, otherwise
// native narrow string encoding is UTF8 and we are done.
//
if(converter)
{
string tmp;
converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()),
reinterpret_cast<const Byte*>(target.data() + target.size()), tmp);
tmp.swap(target);
}
}
return target;
}
示例2: IllegalConversionException
string
IceUtil::wstringToString(const wstring& v, const StringConverterPtr& converter, const WstringConverterPtr& wConverter,
IceUtil::ConversionFlags flags)
{
string target;
if(!v.empty())
{
//
// First convert to UTF8 narrow string.
//
if(wConverter)
{
UTF8BufferI buffer;
Byte* last = wConverter->toUTF8(v.data(), v.data() + v.size(), buffer);
target = string(reinterpret_cast<const char*>(buffer.getBuffer()), last - buffer.getBuffer());
}
else
{
size_t size = v.size() * 4 * sizeof(char);
Byte* outBuf = new Byte[size];
Byte* targetStart = outBuf;
Byte* targetEnd = outBuf + size;
const wchar_t* sourceStart = v.data();
ConversionResult cr =
convertUTFWstringToUTF8(
sourceStart, sourceStart + v.size(),
targetStart, targetEnd, flags);
if(cr != conversionOK)
{
delete[] outBuf;
assert(cr == sourceExhausted || cr == sourceIllegal);
throw IllegalConversionException(__FILE__, __LINE__,
cr == sourceExhausted ? "partial character" : "bad encoding");
}
target = string(reinterpret_cast<char*>(outBuf), static_cast<size_t>(targetStart - outBuf));
delete[] outBuf;
}
//
// If narrow string converter is present convert to the native narrow string encoding, otherwise
// native narrow string encoding is UTF8 and we are done.
//
if(converter)
{
string tmp;
converter->fromUTF8(reinterpret_cast<const Byte*>(target.data()),
reinterpret_cast<const Byte*>(target.data() + target.size()), tmp);
tmp.swap(target);
}
}
return target;
}
示例3: unicode_to_ansi
string unicode_to_ansi(const wstring& str, unsigned code_page) {
unsigned str_size = static_cast<unsigned>(str.size());
if (str_size == 0)
return string();
int size = WideCharToMultiByte(code_page, 0, str.data(), str_size, nullptr, 0, nullptr, nullptr);
Buffer<char> out(size);
size = WideCharToMultiByte(code_page, 0, str.data(), str_size, out.data(), size, nullptr, nullptr);
CHECK_SYS(size);
return string(out.data(), size);
}
示例4: RuntimeHostException
ObjectInstance::ObjectInstance(ApplicationDomain* applicationDomain, const wstring assemblyName, const wstring className)
{
HRESULT hr = applicationDomain->GetHandle()->CreateInstance(
_bstr_t(assemblyName.data()),
_bstr_t(className.data()),
&this->objectHandle);
if (!SUCCEEDED(hr))
{
throw new RuntimeHostException("Unable to create the object instance");
}
}
示例5: AddNewScheduledTask
//---------------------------------------------------------------------------
int TTaskScheduler::AddNewScheduledTask(wstring taskName){
/////////////////////////////////////////////////////////////////
// Call ITaskScheduler::NewWorkItem to create new task.
/////////////////////////////////////////////////////////////////
ITask *pITask;
HRESULT hr = pITS->NewWorkItem(taskName.data(), // Name of task
CLSID_CTask, // Class identifier
IID_ITask, // Interface identifier
(IUnknown**)&pITask); // Address of task interface
if (FAILED(hr)){
sprintf(lastError, "Failed calling NewWorkItem, error = 0x%x\n",hr);
return 0;
}
Save(pITask);
pITask->Release();
return 1;
}
示例6: find_dir
UInt32 Archive::find_dir(const wstring& path) {
if (file_list.empty())
make_index();
ArcFileInfo dir_info;
dir_info.is_dir = true;
dir_info.parent = c_root_index;
size_t begin_pos = 0;
while (begin_pos < path.size()) {
size_t end_pos = begin_pos;
while (end_pos < path.size() && !is_slash(path[end_pos])) end_pos++;
if (end_pos != begin_pos) {
dir_info.name.assign(path.data() + begin_pos, end_pos - begin_pos);
FileIndexRange fi_range = equal_range(file_list_index.begin(), file_list_index.end(), -1, [&] (UInt32 left, UInt32 right) -> bool {
const ArcFileInfo& fi_left = left == -1 ? dir_info : file_list[left];
const ArcFileInfo& fi_right = right == -1 ? dir_info : file_list[right];
return fi_left < fi_right;
});
if (fi_range.first == fi_range.second)
FAIL(HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND));
dir_info.parent = *fi_range.first;
}
begin_pos = end_pos + 1;
}
return dir_info.parent;
}
示例7: word_wrap
wstring word_wrap(const wstring& str, wstring::size_type wrap_bound) {
wstring result;
wstring::size_type begin_pos = 0;
while (begin_pos < str.size()) {
wstring::size_type end_pos = begin_pos + wrap_bound;
if (end_pos < str.size()) {
for (wstring::size_type i = end_pos; i > begin_pos; i--) {
if (str[i - 1] == L' ') {
end_pos = i;
break;
}
}
}
else {
end_pos = str.size();
}
wstring::size_type trim_pos = end_pos;
while (trim_pos > begin_pos && str[trim_pos - 1] == L' ') trim_pos--;
if (trim_pos > begin_pos) {
if (!result.empty())
result.append(1, L'\n');
result.append(str.data() + begin_pos, trim_pos - begin_pos);
}
begin_pos = end_pos;
}
return result;
}
示例8: ConvertWstringToCodepage
std::string ConvertWstringToCodepage( wstring s, int iCodePage )
{
if( s.empty() )
return std::string();
int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(),
nullptr, 0, nullptr, FALSE );
ASSERT_M( iBytes > 0, werr_format( GetLastError(), "WideCharToMultiByte" ).c_str() );
char * buf = new char[iBytes + 1];
std::fill(buf, buf + iBytes + 1, '\0');
WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(), buf, iBytes, nullptr, FALSE );
std::string ret( buf );
delete[] buf;
return ret;
}
示例9: substr_match
bool substr_match(const wstring& str, wstring::size_type pos, wstring::const_pointer mstr) {
size_t mstr_len = wcslen(mstr);
if ((pos > str.length()) || (pos + mstr_len > str.length())) {
return false;
}
return wmemcmp(str.data() + pos, mstr, mstr_len) == 0;
}
示例10: ConvertWstringToACP
CString ConvertWstringToACP( wstring s )
{
if( s.empty() )
return "";
int iBytes = WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(),
NULL, 0, NULL, FALSE );
ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() );
CString ret;
WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(),
ret.GetBuf( iBytes ), iBytes, NULL, FALSE );
ret.RelBuf( iBytes );
return ret;
}
示例11: ConvertWstringToCodepage
RString ConvertWstringToCodepage( wstring s, int iCodePage )
{
if( s.empty() )
return RString();
int iBytes = WideCharToMultiByte( iCodePage, 0, s.data(), s.size(),
NULL, 0, NULL, FALSE );
ASSERT_M( iBytes > 0, werr_ssprintf( GetLastError(), "WideCharToMultiByte" ).c_str() );
char * buf = new char[iBytes];
WideCharToMultiByte( CP_ACP, 0, s.data(), s.size(),
buf, iBytes, NULL, FALSE );
RString ret( buf );
delete[] buf;
return ret;
}
示例12: dumpLabel
void CCilDisasm::dumpLabel( wstring& str )
{
//32 chars
str.append( L":" );
swprintf_s( m_wstrBuffer, ARRAYSIZE( m_wstrBuffer ), L"%-32s", str.data() );
wcout << m_wstrBuffer;
}
示例13: DeleteTask
int TTaskScheduler::DeleteTask(wstring taskName){
HRESULT hr = pITS->Delete(taskName.data());
if(hr == S_OK){
return 1;
}
sprintf(lastError, "Unable to delete a task, error = 0x%x\n",hr);
return 0;
}
示例14: useIconFromFile
void DocumentIconFinder::useIconFromFile(const wstring& iconFile)
{
TCHAR buffer[MAX_PATH];
throwOnFailure<OleException>(
StringCchCopy(buffer, MAX_PATH, iconFile.data()));
m_iconIndex = PathParseIconLocation(buffer);
m_iconFile = buffer;
}
示例15: Execute
VARIANT ObjectInstance::Execute(const wstring methodName, DISPPARAMS inputParameters)
{
if (this->objectHandle == NULL)
{
throw new RuntimeHostException("ObjectHandle is no longer valid");
}
VARIANT v;
DISPID dispid;
LPOLESTR szMethodName = _bstr_t(methodName.data());
VARIANT result;
EXCEPINFO pExcepInfo;
unsigned int puArgErr = 0;
// Initialze the variants
VariantInit(&v);
VariantInit(&result);
HRESULT hr = this->objectHandle->Unwrap(&v);
if (!SUCCEEDED(hr))
{
throw new RuntimeHostException("Unable to retrieve method information");
}
// The .NET Component should expose IDispatch
IDispatch* pdispatch = v.pdispVal;
// Retrieve the DISPID
hr = pdispatch->GetIDsOfNames(
IID_NULL,
&szMethodName,
1,
LOCALE_SYSTEM_DEFAULT,
&dispid);
if (!SUCCEEDED(hr))
{
throw new RuntimeHostException("Unable to retrieve method information");
}
// Invoke the method on the IDispatch Interface
hr = pdispatch->Invoke(
dispid,
IID_NULL,
LOCALE_SYSTEM_DEFAULT,
DISPATCH_METHOD,
&inputParameters,
&result,
&pExcepInfo,
&puArgErr);
if (!SUCCEEDED(hr))
{
throw new RuntimeHostException("Error on method execution");
}
return result;
}