1 module cassandra.internal.utils;
2 
3 import std.array : appender;
4 import std.format : formattedWrite;
5 
6 string hex(T)(T v) {
7 	auto buf = appender!string();
8 	ubyte* ptr = cast(ubyte*)&v;
9 	foreach (b; ptr[0..v.sizeof]) {
10 		formattedWrite(buf, "%x ", b);
11 	}
12 	return buf.data;
13 }
14 
15 void enforceValidIdentifier(string text)
16 {
17 	foreach (ch; text) {
18 		switch (ch) {
19 			default: throw new Exception("Invalid identifier, '"~text~"'.");
20 			case 'a': .. case 'z':
21 			case 'A': .. case 'Z':
22 			case '0': .. case '9':
23 			case '_':
24 				break;
25 		}
26 	}
27 }
28 
29 /*void print(ubyte[] data) {
30 	import std.ascii;
31 	foreach (d1; data) {
32 		auto d = cast(char)d1;
33 		if (isPrintable(d)) {
34 			writef("%c ", d);
35 		} else {
36 			writef("%2x ", d);
37 		}
38 	}
39 	writeln();
40 }
41 */
42 
43 
44 
45 /*ubyte[] toBytes(string[string] sm) {
46 	return null;
47 }
48 ubyte[] toBytes(int i) {
49 	return null;
50 }
51 /*void write(Socket s, StringMap data) {
52 	assert(data.length < short.max);
53 	write(s, cast(short)data.length);
54 	foreach (k,v; data) {
55 		writeln("kv:", k, v);
56 		write(s, k);
57 		write(s, v);
58 	}
59 	writeln("wrote StringMap");
60 }
61 
62 /// This implementation even seems to use the compilers implicit casts
63 bool hasUFCSmember(T, string member)() {
64 	T v;
65 	return __traits(compiles, mixin("v."~ member));
66 }*/