| 217 | } |
| 218 | |
| 219 | bool Decoder::operator<<(char c) |
| 220 | { |
| 221 | try |
| 222 | { |
| 223 | switch ((DecoderInternalState)m_State) |
| 224 | { |
| 225 | case DecoderInternalState::Start: |
| 226 | switch (c) |
| 227 | { |
| 228 | case 'n': |
| 229 | m_State = (int)DecoderInternalState::ParseNull; |
| 230 | if (closeValue()) |
| 231 | return true; |
| 232 | break; |
| 233 | case 'i': |
| 234 | m_TempInt = 0; |
| 235 | m_TempIntNeg = false; |
| 236 | m_State = (int)DecoderInternalState::ParseIntSign; |
| 237 | break; |
| 238 | case 'l': |
| 239 | m_StackValue.emplace(Value(ValueType::List)); |
| 240 | break; |
| 241 | case 'd': |
| 242 | m_StackValue.emplace(Value(ValueType::Dictionary)); |
| 243 | m_DictReadState.emplace((int)DictReadState::KeyExpected); |
| 244 | break; |
| 245 | case 'e': |
| 246 | if (closeValue()) |
| 247 | return true; |
| 248 | break; |
| 249 | default: |
| 250 | if (c >= '0' && c <= '9') |
| 251 | { |
| 252 | m_TempInt = c - '0'; |
| 253 | m_TempString.clear(); |
| 254 | m_State = (int)DecoderInternalState::ParseString; |
| 255 | } |
| 256 | else |
| 257 | throw logic_error("unexpected character."); |
| 258 | } |
| 259 | break; |
| 260 | case DecoderInternalState::ParseIntSign: |
| 261 | if (c == '-') |
| 262 | { |
| 263 | m_TempIntNeg = true; |
| 264 | m_State = (int)DecoderInternalState::ParseIntPart; |
| 265 | } |
| 266 | else if (c >= '0' && c <= '9') |
| 267 | { |
| 268 | m_TempInt = c - '0'; |
| 269 | m_State = (int)DecoderInternalState::ParseIntPart; |
| 270 | } |
| 271 | else |
| 272 | throw logic_error("unexpected character."); |
| 273 | break; |
| 274 | case DecoderInternalState::ParseIntPart: |
| 275 | if (c >= '0' && c <= '9') |
| 276 | m_TempInt = m_TempInt * 10 + c - '0'; |