本文整理汇总了C++中std::wstring::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::resize方法的具体用法?C++ wstring::resize怎么用?C++ wstring::resize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::wstring
的用法示例。
在下文中一共展示了wstring::resize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
utf8_conv_result_t utf8_wchar(const std::string &utf8, std::wstring &wide)
{
// allocate space for worst-case
wide.resize(utf8.size());
wchar_t const* dst_start = wide.c_str();
char const* src_start = utf8.c_str();
ConversionResult ret;
// TODO: 3 refactor this to use wchar_t as a template
// it would cause less code to be generated without
// relying on dead-code elimination and fix msvc constant
// expression warning
if (sizeof(wchar_t) == sizeof(UTF32))
{
ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start
+ utf8.size(), (UTF32**)&dst_start, (UTF32*)dst_start + wide.size()
, lenientConversion);
wide.resize(dst_start - wide.c_str());
return (utf8_conv_result_t)ret;
}
else if (sizeof(wchar_t) == sizeof(UTF16))
{
ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start
+ utf8.size(), (UTF16**)&dst_start, (UTF16*)dst_start + wide.size()
, lenientConversion);
wide.resize(dst_start - wide.c_str());
return (utf8_conv_result_t)ret;
}
else
{
return source_illegal;
}
}
示例2: gbk_to_utf16
bool gbk_to_utf16( std::wstring& dest, const std::string& src )
{
#ifdef _WIN32
dest.resize(src.size());
const string old_locale = setlocale(LC_CTYPE, NULL);
setlocale(LC_CTYPE, ".936");
size_t unicodeLength = mbstowcs(const_cast<wchar_t*>(dest.data()), src.c_str(), src.size());
setlocale(LC_CTYPE, old_locale.c_str());
if (unicodeLength == -1)
{
dest = L"";
return false;
}
dest.resize(unicodeLength);
#else
string strTmp;
if (!gbk_to_utf8(strTmp, src))
return false;
utf8_to_utf16(dest, strTmp);
if (dest==L"")
{
return false;
}
#endif
return true;
}
示例3: if
inline int utf8_wchar(const std::string &utf8, std::wstring &wide)
{
// allocate space for worst-case
wide.resize(utf8.size());
wchar_t const* dst_start = wide.c_str();
char const* src_start = utf8.c_str();
ConversionResult ret;
if (sizeof(wchar_t) == sizeof(UTF32))
{
ret = ConvertUTF8toUTF32((const UTF8**)&src_start, (const UTF8*)src_start
+ utf8.size(), (UTF32**)&dst_start, (UTF32*)dst_start + wide.size()
, lenientConversion);
wide.resize(dst_start - wide.c_str());
return ret;
}
else if (sizeof(wchar_t) == sizeof(UTF16))
{
ret = ConvertUTF8toUTF16((const UTF8**)&src_start, (const UTF8*)src_start
+ utf8.size(), (UTF16**)&dst_start, (UTF16*)dst_start + wide.size()
, lenientConversion);
wide.resize(dst_start - wide.c_str());
return ret;
}
else
{
return sourceIllegal;
}
}
示例4:
int ISO8601::ToString(const struct tm& value, std::wstring& str)
{
int len = MAX_DATETIME_LENGTH;
str.resize(len, '\0');
int r = ISO8601::ToString(value, const_cast<wchar_t *>(str.c_str()), &len);
str.resize(len);
return (errno = r);
}
示例5: readEntities
static void readEntities(const std::string &strValue, std::wstring &strResult)
{
size_t size = 0;
std::string strMulti;
readEntities(strValue, strMulti);
strResult.resize(strMulti.size());
mbstowcs_s(&size, &strResult[0], strResult.size(), strMulti.c_str(), strMulti.size());
strResult.resize(size);
}
示例6:
int UTF8::ToUnicode(const char *utf8_data, int len, std::wstring& str)
{
int wlen = (len + 1) * 4;
str.resize(wlen, L'\0');
int r = UTF8::ToUnicode(utf8_data, len, (wchar_t *)str.c_str(), &wlen);
if (r) return r;
str.resize(wlen, L'\0');
return (errno = 0);
}
示例7: codepage_to_wstring_append
bool token::codepage_to_wstring_append( uint cp, std::wstring& dst ) const
{
uints i = dst.length();
dst.resize(i+len());
wchar_t* data = const_cast<wchar_t*>(dst.data());
uint n = MultiByteToWideChar( cp, 0, ptr(), (uint)len(), data+i, (uint)len() );
dst.resize(i+n);
return n>0;
}
示例8: namedValue
bool Reader::namedValue(const char *name, std::wstring &value)
{
std::string text;
bool bOK = namedValue(name, text);
if (bOK)
{
size_t size = text.size();
value.resize(' ', size * 2 + 1);
mbstowcs_s(&size, &value[0], value.size(), text.c_str(), text.size());
value.resize(size);
}
return bOK;
}
示例9: parseDate
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
//
//
// Parse a date string
//
//
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
void dataHandlerDateTimeBase::parseDate(
std::wstring dateString,
imbxInt32* pYear,
imbxInt32* pMonth,
imbxInt32* pDay)
{
PUNTOEXE_FUNCTION_START(L"dataHandlerDateTimeBase::parseDate");
if(dateString.size()<8)
dateString.resize(8, L'0');
std::wstring dateYear=dateString.substr(0, 4);
std::wstring dateMonth=dateString.substr(4, 2);
std::wstring dateDay=dateString.substr(6, 2);
std::wistringstream yearStream(dateYear);
yearStream >> (*pYear);
std::wistringstream monthStream(dateMonth);
monthStream >> (*pMonth);
std::wistringstream dayStream(dateDay);
dayStream >> (*pDay);
PUNTOEXE_FUNCTION_END();
}
示例10: get_value
static LSTATUS get_value(HKEY hKey, const wchar_t* lpValueName, std::wstring& value)
{
DWORD type = REG_NONE, size = 0;
LSTATUS res = RegQueryValueExW(hKey, lpValueName, NULL, &type, NULL, &size);
size /= sizeof(wchar_t);
if (res == ERROR_SUCCESS && ((type != REG_EXPAND_SZ && type != REG_SZ) || size > max_string_size))
return ERROR_INVALID_DATA;
if (size == 0)
return res;
value.resize(size);
res = RegQueryValueExW(hKey, lpValueName, NULL, &type, reinterpret_cast< LPBYTE >(&value[0]), &size);
value.resize(std::wcslen(value.c_str())); // remove extra terminating zero
return res;
}
示例11: GetValue
bool CRegUtil::GetValue(const wchar_t* const name, std::wstring& strValue)
{
const int nSize = 1024;
std::vector<BYTE> buffer;
DWORD dwLength = 0;
DWORD dwType = REG_NONE;
buffer.resize(nSize);
void* pBuffer = &buffer[0];
LONG lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
if((lResult != ERROR_MORE_DATA && lResult != ERROR_SUCCESS)
|| (dwType != REG_SZ)
|| dwLength == 0)
{
return false;
}
if(lResult == ERROR_MORE_DATA)
{
buffer.resize(dwLength);
pBuffer = &buffer[0];
lResult = ::RegQueryValueEx(m_hKey, name, 0, &dwType, (LPBYTE)pBuffer, &dwLength);
}
if(lResult != ERROR_SUCCESS)
return false;
strValue.assign((const wchar_t*)pBuffer, dwLength / sizeof(wchar_t));
if(strValue.at(strValue.size() - 1) == 0)
strValue.resize(strValue.size() - 1);
return true;
}
示例12: GetValue
bool Cx_StringTable::GetValue(std::wstring& value,
const std::wstring& module, const std::wstring& id)
{
if (!m_loaded)
{
LoadFiles(x3::GetTranslationsPath(L"strings"));
LoadFiles(x3::RelToAbsWithPlugin(L"../translations/strings", false));
}
IT_ITEM it = Find(module);
value.resize(0);
if (it != m_groups.end())
{
Cx_ConfigSection group(it->group);
ASSERT(group.IsNotNull());
Cx_ConfigSection sec(group.GetSection(L"string", L"id", id.c_str(), false));
value = sec->GetString(L"value");
ReplaceLf(value);
}
return !value.empty();
}
示例13: CopyFiles
/*
** Copies files and folders from one location to another.
**
*/
bool System::CopyFiles(std::wstring from, std::wstring to, bool bMove)
{
// If given "from" path ends with path separator, remove it (Workaround for XP: error code 1026)
size_t len;
while (len = from.size(), len > 0 && PathUtil::IsSeparator(from[len - 1]))
{
from.resize(len - 1);
}
// The strings must end with double \0
from.append(1, L'\0');
to.append(1, L'\0');
SHFILEOPSTRUCT fo =
{
nullptr,
bMove ? FO_MOVE : FO_COPY,
from.c_str(),
to.c_str(),
FOF_NO_UI | FOF_NOCONFIRMATION | FOF_ALLOWUNDO
};
int result = SHFileOperation(&fo);
if (result != 0)
{
LogErrorF(L"Copy error: From %s to %s (%i)", from.c_str(), to.c_str(), result);
return false;
}
return true;
}
示例14: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
dir = argv[0];
dir.resize(dir.find_last_of(_T("\\")) + 1);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
示例15: GetFromLetras
/*
** GetFromLetras
**
** Download lyrics from Letras.
**
*/
bool CLyrics::GetFromLetras(const std::wstring& artist, const std::wstring& title, std::wstring& data)
{
bool ret = false;
std::wstring url = L"http://letras.terra.com.br/winamp.php?musica=" + title;
url += L"&artista=";
url += artist;
data = CInternet::DownloadUrl(url, CP_ACP);
if (!data.empty())
{
std::wstring::size_type pos = data.find(L"\"letra\"");
pos = data.find(L"<p>", pos);
if (pos != std::wstring::npos)
{
pos += 3;
data.erase(0, pos);
pos = data.find(L"</p>");
data.resize(pos);
CInternet::DecodeReferences(data);
while ((pos = data.find(L"<br/>"), pos) != std::wstring::npos)
{
data.erase(pos, 5);
}
ret = true;
}
}
return ret;
}