本文整理汇总了C++中aws::String::at方法的典型用法代码示例。如果您正苦于以下问题:C++ String::at方法的具体用法?C++ String::at怎么用?C++ String::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aws::String
的用法示例。
在下文中一共展示了String::at方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHomeDirectory
Aws::String FileSystemUtils::GetHomeDirectory()
{
static const char* HOME_DIR_ENV_VAR = "HOME";
AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Checking " << HOME_DIR_ENV_VAR << " for the home directory.");
const char* homeEnvDir = std::getenv(HOME_DIR_ENV_VAR);
Aws::String homeDir(homeEnvDir ? homeEnvDir : "");
AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Environment value for variable " << HOME_DIR_ENV_VAR << " is " << homeDir);
if(homeDir.empty())
{
AWS_LOG_WARN(FILE_SYSTEM_UTILS_LOG_TAG, "Home dir not stored in environment, trying to fetch manually from the OS.");
passwd pw;
passwd *p_pw = nullptr;
char pw_buffer[4096];
getpwuid_r(getuid(), &pw, pw_buffer, sizeof(pw_buffer), &p_pw);
if(p_pw && p_pw->pw_dir)
{
homeDir = p_pw->pw_dir;
}
AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Pulled " << homeDir << " as home directory from the OS.");
}
Aws::String retVal = homeDir.size() > 0 ? StringUtils::Trim(homeDir.c_str()) : "";
if(!retVal.empty())
{
if(retVal.at(retVal.length() - 1) != PATH_DELIM)
{
AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Home directory is missing the final " << PATH_DELIM << " appending one to normalize");
retVal += PATH_DELIM;
}
}
AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Final Home Directory is " << retVal);
return retVal;
}
示例2: GetHomeDirectory
Aws::String GetHomeDirectory()
{
static const char* HOME_DIR_ENV_VAR = "USERPROFILE";
AWS_LOGSTREAM_TRACE(FILE_SYSTEM_UTILS_LOG_TAG, "Checking " << HOME_DIR_ENV_VAR << " for the home directory.");
Aws::String homeDir = Aws::Environment::GetEnv(HOME_DIR_ENV_VAR);
AWS_LOGSTREAM_DEBUG(FILE_SYSTEM_UTILS_LOG_TAG, "Environment value for variable " << HOME_DIR_ENV_VAR << " is " << homeDir);
if(homeDir.empty())
{
AWS_LOGSTREAM_WARN(FILE_SYSTEM_UTILS_LOG_TAG, "Home dir not stored in environment, trying to fetch manually from the OS.");
HANDLE hToken;
if (OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &hToken))
{
DWORD len = MAX_PATH;
WCHAR path[MAX_PATH];
if (GetUserProfileDirectoryW(hToken, path, &len))
{
homeDir = Aws::Utils::StringUtils::FromWString(path);
}
CloseHandle(hToken);
}
AWS_LOGSTREAM_INFO(FILE_SYSTEM_UTILS_LOG_TAG, "Pulled " << homeDir << " as home directory from the OS.");
}
Aws::String retVal = (homeDir.size() > 0) ? Aws::Utils::StringUtils::Trim(homeDir.c_str()) : "";
if (!retVal.empty())
{
if (retVal.at(retVal.length() - 1) != Aws::FileSystem::PATH_DELIM)
{
retVal += Aws::FileSystem::PATH_DELIM;
}
}
return retVal;
}