summaryrefslogtreecommitdiff
path: root/protocols/FacebookRM/src/utils.cpp
diff options
context:
space:
mode:
authorRobert Pösel <robyer@seznam.cz>2014-11-28 19:06:56 +0000
committerRobert Pösel <robyer@seznam.cz>2014-11-28 19:06:56 +0000
commitb063b7878c47f85f0760d8fdf9595e3b8b3540cf (patch)
tree0b38eaa352a8fac90d44cc3f491bf782effa3d3a /protocols/FacebookRM/src/utils.cpp
parent7fb13d1cfb7528d617406bd4701cc13d7a64abd4 (diff)
Facebook: Improve append_ordinal() and use of it
It should fix receiving very special characters in messages but probably it won't make any differences in real use... git-svn-id: http://svn.miranda-ng.org/main/trunk@11132 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'protocols/FacebookRM/src/utils.cpp')
-rw-r--r--protocols/FacebookRM/src/utils.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/protocols/FacebookRM/src/utils.cpp b/protocols/FacebookRM/src/utils.cpp
index 38bde17e73..e4424f0b25 100644
--- a/protocols/FacebookRM/src/utils.cpp
+++ b/protocols/FacebookRM/src/utils.cpp
@@ -133,7 +133,11 @@ unsigned int utils::text::count_all(std::string* data, const std::string &term)
void utils::text::append_ordinal(unsigned long value, std::string* data)
{
- if (value >= 128 && value <= 2047)
+ if (value <= 127)
+ { // U+0000 .. U+007F
+ *data += (char)value;
+ }
+ else if (value >= 128 && value <= 2047)
{ // U+0080 .. U+07FF
*data += (char)(192 + (value / 64));
*data += (char)(128 + (value % 64));
@@ -144,9 +148,12 @@ void utils::text::append_ordinal(unsigned long value, std::string* data)
*data += (char)(128 + ((value / 64) % 64));
*data += (char)(128 + (value % 64));
}
- else if (value <= 127)
- { // U+0000 .. U+007F
- *data += (char)value;
+ else
+ {
+ *data += (char)((value >> 24) & 0xFF);
+ *data += (char)((value >> 16) & 0xFF);
+ *data += (char)((value >> 8) & 0xFF);
+ *data += (char)((value) & 0xFF);
}
}
@@ -189,7 +196,7 @@ std::string utils::text::html_entities_decode(std::string data)
std::string num = data.substr(i, comma - i);
if (!num.empty()) {
- unsigned int udn = strtol(num.c_str(), NULL, hexa ? 16 : 10);
+ unsigned long udn = strtoul(num.c_str(), NULL, hexa ? 16 : 10);
utils::text::append_ordinal(udn, &new_string);
}
@@ -320,7 +327,7 @@ std::string utils::text::slashu_to_utf8(const std::string &data)
{
if (data.at(i) == '\\' && (i+1) < data.length() && data.at(i+1) == 'u')
{
- unsigned int udn = strtol(data.substr(i + 2, 4).c_str(), NULL, 16);
+ unsigned long udn = strtoul(data.substr(i + 2, 4).c_str(), NULL, 16);
append_ordinal(udn, &new_string);
i += 5;
continue;