Skip to content

Commit

Permalink
Merge pull request #733 from sinkuu/fix_encode
Browse files Browse the repository at this point in the history
Fix encoding in put(dchar)
  • Loading branch information
s-ludwig committed Jul 17, 2014
2 parents eccdb6d + 64d90bb commit d0ae87b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 9 additions & 1 deletion source/vibe/core/stream.d
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,17 @@ interface OutputStream {
/// ditto
deprecated("Please use vibe.stream.wrapper.StreamOutputRange instead.")
final void put(in char[] elems) { write(elems); }

/// ditto
deprecated("Please use vibe.stream.wrapper.StreamOutputRange instead.")
final void put(dchar elem) { import std.utf; char[4] chars; encode(chars, elem); put(chars); }
final void put(dchar elem)
{
import std.utf;
char[4] chars;
auto len = encode(chars, elem);
put(chars[0 .. len]);
}

/// ditto
deprecated("Please use vibe.stream.wrapper.StreamOutputRange instead.")
final void put(in dchar[] elems) { foreach( ch; elems ) put(ch); }
Expand Down
11 changes: 9 additions & 2 deletions source/vibe/stream/wrapper.d
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,13 @@ struct StreamOutputRange {
void put(char elem) { put(cast(ubyte)elem); }
void put(const(char)[] elems) { put(cast(const(ubyte)[])elems); }

void put(dchar elem) { import std.utf; char[4] chars; encode(chars, elem); put(chars); }
void put(dchar elem)
{
import std.utf;
char[4] chars;
auto len = encode(chars, elem);
put(chars[0 .. len]);
}

void put(const(dchar)[] elems) { foreach( ch; elems ) put(ch); }
}
}

0 comments on commit d0ae87b

Please sign in to comment.