本文整理汇总了C++中std::string::back方法的典型用法代码示例。如果您正苦于以下问题:C++ string::back方法的具体用法?C++ string::back怎么用?C++ string::back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::string
的用法示例。
在下文中一共展示了string::back方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: skey
void IniSetting::ParserCallback::onPopEntry(
const std::string &key,
const std::string &value,
const std::string &offset,
void *arg) {
Variant *arr = (Variant*)arg;
forceToArray(*arr);
bool oEmpty = offset.empty();
// Substitution copy or symlink
// Offset come in like: hhvm.a.b\0c\[email protected]
// Check for `\0` because it is possible, although unlikely, to have
// something like hhvm.a.b[[email protected]]. Thus we wouldn't want to make a substitution.
if (!oEmpty && (offset.size() == 1 || offset[offset.size() - 2] == '\0') &&
(offset.back() == '@' || offset.back() == ':')) {
makeSettingSub(key, offset, value, *arr);
} else { // Normal array value
String skey(key);
auto& hash = arr->toArrRef().lvalAt(skey);
forceToArray(hash);
if (!oEmpty) { // a[b]
makeArray(hash, offset, value);
} else { // a[]
hash.toArrRef().append(value);
}
}
}
示例2: Validate
bool CreditCard::Validate(std::string creditCardNumber)
{
unsigned int sum=0;
bool toggle=true;
unsigned int otherCheckDigit=creditCardNumber.back() - '0';
unsigned int myCheckDigit=0;
creditCardNumber.pop_back();
while(!creditCardNumber.empty())
{
unsigned int temp=creditCardNumber.back() - '0'; //saves last digit
if (toggle)
{
temp= temp*2;
if (temp>=10)
temp=temp-9;
}
sum=sum+temp;
toggle=!toggle;
creditCardNumber.pop_back(); //deletes last digit
}
myCheckDigit= (sum*9)%10;
return (otherCheckDigit==myCheckDigit);
}
示例3: toNum
long long toNum(std::string str, int type = 0)
{
int len = str.length();
long long ret = 0;
if (len < 1)
return 0;
if (canBeNum(str) == false)
return 0;
std::stringstream ss;
bool negative = false;
if (str.front() == '-')
{
str.erase(0, 1);
negative = true;
len--;
}
else if (str.front() == '+')
{
str.erase(0, 1);
len--;
}
switch (type)
{
case 0:
if (len == 0)
return 0;
if (str.back() == 'h' || str.back() == 'H')
{
str.erase(len - 1, 1);
ss << std::hex << str;
ss >> ret;
}
else if (str.front() == '0' && len > 1)
示例4: set_workspace
void basic_configuration::set_workspace(std::string path)
{
if (path.back() != '/' && path.back() != '\\')
path.push_back('/');
pimpl->workspace_path = path;
}
示例5: parse_obj
bool ConfigReader::parse_obj(const std::string &key, std::string &obj,
std::string &err)
{
std::vector<std::string> items;
std::string okey, oval;
std::unordered_map<std::string, std::string> map;
size_t ind;
/* remove surrounding braces and whitespace */
obj = obj.substr(1);
remove_leading(obj);
while (obj.back() != '}')
obj.pop_back();
obj.pop_back();
while (isspace(obj.back()))
obj.pop_back();
utils::split(obj, '\n', items);
for (std::string s : items) {
if ((ind = s.find('=')) == std::string::npos) {
err = "unrecognized token in list -- ";
for (ind = 0; !isspace(s[ind]); ++ind)
err += s[ind];
return false;
}
okey = s.substr(0, ind);
while (isspace(okey.back()))
okey.pop_back();
oval = parse_string(s);
map[okey] = oval;
}
olistmap[key].emplace_back(map);
return true;
}
示例6: downloadMedia
void bebopftp::downloadMedia(std::string bebop_ip, std::string download_to, bool erase)
{
if(download_to.back() != '/' && download_to.back() != '\\')
{
download_to.append("/");
}
nsFTP::CFTPClient ftpClient;
nsFTP::CLogonInfo logonInfo(bebop_ip);
ftpClient.Login(logonInfo);
nsFTP::TFTPFileStatusShPtrVec list;
ftpClient.List(BEBOP_MEDIA_LOCATION, list);
for(nsFTP::TFTPFileStatusShPtrVec::iterator it=list.begin(); it!=list.end(); it++)
{
std::cout << "Downloading " << (*it)->Name() << " into " << download_to << std::endl;
ftpClient.DownloadFile(BEBOP_MEDIA_LOCATION + (*it)->Name(), download_to + (*it)->Name());
if(erase)
{
ftpClient.Delete(BEBOP_MEDIA_LOCATION + (*it)->Name());
}
}
ftpClient.Logout();
std::cout << "Done." << std::endl;
}
示例7: GetLastPathComponent
/*
* GetLastPathComponent
* @path: Path to get the last component from
* @return: Returns the last path component position in the string
*/
inline std::string::size_type GetLastPathComponent(std::string path)
{
// Remove any slash at the end of the string, so our finding can be safe
while(path.back() == '/' || path.back() == '\\') path.pop_back();
// Do the search
size_t pos = path.find_last_of("/\\");
return (pos == path.npos? 0 : pos + 1);
}
示例8: getFullPath
std::string getFullPath(const std::string& parentDir, const std::string& name) {
std::string full = parentDir;
if (parentDir.back() != '/' && parentDir.back() != '\\') {
return parentDir + "\\" + name;
} else {
return parentDir + name;
}
}
示例9: ensure_trailing_separators
static void ensure_trailing_separators(std::string& local_path, std::string& remote_path) {
if (!adb_is_separator(local_path.back())) {
local_path.push_back(OS_PATH_SEPARATOR);
}
if (remote_path.back() != '/') {
remote_path.push_back('/');
}
}
示例10: normalize
void Talkbot::normalize(std::string& sentence) const
{
if(not sentence.empty())
{
if(std::islower(sentence[0]))
sentence[0] = std::toupper(sentence[0]);
if(sentence.back() != '.' and sentence.back() != '!' and sentence.back() != '?')
sentence.push_back('.');
}
}
示例11: NormalizePath
/*
* NormalizePath
* Normalizates a path string, so for example:
* "somefolder/something" will output "somefolder\\something"
* "SOMEfoldER/something/" will output "somefolder\\something"
* "somefolder\\something" will output "somefolder\\something"
* etc
*/
inline std::string NormalizePath(std::string path)
{
std::replace(path.begin(), path.end(), '/', '\\'); // Replace all '/' with '\\'
tolower(path); // tolower the strings (Windows paths are case insensitive)
while(path.back() == '/' || path.back() == '\\') // We don't want a slash at the end of the folder path
path.pop_back(); // ..
trim(path); // Trim the string...
return path;
}
示例12: joinPath
LODEN_CORE_EXPORT std::string joinPath(const std::string &path1, const std::string &path2)
{
if (path1.empty())
return path2;
if (isAbsolutePath(path2))
return path2;
if(path1.back() == '/' || path1.back() == '\\')
return path1 + path2;
return path1 + "/" + path2;
}
示例13: receive
bool GenericSocket::receive(int timeout, std::string &reply, int expected, bool raw)
{
int length;
int run;
struct pollfd pfd = { .fd = fd, .events = POLLIN | POLLERR | POLLHUP, .revents = 0 };
char buffer[8192];
reply.clear();
for(run = 8; run > 0; run--)
{
if(poll(&pfd, 1, timeout) != 1)
return(false);
if(pfd.revents & (POLLERR | POLLHUP))
return(false);
if((length = read(fd, buffer, sizeof(buffer) - 1)) < 0)
return(false);
if(length == 0)
{
if(reply.length() == 0) // ignore terminating empty udp packed from previous output
continue;
else
break;
}
reply.append(buffer, (size_t)length);
if((expected > 0) && (expected > length))
expected -= length;
else
break;
}
if(reply.back() == '\n')
reply.pop_back();
if(!raw && (reply.back() == '\r'))
reply.pop_back();
return(true);
}
static std::string sha_hash_to_text(const unsigned char *hash)
{
unsigned int current;
std::stringstream hash_string;
for(current = 0; current < SHA_DIGEST_LENGTH; current++)
hash_string << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)hash[current];
return(hash_string.str());
}
示例14: SplitGltfAttribute
void SplitGltfAttribute(std::string attribute, std::string *semanticName, DWORD *semanticIndex)
{
*semanticIndex = 0;
if (isdigit(attribute.back()))
{
*semanticIndex = attribute.back() - '0';
attribute.pop_back();
if (attribute.back() == '_')
attribute.pop_back();
}
*semanticName = attribute;
}
示例15: attributeHasAnnotation
bool attributeHasAnnotation(
const std::string& annotation,
const std::string& attributeName,
std::string* comment) {
// Unqualified actions must compare directly e.g. we don't want to return a match for
// for 'CAPA:suppress' when the annotation is 'CAPA::suppress[foo]'
if(attributeName.find('[') == std::string::npos) {
return attributeName == annotation;
}
// Otherwise, check if the attributeName is a prefix of the annotation
// We need to check prefix and not equality in case there's a comment
if(annotation.length() < attributeName.length() ||
!std::equal(attributeName.begin(), attributeName.end(), annotation.begin())) {
return false;
}
// The attributes match.
// Try to pick out a comment if we need to
if(comment != nullptr) {
const auto commentStart = annotation.find('[', attributeName.length());
if(commentStart != std::string::npos && annotation.back() == ']') {
*comment =
annotation.substr(commentStart + 1, annotation.length() - commentStart - 2);
}
}
return true;
}