Skip to content

Commit

Permalink
Properly convert CP1252 filenames to uppercase
Browse files Browse the repository at this point in the history
Replace invalid CP1252 characters with question mark
  • Loading branch information
rapperskull committed Feb 27, 2024
1 parent 6384074 commit 5a4c7f6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
18 changes: 17 additions & 1 deletion cp1252/cp1252.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ char getCP1252FromUnicode(uint32_t input) {
return (char)input;
}
else {
return '\x20'; // SPACE
return '\x3F'; // QUESTION MARK
}
}
}
Expand Down Expand Up @@ -274,4 +274,20 @@ char* getCP1252String(const char* input) {
return ret;
}

char toupperCP1252(char c) {
if (c >= 'a' && c <= 'z') {
c -= 32;
}
else if (c == '\x9A' || c == '\x9C' || c == '\x9E') {
c -= 16;
}
else if ((c >= '\xE0' && c <= '\xF6') || (c >= '\xF8' && c <= '\xFE')) {
c -= 32;
}
else if (c == '\xFF') {
c = '\x9F';
}
return c;
}

#endif //CP1252_INCLUDED
7 changes: 2 additions & 5 deletions extract-xiso.c
Original file line number Diff line number Diff line change
Expand Up @@ -1568,11 +1568,8 @@ int avl_compare_key( const char *in_lhs, const char *in_rhs ) {
unsigned char a, b;

for ( ;; ) {
a = (unsigned char)*in_lhs++;
b = (unsigned char)*in_rhs++;

if ( a >= 'a' && a <= 'z' ) a -= 32; // uppercase(a);
if ( b >= 'a' && b <= 'z' ) b -= 32; // uppercase(b);
a = (unsigned char)toupperCP1252(*in_lhs++);
b = (unsigned char)toupperCP1252(*in_rhs++);

if ( a ) {
if ( b ) {
Expand Down

0 comments on commit 5a4c7f6

Please sign in to comment.