MCPcopy Create free account
hub / github.com/9chu/LuaSTGPlus / closeValue

Method closeValue

LuaSTGPlus/Bencode.cpp:148–217  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148bool Decoder::closeValue()
149{
150 DecoderInternalState tState = (DecoderInternalState)m_State;
151 m_State = (int)DecoderInternalState::Start;
152
153 Value tValue;
154 switch (tState)
155 {
156 case DecoderInternalState::Start:
157 if (m_StackValue.empty())
158 throw logic_error("unexpected end of object.");
159 tValue = std::move(m_StackValue.top());
160 m_StackValue.pop();
161 if (tValue.Type == ValueType::Dictionary)
162 {
163 if (m_DictReadState.top() != (int)DictReadState::KeyExpected)
164 throw logic_error("key-value pair expected.");
165 m_DictReadState.pop();
166 }
167 break;
168 case DecoderInternalState::ParseNull:
169 tValue.Type = ValueType::Null;
170 break;
171 case DecoderInternalState::ParseIntSign:
172 case DecoderInternalState::ParseIntPart:
173 tValue.Type = ValueType::Int;
174 tValue.VInt = m_TempIntNeg ? -m_TempInt : m_TempInt;
175 break;
176 case DecoderInternalState::ParseString:
177 case DecoderInternalState::ParseStringContent:
178 tValue.Type = ValueType::String;
179 tValue.VString = m_TempString;
180 break;
181 default:
182 throw logic_error("internal error.");
183 }
184
185 if (m_StackValue.empty())
186 {
187 m_RootValue = std::move(tValue);
188 return true;
189 }
190
191 switch (m_StackValue.top().Type)
192 {
193 case ValueType::List:
194 m_StackValue.top().VList.emplace_back(make_shared<Value>(std::move(tValue)));
195 break;
196 case ValueType::Dictionary:
197 if (m_DictReadState.top() == (int)DictReadState::KeyExpected)
198 {
199 if (tValue.Type != ValueType::String)
200 throw logic_error("key must be a string.");
201 m_DictKeyState.emplace(std::move(tValue.VString));
202 m_DictReadState.top() = (int)DictReadState::ValueExpected;
203 }
204 else
205 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected