- clipboard working now for utf8
This commit is contained in:
parent
0bbb65fdda
commit
f97e8d5fc3
|
@ -1 +1 @@
|
||||||
Subproject commit c3ef4617d38e0062ab4835c5d5662a9580f1f095
|
Subproject commit bf04854ade7cd0fc51483c857e590acfef4fbc26
|
|
@ -99,19 +99,12 @@ bool ChatManager::textInput(std::string inputText) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] inputText [%s]\n",__FILE__,__FUNCTION__,__LINE__,inputText.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] inputText [%s]\n",__FILE__,__FUNCTION__,__LINE__,inputText.c_str());
|
||||||
|
|
||||||
int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght);
|
int maxTextLenAllowed = (customCB != NULL ? this->maxCustomTextLength : maxTextLenght);
|
||||||
//int maxpaste = 0;
|
|
||||||
//maxpaste = maxTextLenAllowed - text.length();
|
|
||||||
//maxpaste = maxTextLenAllowed - getTextByteLength();
|
|
||||||
//string textToAdd = inputText.substr (0,maxpaste);
|
|
||||||
|
|
||||||
string textToAdd = getTextWithLengthCheck(inputText,textCharLength.size(),maxTextLenAllowed);
|
string textToAdd = getTextWithLengthCheck(inputText,textCharLength.size(),maxTextLenAllowed);
|
||||||
|
|
||||||
if(editEnabled && (int)textCharLength.size() < maxTextLenAllowed && textToAdd.size() > 0) {
|
if(editEnabled && (int)textCharLength.size() < maxTextLenAllowed && textToAdd.size() > 0) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
WString addText(textToAdd);
|
appendText(textToAdd, true, true);
|
||||||
appendText(addText.cw_str(), true, true);
|
|
||||||
|
|
||||||
updateAutoCompleteBuffer();
|
updateAutoCompleteBuffer();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -119,62 +112,22 @@ bool ChatManager::textInput(std::string inputText) {
|
||||||
}
|
}
|
||||||
|
|
||||||
string ChatManager::getTextWithLengthCheck(string addText, int currentLength, int maxLength) {
|
string ChatManager::getTextWithLengthCheck(string addText, int currentLength, int maxLength) {
|
||||||
|
|
||||||
printf("len check text [%s] curlen: %d maxlen: %d\n",addText.c_str(),currentLength,maxLength);
|
|
||||||
|
|
||||||
string resultText = "";
|
string resultText = "";
|
||||||
if(addText.empty() == false) {
|
if(addText.empty() == false) {
|
||||||
int utf8CharsAdded = 0;
|
int utf8CharsAdded = 0;
|
||||||
WString addTextW(addText);
|
for(unsigned int index = 0; index < addText.size(); ) {
|
||||||
const wchar_t *addTextPtr = addTextW.cw_str();
|
int len = getUTF8_Width(&addText[index]);
|
||||||
printf("wcslen(addTextPtr)=%d\n",(int)wcslen(addTextPtr));
|
|
||||||
for(unsigned int i = 0; i < wcslen(addTextPtr); ++i) {
|
|
||||||
wchar_t key = addTextPtr[i];
|
|
||||||
//if(isAllowedInputTextKey(key) == true && key != 10)
|
|
||||||
if(true)
|
|
||||||
{
|
|
||||||
char buf[4] = {0};
|
|
||||||
if (key < 0x80) {
|
|
||||||
printf("#1 len check cur: %d max: %d\n",currentLength + utf8CharsAdded,maxLength);
|
|
||||||
buf[0] = key;
|
|
||||||
}
|
|
||||||
else if (key < 0x800) {
|
|
||||||
printf("#2 len check cur: %d max: %d\n",currentLength + utf8CharsAdded,maxLength);
|
|
||||||
buf[0] = (0xC0 | key >> 6);
|
|
||||||
buf[1] = (0x80 | (key & 0x3F));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("#3 len check cur: %d max: %d\n",currentLength + utf8CharsAdded,maxLength);
|
|
||||||
buf[0] = (0xE0 | key >> 12);
|
|
||||||
buf[1] = (0x80 | (key >> 6 & 0x3F));
|
|
||||||
buf[2] = (0x80 | (key & 0x3F));
|
|
||||||
}
|
|
||||||
utf8CharsAdded++;
|
utf8CharsAdded++;
|
||||||
if(currentLength + utf8CharsAdded > maxLength) {
|
if(currentLength + utf8CharsAdded > maxLength) {
|
||||||
printf("break;");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
resultText += buf;
|
resultText += addText.substr(index,len);
|
||||||
}
|
index += len;
|
||||||
else {
|
|
||||||
//printf("len check char NOT ALLOWED at pos: %d\n",i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//printf("len check resultText: %s\n",resultText.c_str());
|
|
||||||
return resultText;
|
return resultText;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ChatManager::getTextByteLength() {
|
|
||||||
int byteLength = 0;
|
|
||||||
if(text.empty() == false && textCharLength.empty() == false) {
|
|
||||||
for(unsigned int i = 0; i < textCharLength.size(); ++i) {
|
|
||||||
byteLength+= textCharLength[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return byteLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ChatManager::keyDown(SDL_KeyboardEvent key) {
|
void ChatManager::keyDown(SDL_KeyboardEvent key) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] key = [%c] [%d]\n",__FILE__,__FUNCTION__,__LINE__,key.keysym.sym,key.keysym.sym);
|
||||||
|
|
||||||
|
@ -389,8 +342,7 @@ void ChatManager::keyDown(SDL_KeyboardEvent key) {
|
||||||
else {
|
else {
|
||||||
//printf("ADD: currentAutoCompleteName [%s] autoCompleteResult [%s] text [%s]\n",currentAutoCompleteName.c_str(),autoCompleteResult.c_str(),text.c_str());
|
//printf("ADD: currentAutoCompleteName [%s] autoCompleteResult [%s] text [%s]\n",currentAutoCompleteName.c_str(),autoCompleteResult.c_str(),text.c_str());
|
||||||
}
|
}
|
||||||
WString addText(autoCompleteResult);
|
appendText(autoCompleteResult, false, false);
|
||||||
appendText(addText.cw_str(), false, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -462,40 +414,19 @@ void ChatManager::deleteText(int deleteCount,bool addToAutoCompleteBuffer) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatManager::appendText(const wchar_t *addText, bool validateChars, bool addToAutoCompleteBuffer) {
|
void ChatManager::appendText(string addText, bool validateChars, bool addToAutoCompleteBuffer) {
|
||||||
for(unsigned int i = 0; i < wcslen(addText); ++i) {
|
|
||||||
wchar_t key = addText[i];
|
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("appendText key [%d]\n\n",(int)key);
|
|
||||||
|
|
||||||
if(validateChars == false ||
|
for(unsigned int index = 0; index < addText.size(); ) {
|
||||||
(isAllowedInputTextKey(key) == true && key != 10)) {
|
int len = getUTF8_Width(&addText[index]);
|
||||||
char buf[4] = {0};
|
textCharLength.push_back(len);
|
||||||
if (key < 0x80) {
|
text += addText.substr(index,len);
|
||||||
buf[0] = key;
|
index += len;
|
||||||
textCharLength.push_back(1);
|
|
||||||
//printf("1 char, textCharLength = %d\n",textCharLength.size());
|
|
||||||
}
|
|
||||||
else if (key < 0x800) {
|
|
||||||
buf[0] = (0xC0 | key >> 6);
|
|
||||||
buf[1] = (0x80 | (key & 0x3F));
|
|
||||||
textCharLength.push_back(2);
|
|
||||||
//printf("2 char, textCharLength = %d\n",textCharLength.size());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
buf[0] = (0xE0 | key >> 12);
|
|
||||||
buf[1] = (0x80 | (key >> 6 & 0x3F));
|
|
||||||
buf[2] = (0x80 | (key & 0x3F));
|
|
||||||
textCharLength.push_back(3);
|
|
||||||
//printf("3 char, textCharLength = %d\n",textCharLength.size());
|
|
||||||
}
|
|
||||||
text += buf;
|
|
||||||
|
|
||||||
if(addToAutoCompleteBuffer == true) {
|
if(addToAutoCompleteBuffer == true) {
|
||||||
updateAutoCompleteBuffer();
|
updateAutoCompleteBuffer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void ChatManager::updateAutoCompleteBuffer() {
|
void ChatManager::updateAutoCompleteBuffer() {
|
||||||
if(text.empty() == false) {
|
if(text.empty() == false) {
|
||||||
|
|
|
@ -70,8 +70,7 @@ private:
|
||||||
int maxCustomTextLength;
|
int maxCustomTextLength;
|
||||||
|
|
||||||
string getTextWithLengthCheck(string text, int currentLength, int maxLength);
|
string getTextWithLengthCheck(string text, int currentLength, int maxLength);
|
||||||
int getTextByteLength();
|
void appendText(string addText, bool validateChars=true,bool addToAutoCompleteBuffer=true);
|
||||||
void appendText(const wchar_t *addText, bool validateChars=true,bool addToAutoCompleteBuffer=true);
|
|
||||||
void deleteText(int deleteCount,bool addToAutoCompleteBuffer=true);
|
void deleteText(int deleteCount,bool addToAutoCompleteBuffer=true);
|
||||||
void updateAutoCompleteBuffer();
|
void updateAutoCompleteBuffer();
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,8 @@ namespace Shared { namespace Util {
|
||||||
void strrev_utf8(std::string &p);
|
void strrev_utf8(std::string &p);
|
||||||
bool is_string_all_ascii(std::string str);
|
bool is_string_all_ascii(std::string str);
|
||||||
|
|
||||||
|
int getUTF8_Width(const char *str);
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
#endif // _SHARED_UTIL_W_STRING_H__
|
#endif // _SHARED_UTIL_W_STRING_H__
|
||||||
|
|
|
@ -309,6 +309,31 @@ namespace Shared { namespace Util {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getUTF8_Width(const char *str) {
|
||||||
|
int ewidth = 0;
|
||||||
|
const unsigned char *s = (const unsigned char *)str;
|
||||||
|
if (!str) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if(*s <= 0x7F) {
|
||||||
|
ewidth = 0;
|
||||||
|
}
|
||||||
|
else if (0xC2 <= *s && *s <= 0xDF) {
|
||||||
|
ewidth = 1;
|
||||||
|
}
|
||||||
|
else if (0xE0 <= *s && *s <= 0xEF) {
|
||||||
|
ewidth = 2;
|
||||||
|
}
|
||||||
|
else if (0xF0 <= *s && *s <= 0xF4) {
|
||||||
|
ewidth = 3;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ewidth = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ( ; *s && ewidth > 0; s++, ewidth--);
|
||||||
|
|
||||||
|
return s - (const unsigned char *)str + 1;
|
||||||
|
}
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user