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


C++ AString::find_last_of方法代码示例

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


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

示例1: SplitFilePath

	AString HawkOSOperator::SplitFilePath(const AString& sFile)
	{
		AString sTmpFile = sFile;
		HawkStringUtil::Replace<AString>(sTmpFile,"\\","/");
		Int32 iPos = (Int32)sTmpFile.find_last_of('/');
		if (iPos > 0)
		{
			return sTmpFile.substr(0,iPos+1);
		}
		return sTmpFile;
	}
开发者ID:SleepingBearZ,项目名称:hawkproject,代码行数:11,代码来源:HawkOSOperator.cpp

示例2: TabCompleteCommand

void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player)
{
	for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
	{
		if (NoCaseCompare(itr->first.substr(0, a_Text.length()), a_Text) != 0)
		{
			// Command name doesn't match
			continue;
		}
		if ((a_Player != nullptr) && !a_Player->HasPermission(itr->second.m_Permission))
		{
			// Player doesn't have permission for the command
			continue;
		}

		/*  Client expects to only get back the last part of a space separated command.
		Find the position of the beginning of the last part:
		Position of last space + 1 for space separated commands
		string::npos + 1 = 0 for commands that are not separated

		Then skip all commands that have too many subcommands.
		When the client asks for suggestions for "/time s"
		the server must skip all commands that consist of more than 2 words just as
		"/time set day". Or in other words, the position of the last space (separator)
		in the strings must be equal or string::npos for both. */
		size_t LastSpaceInText = a_Text.find_last_of(' ') + 1;
		size_t LastSpaceInSuggestion = itr->first.find_last_of(' ') + 1;

		if (LastSpaceInText != LastSpaceInSuggestion)
		{
			// Suggestion has more subcommands than a_Text
			continue;
		}

		a_Results.push_back(itr->first.substr(LastSpaceInSuggestion));
	}
}
开发者ID:GoogleIt15973,项目名称:cuberite,代码行数:37,代码来源:PluginManager.cpp

示例3: ReadFile

bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{

	m_Filename = a_FileName;

	// Normally you would use ifstream, but the SGI CC compiler has
	// a few bugs with ifstream. So ... fstream used.
	fstream f;
	AString   line;
	AString   keyname, valuename, value;
	AString::size_type pLeft, pRight;
	bool IsFromExampleRedirect = false;


	f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in);
	if (f.fail())
	{
		f.clear();
		if (a_AllowExampleRedirect)
		{
			// Retry with the .example.ini file instead of .ini:
			AString ExPath(a_FileName.substr(0, a_FileName.length() - 4));
			ExPath.append(".example.ini");
			f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in);
			if (f.fail())
			{
				return false;
			}
			IsFromExampleRedirect = true;
		}
		else
		{
			return false;
		}
	}

	bool IsFirstLine = true;

	while (getline(f, line))
	{
		// To be compatible with Win32, check for existence of '\r'.
		// Win32 files have the '\r' and Unix files don't at the end of a line.
		// Note that the '\r' will be written to INI files from
		// Unix so that the created INI file can be read under Win32
		// without change.

		// Removes UTF-8 Byte Order Markers (BOM) if, present.
		if (IsFirstLine)
		{
			RemoveBom(line);
			IsFirstLine = false;
		}

		size_t lineLength = line.length();
		if (lineLength == 0)
		{
			continue;
		}
		if (line[lineLength - 1] == '\r')
		{
			line = line.substr(0, lineLength - 1);
		}

		if (line.length() == 0)
		{
			continue;
		}

		// Check that the user hasn't opened a binary file by checking the first
		// character of each line!
		if (!isprint(line[0]))
		{
			printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]);
			f.close();
			return false;
		}
		if ((pLeft = line.find_first_of(";#[=")) == AString::npos)
		{
			continue;
		}

		switch (line[pLeft])
		{
			case '[':
			{
				if (
					((pRight = line.find_last_of("]")) != AString::npos) &&
					(pRight > pLeft)
					)
				{
					keyname = line.substr(pLeft + 1, pRight - pLeft - 1);
					AddKeyName(keyname);
				}
				break;
			}

			case '=':
			{
				valuename = line.substr(0, pLeft);
				value = line.substr(pLeft + 1);
//.........这里部分代码省略.........
开发者ID:Haxi52,项目名称:cuberite,代码行数:101,代码来源:IniFile.cpp

示例4: if

UniquePtr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1(
	const AString & a_FileName,
	cLuaState & a_LuaState,
	const AString & a_PieceName,
	bool a_LogWarnings
)
{
	// First try loading a referenced schematic file, if any:
	AString SchematicFileName;
	if (a_LuaState.GetNamedValue("SchematicFileName", SchematicFileName))
	{
		auto PathEnd = a_FileName.find_last_of("/\\");  // Find the last path separator
		if (PathEnd != AString::npos)
		{
			SchematicFileName = a_FileName.substr(0, PathEnd) + SchematicFileName;
		}
		cBlockArea area;
		if (!cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName))
		{
			CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s.",
				SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str()
			);
			return nullptr;
		}
		return cpp14::make_unique<cPrefab>(area);
	}  // if (SchematicFileName)

	// There's no referenced schematic file, load from BlockDefinitions / BlockData.
	// Get references to the data and the table.concat function:
	cLuaState::cRef TableConcat, BlockDefinitions, BlockData;
	if (
		!a_LuaState.GetNamedGlobal("table.concat", TableConcat) ||
		!a_LuaState.GetNamedValue("BlockDefinitions", BlockDefinitions) ||
		!a_LuaState.GetNamedValue("BlockData", BlockData)
	)
	{
		CONDWARNING(a_LogWarnings, "Cannot parse block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
		return nullptr;
	}

	// Call table.concat() on the BlockDefinitions:
	AString BlockDefStr;
	if (!a_LuaState.Call(TableConcat, BlockDefinitions, "\n", cLuaState::Return, BlockDefStr))
	{
		CONDWARNING(a_LogWarnings, "Cannot concat block definitions for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
		return nullptr;
	}

	// Call table.concat() on the BlockData:
	AString BlockDataStr;
	if (!a_LuaState.Call(TableConcat, BlockData, "", cLuaState::Return, BlockDataStr))
	{
		CONDWARNING(a_LogWarnings, "Cannot concat block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
		return nullptr;
	}

	// Read the size:
	int SizeX = 0, SizeY = 0, SizeZ = 0;
	if (
		!a_LuaState.GetNamedValue("Size.x", SizeX) ||
		!a_LuaState.GetNamedValue("Size.y", SizeY) ||
		!a_LuaState.GetNamedValue("Size.z", SizeZ)
	)
	{
		CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, its size information is missing", a_PieceName.c_str(), a_FileName.c_str());
		return nullptr;
	}

	// Check that the size matches the data length:
	if (static_cast<size_t>(SizeX * SizeY * SizeZ) != BlockDataStr.size())
	{
		CONDWARNING(a_LogWarnings, "Cannot create piece %s from file %s, its size (%d) doesn't match the blockdata length (%u)",
			a_PieceName.c_str(), a_FileName.c_str(),
			SizeX * SizeY * SizeZ, static_cast<unsigned>(BlockDataStr.size())
		);
		return nullptr;
	}

	return cpp14::make_unique<cPrefab>(BlockDefStr, BlockDataStr, SizeX, SizeY, SizeZ);
}
开发者ID:SamJBarney,项目名称:cuberite,代码行数:80,代码来源:PrefabPiecePool.cpp


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