1 module cif.tiploc; 2 3 import std.string : strip; 4 5 struct TiplocInsert 6 { 7 string tiplocCode; 8 string capitalsIdentification; 9 string nationalLocationCode; 10 char checkCharacter; 11 string tpsDescription; 12 string stanox; 13 string postOfficeLocationCode; 14 string crsCode; 15 string description; 16 17 this(string record) 18 { 19 this.tiplocCode = strip(record[2 .. 9]); 20 this.capitalsIdentification = record[9 .. 11]; 21 this.nationalLocationCode = record[11 .. 17]; 22 this.checkCharacter = record[17]; 23 this.tpsDescription = strip(record[18 .. 44]); 24 this.stanox = record[44 .. 49]; 25 this.postOfficeLocationCode = record[49 .. 53]; 26 this.crsCode = record[53 .. 56]; 27 this.description = strip(record[56 .. 72]); 28 } 29 30 unittest 31 { 32 auto line = "TIBHAMNWS40112700EBIRMINGHAM NEW STREET 656302810BHMBIRMINGHAM N ST "; 33 const TiplocInsert inserted = TiplocInsert(line); 34 35 assert(inserted.tiplocCode == "BHAMNWS"); 36 assert(inserted.capitalsIdentification == "40"); 37 assert(inserted.nationalLocationCode == "112700"); 38 assert(inserted.checkCharacter == 'E'); 39 assert(inserted.tpsDescription == "BIRMINGHAM NEW STREET"); 40 assert(inserted.stanox == "65630"); 41 assert(inserted.postOfficeLocationCode == "2810"); 42 assert(inserted.crsCode == "BHM"); 43 assert(inserted.description == "BIRMINGHAM N ST"); 44 } 45 } 46 47 struct TiplocAmend 48 { 49 string tiplocCode; 50 string capitalsIdentification; 51 string nationalLocationCode; 52 char checkCharacter; 53 string tpsDescription; 54 string stanox; 55 string postOfficeLocationCode; 56 string crsCode; 57 string description; 58 string newTiplocCode; 59 60 this(string record) 61 { 62 this.tiplocCode = strip(record[2 .. 9]); 63 this.capitalsIdentification = record[9 .. 11]; 64 this.nationalLocationCode = record[11 .. 17]; 65 this.checkCharacter = record[17]; 66 this.tpsDescription = strip(record[18 .. 44]); 67 this.stanox = record[44 .. 49]; 68 this.postOfficeLocationCode = record[49 .. 53]; 69 this.crsCode = record[53 .. 56]; 70 this.description = strip(record[56 .. 72]); 71 this.newTiplocCode = strip(record[72 .. 79]); 72 } 73 74 unittest 75 { 76 auto line = "TABHAMNWS40112700EBIRMINGHAM NEW STREET 656302810BHMBIRMINGHAM N ST BHAMNWS "; 77 const TiplocAmend amended = TiplocAmend(line); 78 79 assert(amended.tiplocCode == "BHAMNWS"); 80 assert(amended.capitalsIdentification == "40"); 81 assert(amended.nationalLocationCode == "112700"); 82 assert(amended.checkCharacter == 'E'); 83 assert(amended.tpsDescription == "BIRMINGHAM NEW STREET"); 84 assert(amended.stanox == "65630"); 85 assert(amended.postOfficeLocationCode == "2810"); 86 assert(amended.crsCode == "BHM"); 87 assert(amended.description == "BIRMINGHAM N ST"); 88 assert(amended.newTiplocCode == "BHAMNWS"); 89 } 90 } 91 92 struct TiplocDelete 93 { 94 string tiplocCode; 95 96 this(string record) 97 { 98 this.tiplocCode = strip(record[2 .. 9]); 99 } 100 101 unittest 102 { 103 auto line = "TDBHAMNWS "; 104 const TiplocDelete deleted = TiplocDelete(line); 105 106 assert(deleted.tiplocCode == "BHAMNWS"); 107 } 108 }