1 | /*
|
---|
2 | ###############################################################################
|
---|
3 | #
|
---|
4 | # Temboo Arduino library
|
---|
5 | #
|
---|
6 | # Copyright 2014, Temboo Inc.
|
---|
7 | #
|
---|
8 | # Licensed under the Apache License, Version 2.0 (the "License");
|
---|
9 | # you may not use this file except in compliance with the License.
|
---|
10 | # You may obtain a copy of the License at
|
---|
11 | #
|
---|
12 | # http://www.apache.org/licenses/LICENSE-2.0
|
---|
13 | #
|
---|
14 | # Unless required by applicable law or agreed to in writing,
|
---|
15 | # software distributed under the License is distributed on an
|
---|
16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
---|
17 | # either express or implied. See the License for the specific
|
---|
18 | # language governing permissions and limitations under the License.
|
---|
19 | #
|
---|
20 | ###############################################################################
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include <stddef.h>
|
---|
24 | #include <avr/pgmspace.h>
|
---|
25 | #include "ChoreoPresetFormatter.h"
|
---|
26 | #include "ChoreoPreset.h"
|
---|
27 |
|
---|
28 | static const char TAG_PRESET[] PROGMEM = "\"preset\":";
|
---|
29 |
|
---|
30 | ChoreoPresetFormatter::ChoreoPresetFormatter(const ChoreoPreset* preset) {
|
---|
31 | m_preset = preset;
|
---|
32 | reset();
|
---|
33 | }
|
---|
34 |
|
---|
35 | void ChoreoPresetFormatter::reset() {
|
---|
36 | m_nextChar = NULL;
|
---|
37 | if (m_preset == NULL || m_preset->isEmpty()) {
|
---|
38 | m_nextState = END;
|
---|
39 | } else {
|
---|
40 | m_nextState = START;
|
---|
41 | }
|
---|
42 | }
|
---|
43 |
|
---|
44 | bool ChoreoPresetFormatter::hasNext() {
|
---|
45 | return m_nextState != END;
|
---|
46 | }
|
---|
47 |
|
---|
48 | char ChoreoPresetFormatter::next() {
|
---|
49 | char c = '\0';
|
---|
50 | switch(m_nextState) {
|
---|
51 | case START:
|
---|
52 | c = readStartTagChar(TAG_PRESET, PRESET_TAG);
|
---|
53 | break;
|
---|
54 |
|
---|
55 | case PRESET_TAG:
|
---|
56 | c = readTagChar(NAME_START);
|
---|
57 | break;
|
---|
58 |
|
---|
59 | case NAME_START:
|
---|
60 | c = '"';
|
---|
61 | m_nextChar = m_preset->getName();
|
---|
62 | if ((NULL == m_nextChar) || ('\0' == *m_nextChar)) {
|
---|
63 | m_nextState = NAME_END;
|
---|
64 | } else {
|
---|
65 | m_nextState = NAME;
|
---|
66 | }
|
---|
67 | break;
|
---|
68 |
|
---|
69 | case NAME:
|
---|
70 | c = readValueChar(NAME_END);
|
---|
71 | break;
|
---|
72 |
|
---|
73 | case NAME_END:
|
---|
74 | c = '"';
|
---|
75 | m_nextState = END;
|
---|
76 | break;
|
---|
77 |
|
---|
78 | case END:
|
---|
79 | default:
|
---|
80 | c = '\0';
|
---|
81 | }
|
---|
82 | return c;
|
---|
83 | }
|
---|
84 |
|
---|