1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-10-01 13:58:20 +00:00

Started mucking about with some string conversion routines. Not finished yet.

This commit is contained in:
Thomas Harte 2017-06-12 21:32:36 -04:00
parent 22de481557
commit 626737b9fa
2 changed files with 38 additions and 0 deletions

View File

@ -90,3 +90,37 @@ std::shared_ptr<File> Storage::Data::ZX8081::FileFromData(const std::vector<uint
if(result) return result;
return ZX81FileFromData(data);
}
#pragma mark - String conversion
std::wstring Storage::Data::ZX8081::StringFromData(const std::vector<uint8_t> &data, bool is_zx81) {
std::wstring string;
wchar_t zx80_map[] = {
' ', u'\u2598', u'\u259d', u'\u2580', u'\u2596', u'\u258c', u'\u259e', u'\u259b', u'\u2588', u'\u2584', u'\u2580', '"', u'£', '$', ':', '?',
'(', ')', '>', '<', '=', '+', '-', '*', '/', ';', ',', '.', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
wchar_t zx81_map[] = {
' ', u'\u2598', u'\u259d', u'\u2580', u'\u2596', u'\u258c', u'\u259e', u'\u259b', u'\u2588', u'\u2584', u'\u2580', u'£', '$', ':', '?',
'(', ')', '-', '+', '*', '/', '=', '>', '<', ';', ',', '.', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
};
wchar_t *map = is_zx81 ? zx81_map : zx80_map;
for(uint8_t byte : data) {
string.push_back(map[byte & 0x3f]);
}
return string;
}
std::vector<uint8_t> DataFromString(const std::wstring &string, bool is_zx81) {
std::vector<uint8_t> data;
// TODO
return data;
}

View File

@ -25,6 +25,10 @@ struct File {
std::shared_ptr<File> FileFromData(const std::vector<uint8_t> &data);
std::wstring StringFromData(const std::vector<uint8_t> &data, bool is_zx81);
std::vector<uint8_t> DataFromString(const std::wstring &string, bool is_zx81);
}
}
}