Skip to content

Commit cc9e730

Browse files
committed
Convert filename to UTF-8
1 parent f7e590d commit cc9e730

File tree

3 files changed

+18
-23
lines changed

3 files changed

+18
-23
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
dist: xenial
12
language: cpp
23

34
compiler:

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
cmake_minimum_required(VERSION 2.8)
22
project(fatcat)
33

4+
set(CMAKE_CXX_STANDARD 11)
45
set(SOURCES
56
core/FatEntry.cpp
67
core/FatFilename.cpp

src/core/FatFilename.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
#include <string>
22
#include <iostream>
3+
#include <locale>
4+
#include <codecvt>
35
#include "FatFilename.h"
46
#include "FatEntry.h"
57

68
using namespace std;
79

810
#define FAT_LONG_NAME_LAST 0x40
911

10-
// Offset of letters position in a special "long file name" entry
11-
static unsigned char longFilePos[] = {
12-
30, 28, 24, 22, 20, 18, 16, 14, 9, 7, 5, 3, 1
13-
};
14-
1512
string FatFilename::getFilename()
1613
{
17-
string rfilename;
18-
vector<string>::iterator it;
14+
string filename;
15+
vector<string>::reverse_iterator it;
16+
wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert;
1917

20-
for (it=letters.begin(); it!=letters.end(); it++) {
21-
rfilename += *it;
18+
for (it=letters.rbegin(); it!=letters.rend(); it++) {
19+
filename += *it;
2220
}
2321
letters.clear();
2422

25-
return string(rfilename.rbegin(), rfilename.rend());
23+
if (!filename.length()) {
24+
return {};
25+
}
26+
return convert.to_bytes((char16_t *)filename.c_str());
2627
}
2728

2829
void FatFilename::append(char *buffer)
@@ -35,18 +36,10 @@ void FatFilename::append(char *buffer)
3536
letters.clear();
3637
}
3738

38-
int i;
39-
for (i=0; i<sizeof(longFilePos); i++) {
40-
unsigned char c = buffer[longFilePos[i]];
41-
unsigned char d = buffer[longFilePos[i]+1];
42-
if (c != 0 && c != 0xff) {
43-
string letter;
44-
if (d != 0x00) {
45-
letter += d;
46-
}
47-
letter += c;
48-
letters.push_back(letter);
49-
}
50-
}
39+
string letter;
40+
letter.append(buffer + 1, 5 * 2);
41+
letter.append(buffer + 14, 6 * 2);
42+
letter.append(buffer + 28, 2 * 2);
43+
letters.push_back(letter);
5144
}
5245

0 commit comments

Comments
 (0)