本文整理汇总了C++中Stroka::at方法的典型用法代码示例。如果您正苦于以下问题:C++ Stroka::at方法的具体用法?C++ Stroka::at怎么用?C++ Stroka::at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stroka
的用法示例。
在下文中一共展示了Stroka::at方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resolvepath
bool resolvepath(Stroka &folder, const Stroka &home)
{
YASSERT(home && home.at(0) == '/');
if (!folder) {
return false;
}
// may be from windows
char *ptr = folder.begin();
while ((ptr = strchr(ptr, '\\')) != 0)
*ptr = '/';
if (folder.at(0) == '~') {
if (folder.length() == 1 || folder.at(1) == '/') {
folder = GetHomeDir() + (~folder + 1);
} else {
char* buf = (char*)alloca(folder.length()+1);
strcpy(buf, ~folder + 1);
char* p = strchr(buf, '/');
if (p)
*p++ = 0;
passwd* pw = getpwnam(buf);
if (pw) {
folder = pw->pw_dir;
folder += "/";
if (p)
folder += p;
} else {
return false; // unknown user
}
}
}
int len = folder.length() + home.length() + 1;
char* path = (char*)alloca(len);
if (folder.at(0) != '/') {
strcpy(path, ~home);
strcpy(strrchr(path, '/')+1, ~folder); // the last char must be '/' if it's a dir
} else {
strcpy(path, ~folder);
}
len = strlen(path)+1;
// grabbed from url.cpp
char *newpath = (char*)alloca(len+2);
const char **pp = (const char**)alloca(len*sizeof(char*));
int i = 0;
for (char* s = path; s;) {
pp[i++] = s;
s = strchr(s, '/');
if (s)
*s++ = 0;
}
for (int j = 1; j < i;) {
const char*& p = pp[j];
if (strcmp(p, ".") == 0 || strcmp(p,"") == 0) {
if (j == i-1) {
p = "";
break;
} else {
memmove(pp+j, pp+j+1, (i-j-1)*sizeof(p));
i--;
}
} else if (strcmp(p, "..") == 0) {
if (j == i-1) {
if (j == 1) {
p = "";
} else {
i--;
pp[j-1] = "";
}
break;
} else {
if (j == 1) {
memmove(pp+j, pp+j+1, (i-j-1)*sizeof(p));
i--;
} else {
memmove(pp+j-1, pp+j+1, (i-j-1)*sizeof(p));
i-=2;
j--;
}
}
} else
j++;
}
char* s = newpath;
for (int k = 0; k < i; k++) {
s = strchr(strcpy(s, pp[k]), 0);
*s++ = '/';
}
*(--s) = 0;
folder = newpath;
return true;
}