当前位置: 首页>>代码示例>>C++>>正文


C++ wstring::substr方法代码示例

本文整理汇总了C++中std::wstring::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ wstring::substr方法的具体用法?C++ wstring::substr怎么用?C++ wstring::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::wstring的用法示例。


在下文中一共展示了wstring::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CreateLnkPath

BOOL install_util::CreateLnkPath(std::wstring wsSourceFilePath, std::wstring wsDestLnkPath, std::wstring wsArgument, std::wstring wsAppId)
{
  IShellLink *pisl = NULL;
  HRESULT hr = CoCreateInstance(CLSID_ShellLink,
    NULL,
    CLSCTX_INPROC_SERVER,
    IID_IShellLink,
    (void**)&pisl);
  if (FAILED(hr))
  {
    return FALSE;
  }

  pisl->SetPath(wsSourceFilePath.c_str());
  pisl->SetArguments(wsArgument.c_str());
  int nStart = wsSourceFilePath.find_last_of(_T("/\\")); 
  pisl->SetWorkingDirectory(wsSourceFilePath.substr(0,nStart).c_str());
  IPersistFile *plPF = NULL; 
  hr = pisl->QueryInterface(IID_IPersistFile, (void**)&plPF);
  bool shortcut_existed = false;
  if (SUCCEEDED(hr))
  {
    if (PathExists(wsDestLnkPath))
    {
      shortcut_existed = true;
      install_util::DeleteFile(wsDestLnkPath.c_str());
    }
	if (Win7OrLater() && !wsAppId.empty() && wsAppId.length() < 64)
	{
		IPropertyStore *piPS = NULL;
		if (SUCCEEDED(pisl->QueryInterface(IID_IPropertyStore, (void**)&piPS)))
		{
			PROPVARIANT property_value;
			if (SUCCEEDED(InitPropVariantFromString(wsAppId.c_str(), &property_value)))
			{
				if (piPS->SetValue(PKEY_AppUserModel_ID, property_value) == S_OK)
					piPS->Commit();
				PropVariantClear(&property_value);
			}
			piPS->Release();
		}
	}

    hr = plPF->Save(wsDestLnkPath.c_str(), TRUE);
    plPF->Release();
  }

  pisl->Release();
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);

  return SUCCEEDED(hr);
}
开发者ID:510908220,项目名称:setup,代码行数:52,代码来源:install_util.cpp

示例2: while

static std::list<std::wstring> _TokenizeString(const std::wstring& str, const wchar_t* delims) {
    std::list<std::wstring> components;

    std::size_t start = 0; // start from 0
    std::size_t delimPos = str.find_first_of(delims);

    while (start != std::wstring::npos) {
        components.emplace_back(str.substr(start, delimPos - start));
        start = str.find_first_not_of(delims, delimPos);
        delimPos = str.find_first_of(delims, start);
    }
    return components;
}
开发者ID:RG-J,项目名称:WinObjC,代码行数:13,代码来源:PathMapper.cpp

示例3: if

bool
MSCalibrationForm::parse_formula( const std::wstring& text, std::wstring& formula
							, std::wstring& adduct_lose, bool& isPositive ) const
{
    adduct_lose.clear();

    std::wstring::size_type pos = text.find_first_of( L"+-" );
    if ( pos == std::wstring::npos ) {
        formula = text;
        return !formula.empty();
    } else {
		formula = text.substr( 0, pos);
		if ( text.at( pos ) == L'+' )
			isPositive = true;
		else if ( text.at( pos ) == L'-' )
			isPositive = false;
		else
			return false;
		adduct_lose = text.substr( pos + 1 );
	}
    return true;
}
开发者ID:hermixy,项目名称:qtplatz,代码行数:22,代码来源:mscalibrationform.cpp

示例4: StringSplit

//------------------------------------------------------------------------|
void MGUtils::StringSplit(std::wstring& str, std::wstring& delim, std::vector<std::wstring>& result)
{
	int start = 0;
	int end = str.find_first_of(delim);
	if(end != -1)
	{
		while(end != -1)
		{
			result.push_back(str.substr(start, end - start));
			start = end + 1;
			end = str.find_first_of(delim, start);
			if(end == -1)
			{
				result.push_back(str.substr(start));
			}
		}
	}
	else
	{
		result.push_back(str.substr(start));
	}
}
开发者ID:mangeg,项目名称:MG3,代码行数:23,代码来源:MGUtils.cpp

示例5: StripFile

// Strips the filename and leaves the path
std::wstring CInjector::StripFile(std::wstring filePath)
{
	int pos = -1;
	for (int k = 0; k < filePath.length(); k++)
		if (filePath[k] == L'\\')
			pos = k;

	if (pos != -1) {
		return filePath.substr(0, pos+1);
	} else {
		return L"";
	}
}
开发者ID:infobeisel,项目名称:MBServerSwapper,代码行数:14,代码来源:injector.cpp

示例6: ReadAssetsDirectory

void DevelopmentResourceZipFile::ReadAssetsDirectory(std::wstring fileSpec)
{
      HANDLE fileHandle;
      WIN32_FIND_DATA findData;
 
      // get first file
	  std::wstring pathSpec = m_AssetsDir + fileSpec;
      fileHandle = FindFirstFile( pathSpec.c_str(), &findData );
      if( fileHandle != INVALID_HANDLE_VALUE )
      {
           // loop on all remeaining entries in dir
            while( FindNextFile( fileHandle,&findData ) )
            {
				if (findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
					continue;

				std::wstring fileName = findData.cFileName; 
				if( findData.dwFileAttributes &FILE_ATTRIBUTE_DIRECTORY )
				{
					if (fileName != L".." && fileName != L".")
					{
						fileName = fileSpec.substr(0, fileSpec.length()-1) + fileName + L"\\*";
						ReadAssetsDirectory(fileName);
					}
				}
				else
				{
					fileName = fileSpec.substr(0, fileSpec.length()-1) + fileName;
					std::wstring lower = fileName;
					std::transform(lower.begin(), lower.end(), lower.begin(), (int(*)(int)) std::tolower);
					wcscpy_s(&findData.cFileName[0], MAX_PATH, lower.c_str());
					m_DirectoryContentsMap[ws2s(lower)] = m_AssetFileInfo.size();
					m_AssetFileInfo.push_back(findData);
				} 
            }
      } 

      FindClose( fileHandle );
}
开发者ID:AsbjoernS,项目名称:gamecode4,代码行数:39,代码来源:ResCache.cpp

示例7: GetExtendedLengthPath

// Extends the length limit from 260 to 32767 characters
// See: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx#maxpath
std::wstring GetExtendedLengthPath(const std::wstring& path) {
  const std::wstring prefix = L"\\\\?\\";

  if (StartsWith(path, prefix))
    return path;

  // "\\computer\path" -> "\\?\UNC\computer\path"
  if (StartsWith(path, L"\\\\"))
    return prefix + L"UNC\\" + path.substr(2);

  // "C:\path" -> "\\?\C:\path"
  return prefix + path;
}
开发者ID:Hydro8182,项目名称:taiga,代码行数:15,代码来源:file.cpp

示例8: cleaningYomiForWord

static std::wstring cleaningYomiForWord(const std::wstring& yomi,const std::wstring& word)
{
	int pos = yomi.find(word);
	if (pos != std::wstring::npos)
	{
		if (pos == 0)
		{
			return L"";
		}
		return yomi.substr(0,pos);
	}
	return yomi;
}
开发者ID:rti7743,项目名称:wiki2dic,代码行数:13,代码来源:wiki2eng.cpp

示例9: addUnparsedMessage

void ChatBackend::addUnparsedMessage(std::wstring message)
{
	// TODO: Remove the need to parse chat messages client-side, by sending
	// separate name and text fields in TOCLIENT_CHAT_MESSAGE.

	if (message.size() >= 2 && message[0] == L'<')
	{
		std::size_t closing = message.find_first_of(L'>', 1);
		if (closing != std::wstring::npos &&
				closing + 2 <= message.size() &&
				message[closing+1] == L' ')
		{
			std::wstring name = message.substr(1, closing - 1);
			std::wstring text = message.substr(closing + 2);
			addMessage(name, text);
			return;
		}
	}

	// Unable to parse, probably a server message.
	addMessage(L"", message);
}
开发者ID:Bassa31,项目名称:minetest,代码行数:22,代码来源:chat.cpp

示例10: split

		std::vector<std::wstring> split(const std::wstring& str, const std::wstring& sep)
		{
			std::vector<std::wstring> ret;
			for (size_t pos = 0; pos <= str.size();)
			{
				size_t new_pos = str.find(sep, pos);
				if (std::string::npos == new_pos)
					new_pos = str.size();
				ret.push_back(str.substr(pos, new_pos - pos));
				pos = new_pos + sep.size();
			}
			return ret;
		}
开发者ID:thebluefish,项目名称:AOReconstruct,代码行数:13,代码来源:Utils.cpp

示例11: createEmptyArrayBuffer

/**
 * 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;
}
开发者ID:jkells,项目名称:nscp,代码行数:59,代码来源:arrayBuffer.cpp

示例12: XmlEncode

bool XmlEncode(std::wstring& data, int nMaxCount)
{
    if ((int)data.size() > nMaxCount)
    {
        data = data.substr(0, nMaxCount);
    }

    size_t nCount = 0;
    std::wstring buffer;
    buffer.reserve(data.size());
    for (size_t pos = 0; pos != data.size(); ++pos)
    {
        if (data[pos] == L'\n' || data[pos] == L'\r')
        {
            nCount = pos;
            break;
        }
        else if (data[pos] == L'&')
        {
            buffer.append(L"&amp;");
        }
        else if (data[pos] == L'\"')
        {
            buffer.append(L"&quot;");
        }
        else if (data[pos] == L'\'')
        {
            buffer.append(L"&apos;");
        }
        else if (data[pos] == L'<')
        {
            buffer.append(L"&lt;");
        }
        else if (data[pos] == L'>')
        {
            buffer.append(L"&gt;");
        }
        else if (data[pos] == L'\\')
        {
            buffer.append(L"\\\\");
        }
        else
        {
            buffer.append(&data[pos], 1);
        }
    }

    data.swap(buffer);

    return nCount > 0;
}
开发者ID:Microsoft,项目名称:WinAppDriver,代码行数:51,代码来源:UiTreeWalk.cpp

示例13: splitSectionAndKey

bool UIniConfig::splitSectionAndKey( std::wstring &formattedKey, wstring &sectionName, wstring &keyName )
{
    size_t slashIndex = formattedKey.find('/');
    if(slashIndex == wstring::npos)
    {
        //没有找到'/',sectionName为general。
        sectionName = L"";
        keyName = formattedKey;
    }
    else if(slashIndex == formattedKey.size()-1 || slashIndex == 0)
    {
        //假如第一个'/'出现在key的第一个字符或最后一个字符,则认为格式错误。
        assert(!"UConfig::set 键名格式错误,'/'不能为key的第一个或最后一个字符。");
        return false;
    }
    else
    {
        sectionName = formattedKey.substr(0,slashIndex);
        keyName = formattedKey.substr(slashIndex+1);
    }

    return true;
}
开发者ID:gauldoth,项目名称:UniCore,代码行数:23,代码来源:UConfig.cpp

示例14: StripPath

/// <summary>
/// Get filename from full-qualified path
/// </summary>
/// <param name="path">File path</param>
/// <returns>Filename</returns>
std::wstring Utils::StripPath( const std::wstring& path )
{
    if (path.empty())
        return path;

    auto idx = path.rfind( L'\\' );
    if(idx == path.npos)
        idx = path.rfind( L'/' );

    if (idx != path.npos)
        return path.substr( idx + 1 );
    else
        return path;
}
开发者ID:CaptainBigSmoke,项目名称:Blackbone,代码行数:19,代码来源:Utils.cpp

示例15: Import

bool ObjectImporter::Import(std::wstring file, ImportedObjectData* rawData)
{
	size_t first = file.find_last_of('\\') + 1;
	size_t last = file.find_last_of('.');
	rawData->name = file.substr(first, last-first);
	

	std::wifstream in (file);
	if(!in.is_open())
	{
		std::wstring msg = L"Failed to open file: \n";
		msg.append(file);
		MessageBox(0, msg.c_str(), L"Import error", 0);
		return false;
	}
	else
	{
		std::wstring buff;

		while (!in.eof())
		{
			in >> buff;

			if(buff.size())
			{
				if(buff == ObjImpFormat::animationCount) 
				{ 
					int count = 0;
					if(!ParseInteger(in, count))
						return false;

					if(count)
					{
						rawData->animations.resize(count);
						if(!ParseAnimationFile(in, rawData))
							return false;
					}
					else		
						if(!ParseStandardFile(in, rawData))
							return false;
				}
				else { ParseLine(in, true); }
			}
		}

		in.close();
	}

	return true;
}
开发者ID:Engman,项目名称:fly,代码行数:50,代码来源:ObjectImporter.cpp


注:本文中的std::wstring::substr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。