Created
September 27, 2015 21:01
-
-
Save Marenz/18e2cb5115b7eb7e2db1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ScopeBuffer ( Type, size_t size = 512 ) | |
{ | |
static import std.internal.scopebuffer; | |
struct Range | |
{ | |
ScopeBuffer!(Type, size)* buf; | |
void put ( T... ) ( auto ref T t ) { this.buf.put(t); } | |
} | |
private Type[size] static_buf; | |
std.internal.scopebuffer.ScopeBuffer!Type sql_buf; | |
alias sql_buf this; | |
@property Range share ( ) | |
{ | |
return Range(&this); | |
} | |
~this ( ) | |
{ | |
import std.stdio; | |
writefln("FREEING %s", &this); | |
sql_buf.free(); | |
} | |
} | |
import std.stdio; | |
auto scopeBuffer ( Type, size_t size = 512 ) ( ) | |
{ | |
static import std.internal.scopebuffer; | |
ScopeBuffer!(Type, size) buf; | |
buf.sql_buf = std.internal.scopebuffer.scopeBuffer(buf.static_buf); | |
writefln("returning from scopebuf"); | |
return buf; | |
} | |
void mysql_escape ( Buffer, Input ) ( Input input, Buffer buffer ) | |
{ | |
import std.string : translate; | |
immutable string[dchar] transTable = [ | |
'\\' : "\\\\", | |
'\'' : "\\'", | |
'\0' : "\\0", | |
'\n' : "\\n", | |
'\r' : "\\r", | |
'\n' : "\\n", | |
'\n' : "\\n", | |
'"' : "\\\"", | |
'\032' : "\\Z" | |
]; | |
translate(input, transTable, null, buffer); | |
} | |
unittest | |
{ | |
auto sql = scopeBuffer!(char, 512)(); | |
mysql_escape("123456", sql.share()); | |
assert(sql.length > 0); | |
assert(sql[] == "123456"); | |
writefln("returning unittest"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment