1 /******************************************************************************* 2 3 copyright: Copyright (c) 2004 Kris Bell. All rights reserved 4 5 license: BSD style: $(LICENSE) 6 7 version: Initial release: December 2005 8 9 author: Kris 10 11 *******************************************************************************/ 12 13 module tango.net.http.HttpTriplet; 14 15 /****************************************************************************** 16 17 Class to represent an HTTP response- or request-line 18 19 ******************************************************************************/ 20 21 class HttpTriplet 22 { 23 protected const(char)[] line; 24 protected const(char)[] failed; 25 protected const(char)[][3] tokens; 26 27 /********************************************************************** 28 29 test the validity of these tokens 30 31 **********************************************************************/ 32 33 abstract bool test (); 34 35 /********************************************************************** 36 37 Parse the the given line into its constituent components. 38 39 **********************************************************************/ 40 41 bool parse (const(char)[] line) 42 { 43 int i; 44 int mark; 45 46 this.line = line; 47 foreach (int index, char c; line) 48 if (c is ' ') 49 { 50 if (i < 2) 51 { 52 tokens[i] = line[mark .. index]; 53 mark = index+1; 54 ++i; 55 } 56 else 57 break; 58 } 59 60 tokens[2] = line [mark .. line.length]; 61 return test(); 62 } 63 64 /********************************************************************** 65 66 return a reference to the original string 67 68 **********************************************************************/ 69 70 override string toString () 71 { 72 return line.idup; 73 } 74 75 /********************************************************************** 76 77 return error string after a failed parse() 78 79 **********************************************************************/ 80 81 final const(char)[] error () 82 { 83 return failed; 84 } 85 } 86 87