HRESULT URLParser::ParseVideoURL(std::wstring& wstrURL, std::wstring& wstrVideoURL) { HRESULT hr = E_FAIL; std::wstring wstrNormalizedURL; URLParser::VIDEO_URL_PARSER eVideoURLParser; int iCount = 0; if(0 == wstrURL.find(L"http://")) { iCount += wcslen(L"http://"); } if(iCount == wstrURL.find(L"www.")) { iCount += wcslen(L"www."); } if(iCount == wstrURL.find(L"youtube")) { eVideoURLParser = URLParser::YOUTUBE_VIDEO_URL_PARSER; hr = GetVideoInfoURL(eVideoURLParser, wstrURL, wstrVideoURL ); } /* else if(OTHER_VIDEO_PARSERS) { // For Future } */ return hr; }
HRESULT URLParser::GetVideoInfoURL(URLParser::VIDEO_URL_PARSER eVideoURLParser, std::wstring& wstrURL, std::wstring& wstrVideoURL) { HRESULT hr = E_FAIL; int iVdoIDStart = -1; int iVdoIDEnd = -1; std::wstring wstrVideoID; if(std::wstring::npos != (iVdoIDStart = wstrURL.find(L"v="))) { iVdoIDStart += wcslen(L"v="); iVdoIDEnd = wstrURL.find(L"&", iVdoIDStart); if(std::wstring::npos != iVdoIDEnd) { // pick start to end wstrVideoID = wstrURL.substr(iVdoIDStart, (iVdoIDEnd - iVdoIDStart)); } else { // pick the entire string wstrVideoID = wstrURL.substr(iVdoIDStart, (wstrURL.length() - iVdoIDStart)); } } if(0 != wstrVideoID.length()) { wstrVideoURL.clear(); wstrVideoURL.assign(PRE_VIDEO_ID_URL_STRING); wstrVideoURL.append(wstrVideoID); wstrVideoURL.append(POST_VIDEO_ID_URL_STRING); hr = S_OK; } return hr; }
int FirstInvalidDirSeparatorSizetap(std::wstring& aPath, std::wstring::size_type& aIndex) { // If path semantics is correct (as needed by sisx library) // then the function will return 0 int ret = 0; int pos = 0; #ifdef __LINUX__ if((pos = aPath.find(L"\\\\", aIndex)) != std::wstring::npos) #else if((pos = aPath.find(L"//", aIndex)) != std::wstring::npos) #endif { ret = 2; } #ifdef __LINUX__ else if((pos = aPath.find(L"\\", aIndex)) != std::wstring::npos) #else else if((pos = aPath.find(L"/", aIndex)) != std::wstring::npos) #endif { ret = 1; } aIndex = pos; return ret; }
void ReplaceWString(std::wstring & str, const std::wstring & find, const std::wstring & replace) { for(auto i = str.find(find); i != std::wstring::npos ;i = str.find(find)) { str.replace(i, find.size(), replace); } }
int FacadeDocumentProviderImpl::CalculateFormatIndex(const std::wstring& formatString, std::wstring extension) { if (extension[0] == L'.') extension = extension.substr(1); std::wstring filter = L"*." + CStdStringW(extension).ToLower(); unsigned int iPos = (unsigned int) -1; int iIndex = 1; while (true) { iPos = (x64_int_cast)formatString.find(L"|", iPos+1); if (iPos == formatString.npos) return 1; int startPos = iPos; iPos = (x64_int_cast)formatString.find(L"|", iPos+1); if (iPos == formatString.npos) return 1; int endPos = iPos; std::wstring thisFormat = formatString.substr(startPos+1, endPos-startPos-1); if (thisFormat.find(filter) != thisFormat.npos) return iIndex; iIndex++; iPos++; } return 1; }
/* ** Replaces %1, %2, ... with the corresponding measure value. ** */ bool Meter::ReplaceMeasures(std::wstring& str, AUTOSCALE autoScale, double scale, int decimals, bool percentual) { bool replaced = false; if (str.find(L'%') != std::wstring::npos) { WCHAR buffer[64]; for (size_t i = m_Measures.size(); i > 0; --i) { size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i); size_t start = 0, pos; const WCHAR* measureValue = m_Measures[i - 1]->GetStringOrFormattedValue( autoScale, scale, decimals, percentual); const size_t measureValueLen = wcslen(measureValue); do { pos = str.find(buffer, start, len); if (pos != std::wstring::npos) { str.replace(pos, len, measureValue, measureValueLen); start = pos + measureValueLen; replaced = true; } } while (pos != std::wstring::npos); } } return replaced; }
/* ** Replaces %1, %2 etc with the corresponding measure value */ bool CMeter::ReplaceMeasures(const std::vector<std::wstring>& stringValues, std::wstring& str) { bool replaced = false; if (str.find(L'%') != std::wstring::npos) { WCHAR buffer[64]; // Create the actual text (i.e. replace %1, %2, .. with the measure texts) for (size_t i = stringValues.size(); i > 0; --i) { size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%%%i", (int)i); size_t start = 0, pos; do { pos = str.find(buffer, start, len); if (pos != std::wstring::npos) { str.replace(pos, len, stringValues[i - 1]); start = pos + stringValues[i - 1].length(); replaced = true; } } while (pos != std::wstring::npos); } } return replaced; }
static std::wstring rawinput_device_improve_name(const std::wstring &name) { // The RAW name received is formatted as: // \??\type-id#hardware-id#instance-id#{DeviceClasses-id} // XP starts with "\??\" // Vista64 starts with "\\?\" // ensure the name is something we can handle if (name.find(L"\\\\?\\") != 0 && name.find(L"\\??\\") != 0) return name; std::wstring regpath = compute_device_regpath(name); bool hid = false; auto improved = improve_name_from_base_path(regpath, &hid); if (!improved.empty()) return improved; if (hid) { improved = improve_name_from_usb_path(regpath); if (!improved.empty()) return improved; } // Fall back to the original name return name; }
std::wstring Database::getParameterFromTag(std::wstring temp) { size_t pos; const size_t nExist = std::wstring::npos; pos = temp.find('"'); if ( pos != nExist) { temp.erase(0 , pos+1); pos = temp.find(L'"'); if ( pos != nExist) { temp.erase(pos); return temp; } else { std::wcout << L"Fehler 1, getParameterFromTag()" << std::endl; } } else { std::wcout << L"Fehler 2, getParameterFromTag()" << std::endl; } return L""; }
BOOL CImageUtility::IsLegalPath(std::wstring& wstrPathName) { TSAUTO(); size_t stPos1 = wstrPathName.find_first_of(L':'); size_t stPos2 = wstrPathName.find_first_of(L'\\'); BOOL bIsLegal = TRUE; if (1 != stPos1 || 2 != stPos2 || 3 > wstrPathName.length() || wstrPathName.find(_T("//")) != std::wstring::npos || wstrPathName.find(_T("\\\\")) != std::wstring::npos || wstrPathName.find(_T("/\\")) != std::wstring::npos || wstrPathName.find(_T("\\/")) != std::wstring::npos) { bIsLegal = FALSE; } if (wstrPathName.size() > 150) { bIsLegal = FALSE; } if (TRUE == bIsLegal) { TCHAR* szUnLegalChars = L"/:*?\"<>|"; std::wstring wstrPathNameWithoutHead = wstrPathName.substr(2); for (int i = 0; i < 8; ++i) { if (wstrPathNameWithoutHead.npos != wstrPathNameWithoutHead.find_first_of(szUnLegalChars[i])) { bIsLegal = FALSE; break; } } } return bIsLegal; }
std::wstring getTemplateFilter(const std::wstring & templateContent) { size_t idx_template = templateContent.find(L"$TEMPLATE_FILEFILTER:"); std::wstring line; if(idx_template != std::wstring::npos) { idx_template += wcslen(L"$TEMPLATE_FILEFILTER:"); size_t EOL = templateContent.find(L"\n", idx_template); if(EOL == std::wstring::npos) EOL = templateContent.size() - idx_template - 1; if(templateContent.at(EOL - 1) == L'\r') EOL--; if(EOL < idx_template) EOL = idx_template; line = templateContent.substr(idx_template, EOL - idx_template); } else { line = LoadWideString(IDS_FILTER); } for(size_t i = 0; i < line.size(); i++) if(line[i] == L'|') line[i] = L'\0'; line.push_back(L'\0'); return line; }
bool CheckEquLabel(std::wstring& str) { size_t s = str.find(L" equ "); if (s == std::string::npos) s = str.find(L":equ "); if (s != std::string::npos) { std::wstring name = str.substr(0,s); if (name.back() == ':') name.pop_back(); if (Global.symbolTable.isValidSymbolName(name) == false) { Logger::printError(Logger::Error,L"Invalid equation name %s",name); return true; } if (Global.symbolTable.symbolExists(name,Global.FileInfo.FileNum,Global.Section)) { Logger::printError(Logger::Error,L"Equation name %s already defined",name); return true; } std::wstring replacement = str.substr(s+5); Global.symbolTable.addEquation(name,Global.FileInfo.FileNum,Global.Section,replacement); return true; } return false; }
// --------------------------------------------------------------------------- // Name: vspPackageWrapper::outputMessage // Description: Send a text message to the output pane of visual studio // Arguments: gtString messageString // Return Val: void // Author: Gilad Yarnitzky // Date: 17/2/2011 // --------------------------------------------------------------------------- void vspPackageWrapper::outputMessage(const std::wstring& messageString, bool outputOnlyToLog) { // Add to log: VSCORE(vscPrintDebugMsgToDebugLog)(messageString.c_str()); if (!outputOnlyToLog) { IVsOutputWindowPane* spOutputWindowPane = getDebugPane(); VSP_ASSERT(spOutputWindowPane != NULL); if (spOutputWindowPane != NULL) { HRESULT rc = spOutputWindowPane->Activate(); bool isOk = (rc == S_OK); if (isOk) { std::wstring messageForOutputPane = messageString; // handle a case where the string begins with \n\n\n\n- we don't want to have many "CodeXL-" with no messege std::size_t found1 = messageString.find(VS_STR_NewLine); if (found1 == 0) { for (;;) { std::size_t found2 = messageString.find(VS_STR_NewLine, found1 + 2); if ((found2 != std::string::npos) && (found1 + 2) == found2) { found1 = found2; continue; } else { break; } } messageForOutputPane.insert(found1 + 1, VS_STR_CodeXLPrefix); } else { messageForOutputPane.insert(0, VS_STR_CodeXLPrefix); } messageForOutputPane += VS_STR_NewLine; // Add the message to the debug pane: BSTR oleMessageString = SysAllocString(messageForOutputPane.c_str()); spOutputWindowPane->OutputString(oleMessageString); SysFreeString(oleMessageString); // Reduce the reference count spOutputWindowPane->Release(); } } } }
std::wstring parseEngWordForEn(const std::wstring& innerW,const std::wstring& start,const std::wstring& end,int maxLine = 1 ) { int pos = 0; int endpos = 0; /* for(int i = 0 ; i < maxLine ; i ++ ) { endpos = innerW.find(L"。",endpos); if (endpos == std::wstring::npos) { endpos = innerW.size(); break; } endpos ++; //skip 。 } */ endpos = innerW.size(); int hit = innerW.find(start,pos); if (hit == std::wstring::npos || hit > endpos) { return L""; } hit += start.size(); int hyphenpos = innerW.find(L"|",hit); int closepos = innerW.find(end,hit); if (hyphenpos == std::wstring::npos) { if (closepos == std::wstring::npos) { return L""; } } else { if (closepos == std::wstring::npos) { closepos = hyphenpos; } else { if (closepos > hyphenpos) { closepos = hyphenpos; } } } if (closepos > endpos) { return L""; } std::wstring a = innerW.substr(hit , closepos - hit); a = cleaningYomi(a); return a; }
int CommandLineArguments::GetSwitchDelimiterLength(std::wstring arg) { if (arg.find(L"--") == 0) { return 2; } else if (arg.find(L"-") == 0 || arg.find(L"/") == 0) { return 1; } return 0; }
std::wstring Dialog::preInsert(Coord &, const std::wstring &value) { if ((answers_ & Yes) != 0 && value.find(L'y') != std::wstring::npos) result(Yes); if ((answers_ & No) != 0 && value.find(L'n') != std::wstring::npos) result(No); if ((answers_ & Cancel) != 0 && value.find(L'c') != std::wstring::npos) result(Cancel); return L""; }
std::wstring ReplaceCharWithString(std::wstring source, const wchar_t replaceChar, std::wstring replaceString) { size_t posn = source.find(&replaceChar); while (posn != std::wstring::npos) { source.replace(posn, 1, replaceString); posn = source.find(&replaceChar, posn + replaceString.length()); } return source; }
void ReplicaManagerWrapper::AddIncarnationIdIfNecessary(std::wstring & replica) { if (replica.find(L'@') == std::wstring::npos) { auto dex = replica.find(L':'); wstring r; StringWriter w(r); w << replica.substr(0, dex) << Constants::ReplicaIncarnationDelimiter << Common::Guid::NewGuid().ToString() << ':' << replica.substr(dex+1); replica = r; } }
bool SleepConsole::FindListSubCommand(std::wstring& input) { bool result = false; wstring diskListCommand(L"disks"); wstring currentOperations(L"current operations"); wstring pendingOperations(L"pending operations"); if(input.find(diskListCommand) != wstring::npos){ result = true; for(vector<DISKINFORMATION>::const_iterator iter = disks.begin(); iter != disks.end(); ++iter){ wstring diskName(L"Disk "); int diskNum = iter->DiskNumber; wchar_t buff[2] = {0}; _itow(diskNum, buff, 10); diskName += buff; wcout << diskName << endl; for(std::vector<VOLUMEPROPERTIES>::const_iterator itVol = iter->VOLUMES.begin(); itVol != iter->VOLUMES.end(); ++itVol){ wcout << L"\t" << itVol->MountPoint << endl; } } } else if(input.find(currentOperations) != wstring::npos){ consoleOperation = QUERY; if (GenerateCommandToSend()){ if (ApplyCommand()) result = true; } } else if(input.find(pendingOperations) != wstring::npos){ wchar_t* buffer = new wchar_t[80]; ZeroMemory(buffer, 80); result = true; if (sleephddQueue->empty()){ cout << "No pending operations!\n"; delete buffer; buffer = NULL; return result; } for(std::list<std::pair<std::wstring, Operations> >::iterator iter = sleephddQueue->begin(); iter != sleephddQueue->end(); iter++){ if(iter->second == ACTIVE) swprintf(buffer,L"Partition %s - Active\n", iter->first.c_str()); else swprintf(buffer,L"Partition %s - Locked\n", iter->first.c_str()); wcout << buffer; ZeroMemory(buffer, 80); } delete buffer; buffer = NULL; } else{ cout << "Not supported command!\n"; } return result; }
void Mouse::ReplaceMouseVariables(std::wstring& result) const { // Check for new-style variables: [$MOUSEX] m_Skin->GetParser().ParseVariables(result, ConfigParser::VariableType::Mouse, m_Meter); // Check for old-style variables: $MOUSEX$ size_t start = 0, end; bool loop = true; do { start = result.find(L'$', start); if (start != std::wstring::npos) { size_t si = start + 1; end = result.find(L'$', si); if (end != std::wstring::npos) { size_t ei = end - 1; if (si != ei && result[si] == L'*' && result[ei] == L'*') { result.erase(ei, 1); result.erase(si, 1); start = ei; } else { std::wstring strVariable = result.substr(si, end - si); std::wstring value = m_Skin->GetParser().GetMouseVariable(strVariable, m_Meter); if (!value.empty()) { // Variable found, replace it with the value result.replace(start, end - start + 1, value); start += value.length(); } else { start = end; } } } else { loop = false; } } else { loop = false; } } while (loop); }
/** * Split a string into elements as a newly created arrayBuffer * @param inBuf The CharArray to split along * @param splitChar The char to use as splitter * @param &argLen [OUT] The length of the Array * @param escape [IN] Set to true to try to escape ":s ie. //token1 "token2 with space" token3// * @return The arrayBuffer */ array_buffer::arrayBuffer array_buffer::split2arrayBuffer(const std::wstring inBuf, wchar_t splitChar, unsigned int &argLen, bool escape) { if (inBuf.empty()) return createEmptyArrayBuffer(argLen); std::wstring::size_type p1 = 0; std::wstring::size_type p2 = 0; std::list<std::wstring> token_list; while (p1 != std::wstring::npos && p2 != std::wstring::npos) { if (escape && inBuf[p1] == '\"') { p2 = inBuf.find('\"', p1+1); if (p2 != std::wstring::npos) p2 = inBuf.find(splitChar, p2); } else { p2 = inBuf.find(splitChar, p1); } if (p2 == std::wstring::npos) p2 = inBuf.size(); if (p1 == p2 && p1 != inBuf.size()) { p1++; continue; } // p1 = start of "this token" // p2 = end of "this token" (next split char) if (p2<=p1) throw ArrayBufferException("Invalid position"); std::wstring token = inBuf.substr(p1,p2-p1); if (escape && token[0] == '\"') token = token.substr(1); if (escape && token[token.size()-1] == '\"') token = token.substr(0, token.size()-1); token_list.push_back(token); if (p2 < inBuf.size()) p2++; if (p2 == inBuf.size()) p2 = std::wstring::npos; p1 = p2; } arrayBuffer arrayBuffer = new arrayBufferItem[token_list.size()]; argLen=0; for (std::list<std::wstring>::const_iterator cit=token_list.begin();cit!=token_list.end();++cit) { size_t len = (*cit).size(); wchar_t* token = new wchar_t[len+1]; wcsncpy(token, (*cit).c_str(), len); arrayBuffer[argLen++] = token; } token_list.clear(); return arrayBuffer; }
//----------------------------------------------------------------------------- void mglParser::PutArg(std::wstring &str, bool def) { size_t pos = str.find('$',def?10:0); while(pos<str.length()) { wchar_t ch = str[pos+1]; if(ch>='0' && ch<='9') str.replace(pos,2,par[ch-'0']); else if(ch>='a' && ch<='z') str.replace(pos,2,par[ch-'a'+10]); else if(ch=='$') str.replace(pos,2,L"\uffff"); else str.replace(pos,1,L"\uffff"); pos = str.find('$',def?10:0); } while((pos = str.find(L'\uffff'))<str.length()) str[pos]='$'; }
void CtriPOSOpenSSLHMACSampleDlg::ParseUri(std::wstring uri, std::string &scheme, std::string &host, std::string &port, std::string &path, std::string &query) { size_t findIndex = uri.find(L"://", 0); if (findIndex != std::string::npos) { scheme.assign(ToMultiByte(uri.substr(0, findIndex).c_str())); findIndex += 3; uri.erase(0, findIndex); } findIndex = uri.find(L"/", 0); if (findIndex != std::string::npos) { host.assign(ToMultiByte(uri.substr(0, findIndex).c_str())); uri.erase(0, findIndex); if (!host.empty()) { findIndex = host.find(":", 0); if (findIndex != std::string::npos) { port = host.substr(findIndex + 1); host.erase(findIndex); } } } findIndex = uri.find(L"?", 0); if (findIndex == std::string::npos) { path.assign(ToMultiByte(uri.c_str())); } else { path.assign(ToMultiByte(uri.substr(0, findIndex).c_str())); findIndex++; query.assign(ToMultiByte(uri.substr(findIndex).c_str())); } }
size_t StringUtil::split(std::vector<std::wstring>& vec, std::wstring str, wchar_t delim) { vec.clear(); std::wstring::size_type pos = str.find(delim); while(pos != std::wstring::npos) { vec.push_back(str.substr(0, pos)); str = str.substr(pos + 1); pos = str.find(delim); } vec.push_back(str); return vec.size(); }
size_t StringUtil::split(std::list<std::wstring>& list, std::wstring str, wchar_t delim) { list.clear(); std::wstring::size_type pos = str.find(delim); while(pos != std::wstring::npos) { list.push_back(str.substr(0, pos)); str = str.substr(pos + 1); pos = str.find(delim); } list.push_back(str); return list.size(); }
void CLocalPath::AddSegment(std::wstring const& segment) { std::wstring& path = m_path.get(); assert(!path.empty()); assert(segment.find(L"/") == std::wstring::npos); #ifdef FZ_WINDOWS assert(segment.find(L"\\") == std::wstring::npos); #endif if (!segment.empty()) { path += segment; path += path_separator; } }
std::wstring string_replace_all( std::wstring src, std::wstring const& target, std::wstring const& repl){ if (target.length() == 0) { // searching for a match to the empty string will result in // an infinite loop // it might make sense to throw an exception for this case return src; } if (src.length() == 0) { return src; // nothing to match against } size_t idx = 0; for (;;) { idx = src.find( target, idx); if (idx == std::wstring::npos) break; src.replace( idx, target.length(), repl); idx += repl.length(); } return src; }
std::wstring UeiArgsParser::convertVerbose(const std::wstring& aVerbose) { std::wostringstream arg; arg << SUPPORTED_JVM_ARGS[INDEX_VERBOSE]; if (aVerbose.find(OPTION_SEPARATOR) != std::wstring::npos) { arg << OPTION_SEPARATOR; if (hasOption(aVerbose, ALL)) { arg << JVM_SUPPORTED_VERBOSE_OPTIONS; } else { if (hasOption(aVerbose, GC)) { arg << GC << COMMA; } if (hasOption(aVerbose, CLASS)) { arg << CLASS << COMMA; } } } std::wstring result = arg.str(); std::wostringstream whitespaces; whitespaces << OPTION_SEPARATOR << COMMA; trimTrailingSpaces(result, whitespaces.str()); LOG2(EDebugApi, EInfo,"convertVerbose(%S): %S", aVerbose.c_str(), result.c_str()); return result; }
int TtfDisplay::getStringWidth(const std::wstring &str, HDC currDC, const std::wstring& filterStr, size_t filterLetterWidth) const { //Save if (currDC!=NULL) lastKnownGoodHDC = currDC; //Measure this item by its string. SIZE textSize; HFONT oldFont = NULL; if (font!=NULL) oldFont = (HFONT)SelectObject(lastKnownGoodHDC, font); GetTextExtentPoint32(lastKnownGoodHDC, str.c_str(), str.length(), &textSize); //Restore the DC if (oldFont!=NULL) SelectObject(lastKnownGoodHDC, oldFont); //Calculate the total number of ZWS letters size_t countZWS = 0; if (!filterStr.empty()) { for (size_t i=0; i<str.length(); i++) { if (filterStr.find(str[i])!=wstring::npos) countZWS++; } } //Done return textSize.cx + countZWS*filterLetterWidth; }
void DSNAttributes::Add(const std::wstring& namevaluepair) { CHECK_BOOL(namevaluepair.find(L"=") != namevaluepair.npos, L"Missing = in \"" << namevaluepair << L"\""); _attributes.push_back(namevaluepair); }