Ich muss einen String umwandeln, dass er mit dem von einem anderen Programm erzeugten ident ist. Ich habe das bisher so gemacht:
Code: Alles auswählen
NameInclOrd = re.sub(r"['\"\\/:*?|<>#]", lambda m: "#"+m.group(0).encode("hex"), NameInclOrd)
Ist jemand so nett mir zu helfen?
Danke
Stolzi
Das müsste ich nachbauen:
Code: Alles auswählen
if (ToFileSystem) {
switch (*p) {
// characters that can be used "as is":
case '!':
case '@':
case '$':
case '%':
case '&':
case '(':
case ')':
case '+':
case ',':
case '-':
case ';':
case '=':
case '0' ... '9':
case 'a' ... 'z':
case 'A' ... 'Z':
case 'ä': case 'Ä':
case 'ö': case 'Ö':
case 'ü': case 'Ü':
case 'ß':
break;
// characters that can be mapped to other characters:
case ' ': *p = '_'; break;
case '~': *p = '/'; break;
// characters that have to be encoded:
default:
if (*p != '.' || !*(p + 1) || *(p + 1) == '~') { // Windows can't handle '.' at the end of directory names
int l = p - s;
s = (char *)realloc(s, strlen(s) + 10);
p = s + l;
char buf[4];
sprintf(buf, "#%02X", (unsigned char)*p);
memmove(p + 2, p, strlen(p) + 1);
strncpy(p, buf, 3);
p += 2;
}
}
}