mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-22 12:33:29 +00:00
Started mucking about with some string conversion routines. Not finished yet.
This commit is contained in:
parent
22de481557
commit
626737b9fa
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user