本文整理汇总了C++中wstring类的典型用法代码示例。如果您正苦于以下问题:C++ wstring类的具体用法?C++ wstring怎么用?C++ wstring使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wstring类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetProperty
BOOL MsiSession::SetProperty(LPCTSTR szMsiPorpeorty, const wstring& sVal)
{
return SetProperty(szMsiPorpeorty, sVal.c_str());
}
示例2: GetFileExtension
wstring GetFileExtension(wstring& FileName)
{
wstring tmp = FileName.substr(FileName.find_last_of(L".") + 1, FileName.length());
return tmp;
}
示例3: CrabStringFindWholeWord
wstring CrabStringFindWholeWord(const wstring &t, size_t pos, const wstring &BreakupMark, const wstring &BreakupMarkOnceMore)
{
wstring foundstr;
if(0==pos) {
wstring strR = t;
size_t foundposL = 0;
size_t foundposR = t.find(BreakupMark);
if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
}
}
if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
foundposR=foundposR-1;
}
foundstr = t.substr(foundposL,foundposR-foundposL+1);
} else if(t.length()-1==pos) {
wstring strL = t;
size_t foundposL = t.rfind(BreakupMark);
if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
}
}
if(wstring::npos==foundposL){foundposL=0;}else{
foundposL=foundposL+1;
}
size_t foundposR = t.length()-1;
foundstr = t.substr(foundposL,foundposR-foundposL+1);
} else if(0<pos && t.length()-1>pos) {
wstring strL = t.substr(0,pos);
wstring strR = t.substr(pos);
size_t foundposL = strL.rfind(BreakupMark);
if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
if(wstring::npos==foundposL){foundposL = strL.rfind(BreakupMarkOnceMore);}else{
if(strL.rfind(BreakupMarkOnceMore)>foundposL){foundposL=strL.rfind(BreakupMarkOnceMore);}
}
}
if(wstring::npos==foundposL){foundposL=0;}else{
foundposL=foundposL+1;
}
size_t foundposR = strR.find(BreakupMark);
if(BreakupMarkOnceMore.length()>0){ // <added><20150615><dzliu> use another BreakupMarkOnceMore
if(wstring::npos==foundposR){foundposR = strR.find(BreakupMarkOnceMore);}else{
if(strR.find(BreakupMarkOnceMore)<foundposR){foundposR=strR.find(BreakupMarkOnceMore);}
}
}
if(wstring::npos==foundposR){foundposR=t.length()-1;}else{
foundposR=foundposR-1+pos;
}
foundstr = t.substr(foundposL,foundposR-foundposL+1);
}
return foundstr;
}
示例4: toLowerCase
wstring toLowerCase(wstring str)
{
if (str.length())
_wcslwr_s(&str[0], str.length() + 1);
return str;
}
示例5: ws2s
string ws2s(wstring& inputws)
{
USES_CONVERSION;
return W2CA(inputws.c_str());
}
示例6: encode_string
void encode_string(const wstring& d) {
encode_string(d.c_str(), d.size());
}
示例7: UserCmd_Process
bool UserCmd_Process(uint client, const wstring &cmd)
{
returncode = DEFAULT_RETURNCODE;
if (!cmd.compare(L"/conn"))
{
// Prohibit jump if in a restricted system or in the target system
uint system = 0;
pub::Player::GetSystem(client, system);
if (system == set_iRestrictedSystemID
|| system == set_iTargetSystemID
|| GetCustomBaseForClient(client))
{
PrintUserCmdText(client, L"ERR Cannot use command in this system or base");
return true;
}
if (!IsDockedClient(client))
{
PrintUserCmdText(client, STR_INFO1);
return true;
}
if (!ValidateCargo(client))
{
PrintUserCmdText(client, STR_INFO2);
return true;
}
StoreReturnPointForClient(client);
PrintUserCmdText(client, L"Redirecting undock to Connecticut.");
transferFlags[client] = CLIENT_STATE_TRANSFER;
return true;
}
else if (!cmd.compare(L"/return"))
{
if (!ReadReturnPointForClient(client))
{
PrintUserCmdText(client, L"No return possible");
return true;
}
if (!IsDockedClient(client))
{
PrintUserCmdText(client, STR_INFO1);
return true;
}
if (!CheckReturnDock(client, set_iTargetBaseID))
{
PrintUserCmdText(client, L"Not in correct base");
return true;
}
if (!ValidateCargo(client))
{
PrintUserCmdText(client, STR_INFO2);
return true;
}
PrintUserCmdText(client, L"Redirecting undock to previous base");
transferFlags[client] = CLIENT_STATE_RETURN;
return true;
}
return false;
}
示例8: extract
__int64 extract(int fd,__int64 startOffset,__int64 endOffset ,const wstring &toDir,const wstring& prefix,bool printProgress)
{
LOG_DEBUG(L"Extracting block... %s", prefix.c_str());
wstring normailizedToDir= NormalizeDirPath(toDir);
struct archive *inArch;
struct archive *outArch;
struct archive_entry *entry;
int flags;
int r;
flags = ARCHIVE_EXTRACT_TIME;
flags |= ARCHIVE_EXTRACT_PERM;
flags |= ARCHIVE_EXTRACT_ACL;
flags |= ARCHIVE_EXTRACT_FFLAGS;
inArch = archive_read_new();
archive_read_support_format_all(inArch);
archive_read_support_compression_all(inArch);
uint64_t totalSize=0;
uint64_t totalWritten=0;
if (r = duck_read_open_fd(inArch, fd, 10240,startOffset,endOffset))
{
LOG_ERROR(L"Could not open fd");
return false;
}
while (true)
{
r = archive_read_next_header(inArch, &entry);
if (r == ARCHIVE_EOF)
{
break;
}
if (r < ARCHIVE_WARN)
{
Logger::logger.logCstr(true,L"archive_read_next_header-computing size returned error ",archive_error_string(inArch));
return false;
}
wstring path(archive_entry_pathname_w(entry));
if(!strIsPrefixed(path, prefix))
{
continue;
}
totalSize+=archive_entry_size(entry);
}
LOG_DEBUG(L"Computed size: %I64u" ,totalSize);
if(printProgress)
{
wprintf(L"Total size: %I64u bytes\n",totalSize);
}
outArch = archive_write_disk_new();
archive_write_disk_set_options(outArch, flags);
archive_read_close(inArch);
archive_read_free(inArch);
inArch = archive_read_new();
archive_read_support_format_all(inArch);
archive_read_support_compression_all(inArch);
if (r = duck_read_open_fd(inArch, fd, 10240,startOffset,endOffset))
{
LOG_ERROR(L"Could not open fd");
Logger::logger.logCstr(true,L"archive_read_next_header returned error ",archive_error_string(inArch));
return false;
}
//archive_read_extract_set_progress_callback(inArch,extractProgress,NULL);
while (true)
{
r = archive_read_next_header(inArch, &entry);
if (r == ARCHIVE_EOF)
{
LOG_DEBUG(L"EOF reached");
break;
}
if (r < ARCHIVE_WARN)
{
Logger::logger.logCstr(true,L"archive_read_next_header returned error ",archive_error_string(inArch));
return false;
}
if (r < ARCHIVE_OK)
{
Logger::logger.logCstr(true,L"archive_read_next_header returned ",archive_error_string(inArch));
//return false;
}
wstring path(archive_entry_pathname_w(entry));
if(!strIsPrefixed(path, prefix))
{
continue;
}
//remove prefix and dir seperator:
if (prefix != L"")
{
path = path.substr(prefix.length() + 1);
}
wstring s=normailizedToDir;
s+=path;
//.........这里部分代码省略.........
示例9: wmain
int wmain(int argc, wchar_t**argv){
wstring pCmdLine;
for (int i = 0; i < argc; i++)
{
pCmdLine += L' ';
pCmdLine += argv[i];
}
wchar_t path[MAX_PATH]= moduleDbg;
#else
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {
wchar_t path[MAX_PATH];
GetModuleFileNameW(NULL, path, MAX_PATH) ;
#endif
//let windows parse arguments find the arg after the log path token and use it
LPWSTR *arglist;
int nArgs;
arglist = CommandLineToArgvW(GetCommandLineW(), &nArgs);
LOG_DEBUG(L"Module path: %s",path);
wstring pathStr(path);
const wstring verbose(L"--verbose");
const wstring shouldLog(L"--log");
const wstring block2(L"--block2");
const wstring block2Path(L"--block2Path");
const wstring block2Target(L"--block2Target");
const wstring logpath(L"--logpath");
wstring cmd(pCmdLine);
Logger::logger.setVerbose(cmd.find(verbose)!=cmd.npos);
bool LoggerOn=cmd.find(shouldLog)!=cmd.npos;
Logger::logger.setOn(LoggerOn);
if(LoggerOn)
{
if(cmd.find(logpath)!=cmd.npos)
{
for(int i=0;i<nArgs-1;i++)
{
//check if the argument i equals logpath ("--logpath") which means the next argument is the log path
if(logpath.compare(arglist[i])==0)
{
if(!Logger::logger.openStream(wstring(arglist[i+1])))
{
//msg box?
//LOG_ERROR(L"Could not open log file stream : %s",arglist[i+1]);
}
}
}
}
else
{
wstring logPath(pathStr.substr(0,pathStr.find_last_of(L"/\\")) +L"/duckinstaller.log");
if(!Logger::logger.openStream(logPath))
{
//msg box?
//LOG_ERROR(L"Could not open log file stream : %s",logPath.c_str);
}
}
}
int selfFileHandle;
errno_t err = _wsopen_s( &selfFileHandle, path, _O_RDONLY, _SH_DENYWR, _S_IREAD );
if (err != 0)
{
LOG_DEBUG(L"Could not open self (err=%d): %s", (int)err,path);
return -1;
}
DuckFileDescriptor desc={0};
_lseek(selfFileHandle,-(long)(sizeof(desc)),SEEK_END);
size_t endOfDesc=_tell(selfFileHandle);
_read (selfFileHandle, (char*)&desc, sizeof(desc) );
LOG_DEBUG(L"Descriptor read %d %d %d %d %d %d",desc.crc32, desc.magicNum,desc.block1Offset, desc.block2Offset, desc.varDescOffset, desc.version);
if(desc.magicNum== ND_MAGIC_NUM&&desc.version==ND_VER)
{
if(cmd.find(block2)!=cmd.npos)
{
wstring extractFromPath;
wstring targetPath(pathStr.substr(0,pathStr.find_last_of(L"/\\")));
for(int i=0;i<nArgs-1;i++)
{
if(block2Path.compare(arglist[i])==0)
{
extractFromPath=arglist[i+1];
}
else if( block2Target.compare(arglist[i])==0)
{
targetPath=arglist[i+1];
}
//.........这里部分代码省略.........
示例10: setcol
void NCurses_Editor::LineDraw( const wstring& sViewWStr,
int nY,
int nN,
int nTextNum,
int nNum)
{
setcol(_tColorEdit, _pWin);
wmove(_pWin, nY, nN);
int nBoxLine = 0;
if ( _bFullScreen )
nBoxLine = 0;
else
nBoxLine = 1;
whline(_pWin, ' ', width-(nBoxLine*2));
if (_bLineNumView == true)
{
setcol(_tColorEditInfo, _pWin);
mvwprintw(_pWin, nY, nN+1, "%*d", _nLineWidth, nTextNum+1);
setcol(_tColorEditInfo, _pWin);
mvwhline(_pWin, nY, nN+_nLineWidth+1, VLINE, 1);
nN = 3+_nLineWidth+nN;
}
string sTab;
sTab.append(1, (char)TABCONVCHAR);
if (_EditMode == EDIT)
{
string sViewStr = wstrtostr(sViewWStr);
string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
setcol(_tColorEdit, _pWin);
mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
}
else if (_EditMode == SELECT || _EditMode == SHIFT_SELECT)
{
EditSelect tEditSelect = _EditSelect;
SelectSort(&tEditSelect);
int x1 = tEditSelect.x1;
int x2 = tEditSelect.x2;
wstring sLineWStr = _vText[nTextNum];
wstring sWStr;
StrLineToken tStrLineToken;
tStrLineToken.SetWString(sLineWStr, _nCulumn);
int nCurSize = 0;
for (int n = 0; n<tStrLineToken.LineSize(); n++)
{
sWStr = tStrLineToken.GetLineStr(n);
if (n == nNum) break;
nCurSize=nCurSize+sWStr.size();
}
int nCurEndSize = nCurSize+sViewWStr.size();
if (tEditSelect.x1 > nCurSize) x1 = tEditSelect.x1 - nCurSize;
if (tEditSelect.x2 > nCurSize) x2 = tEditSelect.x2 - nCurSize;
if (tEditSelect.y1 == nTextNum && tEditSelect.y2 == nTextNum)
{
if (tEditSelect.x1 >= nCurSize && tEditSelect.x2 <= nCurEndSize)
{
SelectionDraw(sViewWStr, nY, nN, x1, x2);
}
else if (tEditSelect.x1 >= nCurSize && tEditSelect.x2 > nCurEndSize)
{
SelectionDraw(sViewWStr, nY, nN, x1, sViewWStr.size());
}
else if (tEditSelect.x1 < nCurSize && tEditSelect.x2 > nCurSize)
{
SelectionDraw(sViewWStr, nY, nN, 0, x2);
}
else if (tEditSelect.x1 < nCurSize && tEditSelect.x2 > nCurEndSize)
{
string sViewStr = wstrtostr(sViewWStr);
string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
setrcol(_tColorEdit, _pWin); // 반전
mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
}
else
{
string sViewStr = wstrtostr(sViewWStr);
string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
setcol(_tColorEdit, _pWin);
mvwprintw(_pWin, nY, nN, "%s", sViewStr2.c_str());
}
}
else if (tEditSelect.y1 == nTextNum)
{
if (tEditSelect.x1 >= nCurSize)
{
SelectionDraw(sViewWStr, nY, nN, x1, sViewWStr.size());
string sViewStr = wstrtostr(sViewWStr);
string sViewStr2 = MLSUTIL::Replace(sViewStr, sTab.c_str(), " "); // Tab -> Space
//.........这里部分代码省略.........
示例11: s
void Logger::logCstr(bool error,const wstring & prefix,const char * str)
{
string s(str);
wstring wideS(convertToWideString(s));
log(!error,L"%s : %s",prefix.c_str(),wideS.c_str());
}
示例12: upcase
wstring upcase(const wstring& str) {
Buffer<wchar_t> up_str(str.size());
wmemcpy(up_str.data(), str.data(), str.size());
CharUpperBuffW(up_str.data(), static_cast<DWORD>(up_str.size()));
return wstring(up_str.data(), up_str.size());
}
示例13: set_str_nt
bool Key::set_str_nt(const wchar_t* name, const wstring& value) {
LONG res = RegSetValueExW(h_key, name, 0, REG_SZ, reinterpret_cast<LPBYTE>(const_cast<wchar_t*>(value.c_str())), (static_cast<DWORD>(value.size()) + 1) * sizeof(wchar_t));
if (res != ERROR_SUCCESS) {
SetLastError(res);
return false;
}
return true;
}
示例14: while
void StringParser::Parse( const string& key, const wstring& text, StringParser::StringItem* item )
{
item->m_Key = key;
item->m_Text = text;
int i = 0;
int j = 0;
int k = 0;
bool hasError = false;
while( true )
{
for( int x=i; x<text.length(); ++x )
{
if( text[x] == L'{' && x < text.length()-1 && text[x+1] == L'%' )
{
i = x;
break;
}
}
//i = text.find_first_of( L"{%", i );
if( i < 0 )
break;
/// 0123{%s1}
/// 012345678
if( text.length() < i+5 )
break;
wchar_t typeChar = text.at( i+2 );
/// 0123{%{%s1}
if( typeChar != L's'
&& typeChar != L'S'
&& typeChar != L'd'
&& typeChar != L'D'
&& typeChar != L'i'
&& typeChar != L'I'
&& typeChar != L'f'
&& typeChar != L'F' )
{
i += 2;
continue;
}
j = text.find_first_of( L"}", i+4 );
if( j < 0 )
break;
int indexLen = j - i - 3;
/// 0123{%s}8
if( indexLen < 1 )
{
i = j + 1;
continue;
}
/// Ö»Ö§³Ö1-99µÄÐòºÅ
/// 0123{%s100}
if( indexLen > 2 )
{
i = j + 1;
continue;
}
wstring indexStr = text.substr( i+3, indexLen );
/// ÅжÏÊÇ·ñÊÇÊý×Ö
if( indexStr < L"0" || indexStr > L"99" )
{
break;
}
int index = We::Type::ToInt( indexStr );
if( index <= 0 )
{
_LogError( string("StringParser::Parse Error : ") + key );
hasError = true;
break;
}
item->m_Indexes.push_back( index );
item->m_Texts.push_back( text.substr( k, i-k ) );
k = j + 1;
i = j + 1;
}
item->m_Texts.push_back( text.substr( k, text.length()-k ) );
/// ¼ì²éÐòºÅÊÇ·ñÓÐÎó
for( int i=0; i<item->m_Indexes.size(); ++i )
{
/// ÐòºÅ³¬³ö·¶Î§
if( item->m_Indexes[i] > item->m_Indexes.size() )
{
_LogError( string("StringParser::Parse Error : ") + key );
hasError = true;
break;
}
/// ÐòºÅÖظ´
for( int j=i+1; j<item->m_Indexes.size(); ++j )
{
if( item->m_Indexes[i] == item->m_Indexes[j] )
{
_LogError( string("StringParser::Parse Error : ") + key );
hasError = true;
break;
}
}
}
if( hasError )
{
item->m_Texts.clear();
item->m_Indexes.clear();
//.........这里部分代码省略.........
示例15: EnumerateBoots
void EnumerateBoots(wstring dir, int& count)
{
// check for skip-path
if (wcsicmp(dir.c_str(),_bootserv_config._random_skip.c_str())==0)
{
LOG1S(L"skipping {%s}: boots from this folder can ONLY BE ASSIGNED MANUALLY (using map.txt)", dir.c_str());
return;
}
WIN32_FIND_DATA fData;
wstring pattern(dir);
pattern += L"*";
HANDLE hff = FindFirstFile(pattern.c_str(), &fData);
if (hff == INVALID_HANDLE_VALUE)
{
// none found.
return;
}
while(true)
{
// bounds check
if (count >= MAX_BOOTS)
{
LOG1N(L"ERROR in bootserver: Too many boots (MAX supported = %d). Random boot enumeration stopped.", MAX_BOOTS);
break;
}
// check if this is a directory
if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
&& wcscmp(fData.cFileName,L".")!=0
&& wcscmp(fData.cFileName,L"..")!=0)
{
wstring nestedDir(dir);
nestedDir += fData.cFileName;
nestedDir += L"\\";
EnumerateBoots(nestedDir, count);
}
else if ((fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
{
// check for ".bin" extension. This way we have
// a little bit of protection against other types
// of files in boots folder.
int flen = wcslen(fData.cFileName);
if (wcsicmp(fData.cFileName+flen-4, L".bin")==0)
{
int idx = FIRST_RANDOM_BOOT_SLOT + count;
wstring bootFile(dir);
bootFile += L"\\";
bootFile += fData.cFileName;
if (k_bootserv.debug)
LOG1N1S(L"random boot: %d <-- {%s}", idx, bootFile.c_str());
_fast_bin_table[idx - FIRST_EXTRA_BOOT_SLOT] =
new wstring(bootFile);
count++;
}
}
// proceed to next file
if (!FindNextFile(hff, &fData)) break;
}
FindClose(hff);
}