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


C++ StringRef::c_str方法代码示例

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


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

示例1: toDouble

double TILParser::toDouble(StringRef s) {
  char* end = nullptr;
  double val = strtod(s.c_str(), &end);
  // FIXME: some proper error handling here?
  assert(end == s.c_str() + s.length() && "Could not parse string.");
  return val;
}
开发者ID:dandv,项目名称:ohmu,代码行数:7,代码来源:TILParser.cpp

示例2: toInteger

int TILParser::toInteger(StringRef s) {
  char* end = nullptr;
  long long val = strtol(s.c_str(), &end, 0);
  // FIXME: some proper error handling here?
  assert(end == s.c_str() + s.length() && "Could not parse string.");
  return static_cast<int>(val);
}
开发者ID:dandv,项目名称:ohmu,代码行数:7,代码来源:TILParser.cpp

示例3:

IPAddress::IPAddress(StringRef ip, ushort port, bool isIP6 /*= false*/)
{
	if (isIP6)
	{
		Memory::ClearZero(&mAddress6);
		mAddress6.sin6_family = (int)SocketAddressFamily::IP6;
		mAddress6.sin6_port = BitConverter::HostToNetwork(port);
		if (!ip.IsEmpty())	//0.0.0.0 or "" to bind to any local ip
		{
			if (inet_pton(mAddress6.sin6_family, ip.c_str(), &mAddress6.sin6_addr) <= 0)
			{
				Log::AssertFailedFormat("Invalid ip6:{}", ip);
			}
		}
		
	}
	else
	{
		Memory::ClearZero(&mAddress);
		mAddress.sin_family = (int)SocketAddressFamily::IP;
		mAddress.sin_port = BitConverter::HostToNetwork(port);

		if (!ip.IsEmpty())
		{
			if (inet_pton(mAddress.sin_family, ip.c_str(), &mAddress.sin_addr) <= 0)
			{
				Log::AssertFailedFormat("Invalid ip:{}", ip);
			}
		}
		
	}
}
开发者ID:fjz13,项目名称:Medusa,代码行数:32,代码来源:IPAddress.cpp

示例4: Init

void DateTime::Init(const StringRef& dateTimeStr, const StringRef& formaterStr, bool isUTC/*=true*/)
{
	uint year, month, day, hour, minutes, seconds;
#ifdef MEDUSA_WINDOWS
	sscanf_s(dateTimeStr.c_str(), formaterStr.c_str(), &year, &month, &day, &hour, &minutes, &seconds);
#else
	sscanf(dateTimeStr.c_str(), formaterStr.c_str(), &year, &month, &day, &hour, &minutes, &seconds);
#endif
	Init(year, month - 1, day, hour, minutes, seconds, isUTC);
}
开发者ID:fjz13,项目名称:Medusa,代码行数:10,代码来源:DateTime.cpp

示例5: Parse

bool TiledImage::Parse(const pugi::xml_node& node)
{
	// Read all the attribute into member variables.
	mSource= FileId::ParseFrom(node.attribute("source").as_string(nullptr));
	if (mSource.IsEmpty())
	{
		Log::AssertFailed("Invalid image xml node source attribute");
		return false;
	}

	mSize.Width = node.attribute("width").as_int(0);
	mSize.Height = node.attribute("height").as_int(0);

	const char* transparentColorStr = node.attribute("trans").as_string(nullptr);
	mTransparentColor = TiledMap::ParseColor(transparentColorStr);


	StringRef formatStr = node.attribute("format").as_string(nullptr);

	if (formatStr == "png")
	{
		mEmbeddedFileType=FileType::png;
	}
	else if (formatStr == "jpg")
	{
		mEmbeddedFileType=FileType::jpeg;
	}
	else if (!formatStr.IsEmpty())
	{
		Log::FormatError("Unsupported image type:{}", formatStr.c_str());
		return false;
	}

	pugi::xml_node dataNode = node.child("data");
	if (!dataNode.empty())
	{
		StringRef encodingStr = node.attribute("encoding").as_string(nullptr);
		StringRef compressionStr = node.attribute("compression").as_string(nullptr);
		if (encodingStr != "base64")
		{
			Log::FormatError("Unsupported encoding type:{}", encodingStr.c_str());
			return false;
		}

		const char* text = dataNode.value();
		Base64Decoder decoder;
		mEmbeddedImageData = decoder.Code(text);
	}

	return true;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:51,代码来源:TiledImage.cpp

示例6:

SqlException::SqlException(const StringRef& initialMessage, const int errno, const char *sqlState, const char *errorMessage)
    :std::exception(initialMessage.c_str())
{
    mErrno = errno;
    mSqlState = sqlState;
    mErrorMessage = errorMessage;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:7,代码来源:SqlException.cpp

示例7: Parse

bool StringPropertySet::Parse(const StringRef& str)
{
	RETURN_TRUE_IF_EMPTY(str);
	//Key=Value,...
	List<StringRef> outPairs;
	StringParser::Split(str, ",", outPairs);

	List<StringRef> keyValuePair;
	for (auto& optionPair : outPairs)
	{
		keyValuePair.Clear();
		StringParser::Split(optionPair, "=", keyValuePair);
		if (keyValuePair.Count() == 2)
		{
			Add(keyValuePair[0], keyValuePair[1]);
		}
		else if (keyValuePair.Count() == 1)
		{
			Add(keyValuePair[0], HeapString::Empty);
		}
		else
		{
			Log::FormatError("Invalid attribute str:{} in {}", optionPair.c_str(), str.c_str());
			return false;
		}
	}

	return true;
}
开发者ID:xuxiaowei007,项目名称:Medusa,代码行数:29,代码来源:StringPropertySet.cpp

示例8: SetDebuggerThreadName

void ff::SetDebuggerThreadName(StringRef name, DWORD nThreadID)
{
#ifdef _DEBUG
	if (IsDebuggerPresent())
	{
		CHAR szNameACP[512] = "";
		WideCharToMultiByte(CP_ACP, 0, name.c_str(), -1, szNameACP, _countof(szNameACP), nullptr, nullptr);

		typedef struct tagTHREADNAME_INFO
		{
			ULONG_PTR dwType; // must be 0x1000
			const char *szName; // pointer to name (in user addr space)
			ULONG_PTR dwThreadID; // thread ID (-1=caller thread)
			ULONG_PTR dwFlags; // reserved for future use, must be zero
		} THREADNAME_INFO;

		THREADNAME_INFO info;
		info.dwType = 0x1000;
		info.szName = szNameACP;
		info.dwThreadID = nThreadID ? nThreadID : GetCurrentThreadId();
		info.dwFlags = 0;

		__try
		{
			RaiseException(0x406D1388, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*)&info);
		}
		__except (EXCEPTION_CONTINUE_EXECUTION)
		{
		}
	}

#endif // _DEBUG
}
开发者ID:FerretFaceGames,项目名称:infinite-pac-shared,代码行数:33,代码来源:ThreadUtil.cpp

示例9: GetFileMode

bool File::GetFileMode(StringRef filePath, FileMode& outFileMode)
{
	struct stat buf;
	const char* path = filePath.c_str();
	int result = stat(path, &buf);
	if (result == 0)
	{
		if (buf.st_mode&S_IFDIR)
		{
			outFileMode = FileMode::Directory;
		}
		else
		{
			outFileMode = FileMode::File;
		}

		return true;
	}
	else
	{
		if (errno == ENOENT)
		{
			//file not exists
			return false;
		}
		else
		{
			return false;
		}
	}
}
开发者ID:fjz13,项目名称:Medusa,代码行数:31,代码来源:File.cpp

示例10: IsIP

bool IPAddress::IsIP(StringRef val)
{
	//IP address format:<ddd.ddd.ddd.ddd>
	RETURN_FALSE_IF_EMPTY(val);
	in_addr sAddr; // IPv4地址结构体
	int r = inet_pton((int)SocketAddressFamily::IP, val.c_str(), &sAddr);
	return r > 0;	//<=0 means error
}
开发者ID:fjz13,项目名称:Medusa,代码行数:8,代码来源:IPAddress.cpp

示例11: Invoke

inline void ScriptObject::Invoke(const StringRef& funcName, TArgs&&... args)
{
	asIObjectType* scriptObjectType = mScriptObject->GetObjectType();
	asIScriptFunction* func = scriptObjectType->GetMethodByName(funcName.c_str());
	if (func == nullptr)
	{
		Log::AssertFailedFormat("Cannot find {}::{}", scriptObjectType->GetName(), funcName.c_str());
		return;
	}

	asIScriptContext* context = ScriptEngine::Instance().GetScriptContext();
	context->Prepare(func);
	context->SetObject(mScriptObject);
	SetArgs(context, std::forward<TArgs>(args)...);
	context->Execute();

	asThreadCleanup();
}
开发者ID:johndpope,项目名称:Medusa,代码行数:18,代码来源:ScriptObject.cpp

示例12: LoadFromData

bool BehaviorConfig::LoadFromData(const FileIdRef& fileId, const MemoryData& data, uint format /*= 0*/)
{
	Unload();
	RETURN_FALSE_IF(data.IsNull());

	pugi::xml_document doc;
	pugi::xml_parse_result result = doc.load_buffer(data.Data(), data.Size());
	if (!result)
	{
		Log::AssertFailedFormat("Cannot parse xml:{} because {}", fileId, result.description());
		return false;
	}
	for (const auto& child : doc.first_child().children())
	{
		StringRef typeName = child.name();
		StringRef id = child.attribute("Id").value();
		if (id.IsEmpty())
		{
			id = typeName;
		}

#ifdef MEDUSA_SAFE_CHECK
		if (ContainsId(id))
		{
			Log::AssertFailedFormat("Duplicate id:{} in {}", id.c_str(), typeName.c_str());
		}
#endif

		IBehavior* behavior = BehaviorFactory::Instance().SmartCreate(typeName);
		behavior->LoadFromXmlNode(child);
		behavior->Initialize();
		if (id.EndWith("Behavior"))
		{
			Add(id, behavior);
		}
		else
		{
			Add(id + "Behavior", behavior);
		}
	}


	return true;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:44,代码来源:BehaviorConfig.cpp

示例13: Resolve

IPAddress IPAddress::Resolve(StringRef host)
{
	addrinfo* hostent;
	getaddrinfo(host.c_str(), nullptr, nullptr, &hostent);
	IPAddress result;
	result.mAddress.sin_family = hostent->ai_protocol == IPPROTO_IPV6 ? (int)SocketAddressFamily::IP6 : (int)SocketAddressFamily::IP;
	result.mAddress.sin_addr = *reinterpret_cast<in_addr*>(hostent->ai_addr);
	freeaddrinfo(hostent);
	return result;
}
开发者ID:fjz13,项目名称:Medusa,代码行数:10,代码来源:IPAddress.cpp

示例14: LoadFromXmlNode

bool IActBehavior::LoadFromXmlNode(pugi::xml_node node)
{
	RETURN_FALSE_IF_FALSE(IBehavior::LoadFromXmlNode(node));
	StringRef typeName = node.name();
	StringRef predicateId = node.attribute("Predicate").value();

	if (!predicateId.IsEmpty())
	{
		Log::FormatError("Invalid predicate:{} on {}", predicateId.c_str(), typeName.c_str());
		return false;
	}
	if (node.first_child() != nullptr)
	{
		Log::FormatError("Act behavior cannot have children. {}", typeName.c_str());
		return false;
	}

	return true;
}
开发者ID:johndpope,项目名称:Medusa,代码行数:19,代码来源:IActBehavior.cpp

示例15: combineUrl

	String Internet::combineUrl(const StringRef& url, const StringRef& parent) {
		Stamina::RegEx regex;
		if (url.empty() || regex.match("#^\\w+://#", url.c_str())) {
			return url;
		}

		// wyci¹gamy poszczególne elementy URLa
		if (!regex.match("#^(\\w+://[^/]+/)([^\\?]+/)?([^\\?/]*)(\\?.*)?$#", parent.c_str()))
			return url;
		if (url.a_str()[0] == '.' && (url.length() < 2 || url.a_str()[1] != '.')) {
			// (http://..../) + (katalog/) + url bez kropki
			return regex[1] + regex[2] + url.substr(1);
		} else if (url.a_str()[0] == '/') {
			// (http://..../) + url bez kreski
			return regex[1] + url.substr(1);
		} else {
			// (http://..../) + (katalog/) + url
			return regex[1] + regex[2] + url;
		}
	}
开发者ID:Konnekt,项目名称:staminalib,代码行数:20,代码来源:Internet.cpp


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