mirror of
https://github.com/libretro/scummvm.git
synced 2025-02-04 09:56:30 +00:00
DIRECTOR: Add charToNum and numToChar helper functions
This commit is contained in:
parent
b2988ce682
commit
8fcc186b08
@ -480,20 +480,13 @@ void LB::b_charToNum(int nargs) {
|
||||
|
||||
TYPECHECK(d, STRING);
|
||||
|
||||
Common::U32String src = d.asString().decode(Common::kUtf8);
|
||||
if (src.size() == 0) {
|
||||
Common::U32String str = d.asString().decode(Common::kUtf8);
|
||||
if (str.size() == 0) {
|
||||
g_lingo->push(0);
|
||||
return;
|
||||
}
|
||||
|
||||
Common::U32String ch = src.substr(0, 1);
|
||||
Common::String encodedCh = ch.encode(g_director->getPlatformEncoding());
|
||||
int res = 0;
|
||||
while (encodedCh.size()) {
|
||||
res = (res << 8) | (byte)encodedCh.firstChar();
|
||||
encodedCh.deleteChar(0);
|
||||
}
|
||||
g_lingo->push(res);
|
||||
g_lingo->push(charToNum(str[0]));
|
||||
}
|
||||
|
||||
void LB::b_length(int nargs) {
|
||||
@ -507,21 +500,7 @@ void LB::b_length(int nargs) {
|
||||
|
||||
void LB::b_numToChar(int nargs) {
|
||||
int num = g_lingo->pop().asInt();
|
||||
if (num == 0) {
|
||||
g_lingo->push(Common::String());
|
||||
return;
|
||||
}
|
||||
|
||||
Common::String encodedCh;
|
||||
while (num) {
|
||||
encodedCh.insertChar((char)(num & 0xFF), 0);
|
||||
num >>= 8;
|
||||
}
|
||||
Common::U32String ch = encodedCh.decode(g_director->getPlatformEncoding());
|
||||
while (ch.size() > 1) // we only want one character
|
||||
ch.deleteChar(0);
|
||||
|
||||
g_lingo->push(ch.encode(Common::kUtf8));
|
||||
g_lingo->push(Common::U32String(numToChar(num)).encode(Common::kUtf8));
|
||||
}
|
||||
|
||||
void LB::b_offset(int nargs) {
|
||||
|
@ -742,4 +742,24 @@ Common::CodePage detectFontEncoding(Common::Platform platform, uint16 fontId) {
|
||||
return getEncoding(platform, g_director->_wm->_fontMan->getFontLanguage(fontId));
|
||||
}
|
||||
|
||||
int charToNum(Common::u32char_type_t ch) {
|
||||
Common::String encodedCh = Common::U32String(ch).encode(g_director->getPlatformEncoding());
|
||||
int res = 0;
|
||||
while (encodedCh.size()) {
|
||||
res = (res << 8) | (byte)encodedCh.firstChar();
|
||||
encodedCh.deleteChar(0);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Common::u32char_type_t numToChar(int num) {
|
||||
Common::String encodedCh;
|
||||
while (num) {
|
||||
encodedCh.insertChar((char)(num & 0xFF), 0);
|
||||
num >>= 8;
|
||||
}
|
||||
Common::U32String str = encodedCh.decode(g_director->getPlatformEncoding());
|
||||
return str.lastChar();
|
||||
}
|
||||
|
||||
} // End of namespace Director
|
||||
|
@ -85,6 +85,9 @@ Common::Platform platformFromID(uint16 id);
|
||||
Common::CodePage getEncoding(Common::Platform platform, Common::Language language);
|
||||
Common::CodePage detectFontEncoding(Common::Platform platform, uint16 fontId);
|
||||
|
||||
int charToNum(Common::u32char_type_t ch);
|
||||
Common::u32char_type_t numToChar(int num);
|
||||
|
||||
} // End of namespace Director
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user