Skip to content
This repository has been archived by the owner on Jul 14, 2018. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/HaCk3Dq/vk
Browse files Browse the repository at this point in the history
  • Loading branch information
HaCk3Dq committed Apr 24, 2016
2 parents c31aba0 + 97b68c8 commit afd8fda
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@ ListElement[] GetDialogs() {
unreadText,
lastMsg = e.lastMessage.replace("\n", " ");
if (lastMsg.utfLength > COLS-win.menuOffset-newMsg.utfLength-e.name.utfLength-3-e.unreadCount.to!string.length) {
lastMsg = lastMsg.to!wstring[0..COLS-win.menuOffset-newMsg.utfLength-e.name.utfLength-8-e.unreadCount.to!string.length].to!string;
lastMsg = lastMsg.toUTF16wrepl[0..COLS-win.menuOffset-newMsg.utfLength-e.name.utfLength-8-e.unreadCount.to!string.length].toUTF8wrepl;
}
if (e.unreadCount != 0) {
if (e.unread) unreadText ~= e.unreadCount.to!string ~ inbox;
Expand Down
31 changes: 27 additions & 4 deletions source/utils.d
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,9 @@ auto inputRetro(R)(R range) {
}

alias Repldchar = std.typecons.Flag!"useReplacementDchar";
const Repldchar repl = Repldchar.yes;

wstring toUTF16wrepl(in char[] s) @safe {
const Repldchar repl = Repldchar.yes;

wstring toUTF16wrepl(in char[] s) {
wchar[] r;
size_t slen = s.length;

Expand All @@ -314,7 +313,31 @@ wstring toUTF16wrepl(in char[] s) @safe {
}
}

return r.toUTF16;
return cast(wstring)r;
}

string toUTF8wrepl(in wchar[] s) {
char[] r;
size_t i;
size_t slen = s.length;

r.length = slen;
for (i = 0; i < slen; i++)
{
wchar c = s[i];

if (c <= 0x7F)
r[i] = cast(char)c; // fast path for ascii
else
{
r.length = i;
while (i < slen)
encode(r, decode!repl(s, i));
break;
}
}

return cast(string)r;
}


Expand Down

0 comments on commit afd8fda

Please sign in to comment.