1 module nxt.string_store; 2 3 import nxt.variant_arrays; 4 5 @safe pure: 6 7 /** Store sets of strings with different lengths compactly. 8 */ 9 struct StringStore 10 { 11 @safe pure: 12 void insertBack(string value) nothrow @nogc 13 { 14 switch (value.length) 15 { 16 // TODO static foreach 17 case 1: _store.insertBack(cast(char[1])value[0 .. 1]); break; 18 case 2: _store.insertBack(cast(char[2])value[0 .. 2]); break; 19 case 3: _store.insertBack(cast(char[3])value[0 .. 3]); break; 20 case 4: _store.insertBack(cast(char[4])value[0 .. 4]); break; 21 case 5: _store.insertBack(cast(char[5])value[0 .. 5]); break; 22 case 6: _store.insertBack(cast(char[6])value[0 .. 6]); break; 23 case 7: _store.insertBack(cast(char[7])value[0 .. 7]); break; 24 case 8: _store.insertBack(cast(char[8])value[0 .. 8]); break; 25 default: 26 _store.insertBack(value); 27 } 28 } 29 private: 30 VariantArrays!(char[1], 31 char[2], 32 char[3], 33 char[4], 34 char[5], 35 char[6], 36 char[7], 37 char[8], 38 string) _store; 39 } 40 41 /// 42 @safe pure nothrow @nogc unittest 43 { 44 StringStore ss; 45 ss.insertBack("alpha"); 46 ss.insertBack("beta"); 47 }