1 /*******************************************************************************
2 
3         Copyright:
4             Copyright (c) 2004 Kris Bell.
5             Some parts copyright (c) 2009-2016 dunnhumby Germany GmbH.
6             All rights reserved.
7 
8         License:
9             Tango Dual License: 3-Clause BSD License / Academic Free License v3.0.
10             See LICENSE_TANGO.txt for details.
11 
12         Version: Initial release: December 2005
13 
14         Authors: Kris
15 
16 *******************************************************************************/
17 
18 module ocean.net.http.HttpTriplet;
19 
20 import ocean.meta.types.Qualifiers;
21 
22 /******************************************************************************
23 
24         Class to represent an HTTP response- or request-line
25 
26 ******************************************************************************/
27 
28 class HttpTriplet
29 {
30         protected char[]        line;
31         protected char[]        failed;
32         protected char[][3]     tokens;
33 
34         /**********************************************************************
35 
36                 test the validity of these tokens
37 
38         **********************************************************************/
39 
40         abstract bool test ();
41 
42         /**********************************************************************
43 
44                 Parse the the given line into its constituent components.
45 
46         **********************************************************************/
47 
48         bool parse (char[] line)
49         {
50                 size_t i;
51                 size_t mark;
52 
53                 this.line = line;
54                 foreach (size_t index, char c; line)
55                          if (c is ' ')
56                          {
57                              if (i < 2)
58                              {
59                                 tokens[i] = line[mark .. index];
60                                 mark = index+1;
61                                 ++i;
62                              }
63                              else
64                                 break;
65                          }
66 
67                 tokens[2] = line [mark .. line.length];
68                 return test;
69         }
70 
71         /**********************************************************************
72 
73                 return a copy of the original string
74 
75         **********************************************************************/
76 
77         override istring toString ()
78         {
79                 return idup(line);
80         }
81 
82         /**********************************************************************
83 
84                 return error string after a failed parse()
85 
86         **********************************************************************/
87 
88         final char[] error ()
89         {
90                 return failed;
91         }
92 }