1 module cif.routechange; 2 3 import std.conv : to; 4 import std.string : strip; 5 6 struct RouteChange 7 { 8 string location; 9 char suffix; 10 string category; 11 string identity; 12 string headcode; 13 char courseIndicator; 14 string serviceCode; 15 char portionId; 16 string powerType; 17 string timingLoad; 18 int speed; 19 string operatingCharacteristics; 20 char seatingClass; 21 char sleepers; 22 char reservations; 23 char connectionIndicator; 24 string cateringCode; 25 string serviceBranding; 26 string tractionClass; 27 string uicCode; 28 string reservationSystemId; 29 30 this(string record) 31 { 32 this.location = strip(record[2 .. 9]); 33 this.suffix = record[9]; 34 this.category = record[10 .. 12]; 35 this.identity = record[12 .. 16]; 36 this.headcode = strip(record[16 .. 20]); 37 this.courseIndicator = record[20]; 38 this.serviceCode = record[21 .. 29]; 39 this.portionId = record[29]; 40 this.powerType = record[30 .. 33]; 41 this.timingLoad = strip(record[33 .. 37]); 42 43 if (record[37] != ' ') 44 { 45 this.speed = to!int(record[37 .. 40]); 46 } 47 48 this.operatingCharacteristics = record[40 .. 46]; 49 this.seatingClass = record[46]; 50 this.sleepers = record[47]; 51 this.reservations = record[48]; 52 this.connectionIndicator = record[49]; 53 this.cateringCode = strip(record[50 .. 54]); 54 this.serviceBranding = strip(record[54 .. 58]); 55 this.tractionClass = strip(record[58 .. 62]); 56 this.uicCode = strip(record[62 .. 67]); 57 this.reservationSystemId = strip(record[67 .. 75]); 58 } 59 60 unittest 61 { 62 auto line = "CRBRSTLTM XX1B048508125460001 DMUE 090 S S GW850800 "; 63 const RouteChange changesEnRoute = RouteChange(line); 64 65 assert(changesEnRoute.location == "BRSTLTM"); 66 assert(changesEnRoute.suffix == ' '); 67 assert(changesEnRoute.category == "XX"); 68 assert(changesEnRoute.identity == "1B04"); 69 assert(changesEnRoute.headcode == "8508"); 70 assert(changesEnRoute.courseIndicator == '1'); 71 assert(changesEnRoute.serviceCode == "25460001"); 72 assert(changesEnRoute.portionId == ' '); 73 assert(changesEnRoute.powerType == "DMU"); 74 assert(changesEnRoute.timingLoad == "E"); 75 assert(changesEnRoute.speed == 90); 76 assert(changesEnRoute.operatingCharacteristics == " "); 77 assert(changesEnRoute.seatingClass == 'S'); 78 assert(changesEnRoute.sleepers == ' '); 79 assert(changesEnRoute.reservations == 'S'); 80 assert(changesEnRoute.connectionIndicator == ' '); 81 assert(changesEnRoute.cateringCode == ""); 82 assert(changesEnRoute.serviceBranding == ""); 83 assert(changesEnRoute.tractionClass == ""); 84 assert(changesEnRoute.uicCode == ""); 85 assert(changesEnRoute.reservationSystemId == "GW850800"); 86 } 87 }