-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLEO V2.0.0.7 #19
CLEO V2.0.0.7 #19
Conversation
source/III.VC.CLEO/Fxt.cpp
Outdated
for(size_t i = 0; i < len; i++) | ||
this->m_pText[i] = (unsigned char)text[i]; | ||
this->m_pText[len] = 0; | ||
uint16_t* u16_text = new uint16_t[len + 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use wchar_t ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact, it is better to use the uint16_t type, first of all it is more intuitive to tell us that it is 2 bytes (although the cleo library runs on win, but I have planned to port it to the mobile platform, the wchar_t type is not 2 bytes in some systems ), another reason is that my experience in Chinese games tells me that you should never use the wchar_t type to save Chinese characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps then
typedef uint16_t wchar
is most elegant solution.
source/III.VC.CLEO/Fxt.cpp
Outdated
this->m_pText[i] = (unsigned char)text[i]; | ||
this->m_pText[len] = 0; | ||
uint16_t* u16_text = new uint16_t[len + 1]; | ||
memset(u16_text, 0, len + 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memset takes bytes count to set, so it will fill only half of the buffer. Maybe use std::fill instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I forgot, now it only has half the memory written with 0's.
Forgive me I prefer c style
source/III.VC.CLEO/Fxt.cpp
Outdated
@@ -24,6 +24,40 @@ CustomTextEntry::~CustomTextEntry() | |||
delete m_pText; | |||
} | |||
|
|||
static uint8_t get_utf8_bytes(uint8_t utf8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return regular number. Input type should be character. Function could be named better, like "get_utf8_character_size".
Parameter could be named "firstChar".
It would be nice to include comment with link:
https://en.wikipedia.org/wiki/UTF-8#Encoding
source/III.VC.CLEO/Fxt.cpp
Outdated
@@ -24,6 +24,40 @@ CustomTextEntry::~CustomTextEntry() | |||
delete m_pText; | |||
} | |||
|
|||
static uint8_t get_utf8_bytes(uint8_t utf8) | |||
{ | |||
for (uint8_t i = 0; i < 6; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This project is using "opening bracket in new line" style. Better keep it consistent.
source/III.VC.CLEO/Fxt.cpp
Outdated
return 1; | ||
} | ||
|
||
uint16_t CustomText::convert_utf8_to_utf16(uint8_t* utf8, uint16_t utf8_len, uint16_t* utf16, uint16_t utf16_len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use char\wchar_t for characters, int\unsigned int for counts.
source/III.VC.CLEO/Fxt.cpp
Outdated
bytes = get_utf8_bytes(utf8[i]); | ||
|
||
if (bytes > 1) { | ||
utf16[length] = utf8[i] & (0xFF >> (bytes + 1)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many magic in single line. How about creating variable named "mask", then using in. Comments would be nice too.
source/III.VC.CLEO/Fxt.cpp
Outdated
for (uint8_t j = 1; j < bytes; j++) { | ||
i++; | ||
utf16[length] <<= 6; | ||
utf16[length] += utf8[i] & 0x3F; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Magic numbers? 0x3F comes out of blue without any explanation.
source/III.VC.CLEO/Fxt.cpp
Outdated
if (bytes > 1) { | ||
utf16[length] = utf8[i] & (0xFF >> (bytes + 1)); | ||
for (uint8_t j = 1; j < bytes; j++) { | ||
i++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can now i address out of data buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can change its name, although it doesn't matter
Please rebase on current master branch. We added some of similar changes already, so this PR will become simpler. |
fix #16