mirror of
https://github.com/libretro/scummvm.git
synced 2024-12-03 23:52:41 +00:00
COMMON: Sync punycode with JS/Python code:
* Allow [] in file names * Process files ending with spaces or dots
This commit is contained in:
parent
788937e3e1
commit
b9c5ef933f
@ -59,7 +59,7 @@ namespace Common {
|
||||
#define INITIAL_BIAS 72
|
||||
#define SMAX 0x10ffff // maximum Unicode code point
|
||||
|
||||
#define SPECIAL_SYMBOLS "/\":*[]+|\\?%<>,;="
|
||||
#define SPECIAL_SYMBOLS "/\":*|\\?%<>,;="
|
||||
|
||||
static uint32 adapt_bias(uint32 delta, unsigned n_points, int is_first) {
|
||||
uint32 k;
|
||||
@ -78,7 +78,7 @@ static uint32 adapt_bias(uint32 delta, unsigned n_points, int is_first) {
|
||||
static char encode_digit(int c) {
|
||||
assert(c >= 0 && c <= BASE - TMIN);
|
||||
if (c > 25) {
|
||||
return c + 0x30 - 26; /* '0'..'9' */
|
||||
return c + 22; /* '0'..'9' */
|
||||
} else {
|
||||
return c + 0x61; /* 'a'..'z' */
|
||||
}
|
||||
@ -144,8 +144,15 @@ String punycode_encode(const U32String &src) {
|
||||
size_t b = h;
|
||||
|
||||
// If every character is ASCII, return the original string.
|
||||
if (h == srclen)
|
||||
if (h == srclen) {
|
||||
// If string ends with space or dot, still punycode it
|
||||
// because certain FSes do not support files with those
|
||||
// endings
|
||||
if (src[h - 1] == ' ' || src[h - 1] == '.')
|
||||
return dst + '-';
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
// If we have any ASCII characters, add '-' to separate them from
|
||||
// the non-ASCII character insertions.
|
||||
@ -205,6 +212,10 @@ bool punycode_needEncode(const String &src) {
|
||||
}
|
||||
}
|
||||
|
||||
// If name ends with space or dot, we have to encode it
|
||||
if (src[src.size() - 1] == ' ' || src[src.size() - 1] == '.')
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user