MCPcopy Create free account
hub / github.com/cuberite/cuberite / Parse

Method Parse

src/HTTPServer/NameValueParser.cpp:96–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94
95
96void cNameValueParser::Parse(const char * a_Data, size_t a_Size)
97{
98 ASSERT(m_State != psFinished); // Calling Parse() after Finish() is wrong!
99
100 int Last = 0;
101 for (size_t i = 0; i < a_Size;)
102 {
103 switch (m_State)
104 {
105 case psInvalid:
106 case psFinished:
107 {
108 return;
109 }
110
111 case psKeySpace:
112 {
113 // Skip whitespace until a non-whitespace is found, then start the key:
114 while ((i < a_Size) && (a_Data[i] <= ' '))
115 {
116 i++;
117 }
118 if ((i < a_Size) && (a_Data[i] > ' '))
119 {
120 m_State = psKey;
121 Last = i;
122 }
123 break;
124 }
125
126 case psKey:
127 {
128 // Read the key until whitespace or an equal sign:
129 while (i < a_Size)
130 {
131 if (a_Data[i] == '=')
132 {
133 m_CurrentKey.append(a_Data + Last, i - Last);
134 i++;
135 Last = i;
136 m_State = psEqual;
137 break;
138 }
139 else if (a_Data[i] <= ' ')
140 {
141 m_CurrentKey.append(a_Data + Last, i - Last);
142 i++;
143 Last = i;
144 m_State = psEqualSpace;
145 break;
146 }
147 else if (a_Data[i] == ';')
148 {
149 if (!m_AllowsKeyOnly)
150 {
151 m_State = psInvalid;
152 return;
153 }

Callers 1

cNameValueParserTestMethod · 0.45

Calls 1

clearMethod · 0.80

Tested by

no test coverage detected