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 28, 2024
1 parent 6384074 commit 83f5901
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
19 changes: 18 additions & 1 deletion cp1252/cp1252.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ size_t strcplen(const char* buf, bool utf8);
const char* getCodePointFromUTF8Sequence(const char* buf, uint32_t* out);
char* getUTF8String(const char* input);
char* getCP1252String(const char* input);
char toupperCP1252(char c);

uint32_t getUnicodeFromCP1252(char input) {
switch ((unsigned char)input) {
Expand Down Expand Up @@ -144,7 +145,7 @@ char getCP1252FromUnicode(uint32_t input) {
return (char)input;
}
else {
return '\x20'; // SPACE
return '\x3F'; // QUESTION MARK
}
}
}
Expand Down Expand Up @@ -274,4 +275,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 83f5901

Please sign in to comment.