本文整理汇总了C++中wstring类的典型用法代码示例。如果您正苦于以下问题:C++ wstring类的具体用法?C++ wstring怎么用?C++ wstring使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了wstring类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: SetProperty
BOOL MsiSession::SetProperty(LPCTSTR szMsiPorpeorty, const wstring& sVal)
{
return SetProperty(szMsiPorpeorty, sVal.c_str());
}
开发者ID:theMike,项目名称:WindowsInstaller,代码行数:4,代码来源:MsiSession.cpp
示例2: GetFileExtension
wstring GetFileExtension(wstring& FileName)
{
wstring tmp = FileName.substr(FileName.find_last_of(L".") + 1, FileName.length());
return tmp;
}
开发者ID:xmoeproject,项目名称:X-moe,代码行数:5,代码来源:M2Packer.cpp
示例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;
}
开发者ID:1054,项目名称:Crab,代码行数:54,代码来源:CrabStringFindWholeWord.cpp
示例4: toLowerCase
wstring toLowerCase(wstring str)
{
if (str.length())
_wcslwr_s(&str[0], str.length() + 1);
return str;
}
开发者ID:dearmark,项目名称:Fire-IE,代码行数:6,代码来源:strutils.cpp
示例5: ws2s
string ws2s(wstring& inputws)
{
USES_CONVERSION;
return W2CA(inputws.c_str());
}
开发者ID:bblr001,项目名称:MVS,代码行数:5,代码来源:Tools.cpp
示例6: encode_string
void encode_string(const wstring& d) {
encode_string(d.c_str(), d.size());
}
开发者ID:FarGroup,项目名称:FarManager,代码行数:3,代码来源:rsrc.cpp
示例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;
}
开发者ID:HeIIoween,项目名称:FLHook,代码行数:69,代码来源:Main.cpp
示例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;
//.........这里部分代码省略.........
开发者ID:asafamr,项目名称:nd-pack,代码行数:101,代码来源:nd_extractor.cpp
示例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];
}
//.........这里部分代码省略.........
开发者ID:asafamr,项目名称:nd-pack,代码行数:101,代码来源:nd_extractor.cpp
示例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
//.........这里部分代码省略.........
开发者ID:roderico,项目名称:linm,代码行数:101,代码来源:ncurses_editor.cpp
示例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());
}
开发者ID:asafamr,项目名称:nd-pack,代码行数:6,代码来源:nd_extractor.cpp
示例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());
}
开发者ID:landswellsong,项目名称:FAR,代码行数:6,代码来源:sysutils.cpp
示例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;
}
开发者ID:landswellsong,项目名称:FAR,代码行数:8,代码来源:sysutils.cpp
示例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();
//.........这里部分代码省略.........
开发者ID:xpisceo,项目名称:hobbyDemo,代码行数:101,代码来源:WeStringParser.cpp
示例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);
}
开发者ID:kitserver,项目名称:kitserver8,代码行数:65,代码来源:bootserv.cpp
示例16: isDate
int
Dictionary::operator[](const wstring & word)
{
return word.size() == 1 || isDate(word) || isEnglish(word)
|| isNumeric(word) || _dict[word];
}
开发者ID:jokerlee,项目名称:college,代码行数:6,代码来源:segmentor.cpp
示例17:
void d2d::ShowText(wstring strText, D2D1_RECT_F position)
{
m_pRenderTarget->DrawText(strText.c_str(), strText.size(),
m_pTextFormat, position, m_pBlackBrush, D2D1_DRAW_TEXT_OPTIONS_CLIP);
}
开发者ID:wangzhimin,项目名称:WzmPoker,代码行数:5,代码来源:d2d.cpp
示例18: toUpperCase
wstring toUpperCase(wstring str)
{
if (str.length())
_wcsupr_s(&str[0], str.length() + 1);
return str;
}
开发者ID:dearmark,项目名称:Fire-IE,代码行数:6,代码来源:strutils.cpp
示例19: fix_slashes
void fix_slashes(wstring& path) {
for (size_t i = 0; i < path.size(); i++) {
if (path[i] == L'/') path[i] = L'\\';
}
}
开发者ID:CyberShadow,项目名称:FAR,代码行数:5,代码来源:gendep.cpp
示例20: insertReplacedString
// See https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace#Specifying_a_string_as_a_parameter
// Some tricky test cases:
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$001"): "$001"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$01"): "a"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$10"): "j"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$15"): "a5"
// "abcdefghijklmn".replace(/(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)(m)(n)/, "$20"): "b0"
void insertReplacedString(wstring& builder, const wstring& base, const wstring& str, const RegExpMatch& match)
{
const vector<wstring>& substrings = match.substrings;
const wstring& mstr = substrings[0];
for (size_t i = 0; i < str.length(); i++)
{
if (str[i] == L'$' && str.length() > i + 1)
{
wchar_t ch = str[++i];
switch (ch)
{
case L'$': // insert a '$'
builder.push_back(ch);
break;
case L'&': // insert the matched string
builder.append(mstr);
break;
case L'`': // insert the portion preceding the matched string
builder.append(base.begin(), base.begin() + match.index);
break;
case L'\'': // insert the portion following the matched string
builder.append(base.begin() + match.index + mstr.length(), base.end());
break;
default:
if (ch >= L'0' && ch <= L'9')
{
int expidx = 0;
wchar_t ch2 = str.length() > i + 1 ? str[i + 1] : L'\0';
if (ch2 >= L'0' && ch2 <= L'9')
{
expidx = ch2 - L'0' + 10 * (ch - L'0');
// if expidx overflows, fall back to single-digit
if (expidx == 0 || expidx >= (int)substrings.size())
{
expidx = ch - L'0';
ch2 = 0;
}
}
else
{
ch2 = 0;
expidx = ch - L'0';
}
// substrings.size() is 1 bigger than actual sub matches
if (expidx < (int)substrings.size() && expidx > 0)
{
const wstring& submstr = substrings[expidx];
builder.append(submstr);
if (ch2) ++i;
break;
}
}
// $ escape fails, output as is
builder.push_back(L'$');
builder.push_back(ch);
}
}
else builder.push_back(str[i]);
}
}
开发者ID:dearmark,项目名称:Fire-IE,代码行数:67,代码来源:strutils.cpp
注:本文中的wstring类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论