void ShuttleGetDefinition::DefineEnum( int&var, const wxChar * key, const int vdefault, wxArrayString strings ) { StartStruct(); AddItem( wxString(key), "key" ); AddItem( "enum", "type" ); if( IsOptional() ) AddItem( "unchanged", "default" ); else AddItem( (double)vdefault, "default" ); StartField( "enum" ); StartArray(); for( size_t i=0;i<strings.Count(); i++ ) AddItem( strings[i] ); EndArray(); EndField(); EndStruct(); }
void CPDF_StreamContentParser::InputData(FX_LPCBYTE src_buf, FX_DWORD src_size) { if (m_Level > _FPDF_MAX_FORM_LEVEL_) { return; } for (FX_DWORD i = 0; i < src_size; i ++) { int ch = src_buf[i]; int type = _PDF_CharType[ch]; start: switch (m_WordState) { case 0: if (type == 'W') { } else if (type == 'N') { m_WordState = 5; m_pWordBuf[0] = ch; m_WordSize = 1; } else if (type == 'R') { m_WordState = 4; m_pWordBuf[0] = ch; m_WordSize = 1; } else switch (ch) { case '/': m_WordState = 2; m_WordSize = 0; break; case '[': StartArray(); break; case ']': EndArray(); break; case '(': m_WordState = 7; m_StringLevel = 1; m_StringState = 0; m_StringBuf.Clear(); break; case '<': m_WordState = 3; break; case '>': m_WordState = 8; break; case '%': m_WordState = 1; break; } break; case 1: if (ch == '\n' || ch == '\r') { m_WordState = 0; } break; case 2: if (type != 'R' && type != 'N') { EndName(); m_WordState = 0; goto start; } if (m_WordSize < 256) { m_pWordBuf[m_WordSize++] = ch; } break; case 3: if (ch == '<') { StartDict(); m_WordState = 0; } else { m_StringBuf.Clear(); m_WordState = 6; goto start; } break; case 4: if (type != 'R' && type != 'N') { m_WordState = 0; EndKeyword(); if (m_bAbort) { return; } goto start; } if (m_WordSize < 256) { m_pWordBuf[m_WordSize++] = ch; } break; case 5: if (type != 'N') { EndNumber(); m_WordState = 0; goto start; } if (m_WordSize < 256) { m_pWordBuf[m_WordSize++] = ch; } break; case 6: if (ch == '>') { EndHexString(); m_WordState = 0; } else { m_StringBuf.AppendByte(ch); } break; case 7: switch (m_StringState) { case 0: if (ch == ')') { m_StringLevel --; if (m_StringLevel == 0) { EndString(); m_WordState = 0; break; } m_StringBuf.AppendByte(')'); } else if (ch == '(') { m_StringLevel ++; m_StringBuf.AppendByte('('); } else if (ch == '\\') { m_StringState = 1; } else { m_StringBuf.AppendByte((char)ch); } break; case 1: if (ch >= '0' && ch <= '7') { m_EscCode = ch - '0'; m_StringState = 2; break; } if (ch == 'n') { m_StringBuf.AppendByte('\n'); } else if (ch == 'r') { m_StringBuf.AppendByte('\r'); } else if (ch == 't') { m_StringBuf.AppendByte('\t'); } else if (ch == 'b') { m_StringBuf.AppendByte('\b'); } else if (ch == 'f') { m_StringBuf.AppendByte('\f'); } else if (ch == '\\') { m_StringBuf.AppendByte('\\'); } else if (ch == '(') { m_StringBuf.AppendByte('('); } else if (ch == ')') { m_StringBuf.AppendByte(')'); } else if (ch == '\r') { m_StringState = 4; break; } else if (ch == '\n') { } else { m_StringBuf.AppendByte(ch); } m_StringState = 0; break; case 2: if (ch >= '0' && ch <= '7') { m_EscCode = m_EscCode * 8 + ch - '0'; m_StringState = 3; } else { m_StringBuf.AppendByte(m_EscCode); m_StringState = 0; goto start; } break; case 3: if (ch >= '0' && ch <= '7') { m_EscCode = m_EscCode * 8 + ch - '0'; m_StringBuf.AppendByte(m_EscCode); m_StringState = 0; } else { m_StringBuf.AppendByte(m_EscCode); m_StringState = 0; goto start; } break; case 4: m_StringState = 0; if (ch != '\n') { goto start; } break; } break; case 8: m_WordState = 0; if (ch == '>') { EndDict(); } else { goto start; } break; case 9: switch (m_InlineImageState) { case 0: if (type == 'W' || type == 'D') { m_InlineImageState = 1; m_InlineWhiteChar = ch; } else { m_StringBuf.AppendByte(ch); } break; case 1: m_StringBuf.AppendByte(m_InlineWhiteChar); if (ch == 'I') { m_InlineImageState = 2; } else { m_InlineImageState = 0; goto start; } break; case 2: if (ch == 'D') { m_InlineImageState = 3; } else { m_StringBuf.AppendByte('I'); m_InlineImageState = 0; goto start; } break; case 3: EndImageDict(); break; } break; case 10: switch (m_InlineImageState) { case 0: if (type == 'W') { m_InlineImageState = 1; m_InlineWhiteChar = ch; } else { m_ImageSrcBuf.AppendByte(ch); } break; case 1: if (ch == 'E') { m_InlineImageState = 2; } else { m_ImageSrcBuf.AppendByte(m_InlineWhiteChar); m_InlineImageState = 0; goto start; } break; case 2: if (ch == 'I') { m_InlineImageState = 3; } else { m_ImageSrcBuf.AppendByte(m_InlineWhiteChar); m_ImageSrcBuf.AppendByte('E'); m_InlineImageState = 0; goto start; } break; case 3: if (type == 'W') { EndInlineImage(); } else { m_ImageSrcBuf.AppendByte(m_InlineWhiteChar); m_ImageSrcBuf.AppendByte('E'); m_ImageSrcBuf.AppendByte('I'); m_InlineImageState = 0; goto start; } break; } break; case 11: if (m_InlineImageState < m_ImageSrcBuf.GetSize()) { m_ImageSrcBuf.GetBuffer()[m_InlineImageState ++] = ch; } else { if (ch == 'I') { EndInlineImage(); } } break; } } }
void ProcessNextChar(char c) { if (c == '\n') { state = jsBegin; // abandon current parse (if any) and start again return; } switch (state) { case jsBegin: // initial state, expecting '{' if (c == '{') { parser_watcher::StartReceivedMessage(); state = jsExpectId; fieldVal.clear(); fieldId.clear(); arrayDepth = 0; } break; case jsExpectId: // expecting a quoted ID switch (c) { case ' ': // ignore space break; case '"': state = jsId; break; case '}': // empty object, or extra comma at end of field list RemoveLastId(); if (fieldId.size() == 0) { // TODO: should we report this to the monitor as an error? parser_watcher::EndReceivedMessage(); state = jsBegin; } else { RemoveLastIdChar(); state = jsEndVal; } break; default: state = JsError(); break; } break; case jsId: // expecting an identifier, or in the middle of one switch (c) { case '"': state = jsHadId; break; default: if (c < ' ') { state = JsError(); } else if (c != ':' && c != '^') { if (!fieldId.add(c)) { state = JsError(); } } break; } break; case jsHadId: // had a quoted identifier, expecting ':' switch (c) { case ':': state = jsVal; break; case ' ': break; default: state = JsError(); break; } break; case jsVal: // had ':' or ':[', expecting value switch (c) { case ' ': break; case '"': fieldVal.clear(); state = jsStringVal; break; case '[': if (arrayDepth < MAX_ARRAY_NESTING && fieldId.add('^')) { arrayIndices[arrayDepth] = 0; // start an array ++arrayDepth; } else { state = JsError(); } break; case ']': if (InArray()) { EndArray(); // empty array state = jsEndVal; } else { state = JsError(); // ']' received without a matching '[' first } break; case '-': fieldVal.clear(); // TODO: an report error to the watcher state = (fieldVal.add(c)) ? jsNegIntVal : JsError(); break; case '{': // start of a nested object // TODO: report an error to the watcher state = (fieldId.add(':')) ? jsExpectId : JsError(); break; default: if (c >= '0' && c <= '9') { fieldVal.clear(); fieldVal.add(c); // must succeed because we just cleared fieldVal state = jsIntVal; break; } else { state = JsError(); } } break; case jsStringVal: // just had '"' and expecting a string value switch (c) { case '"': ConvertUnicode(); ProcessField(); state = jsEndVal; break; case '\\': state = jsStringEscape; break; default: if (c < ' ') { state = JsError(); } else { fieldVal.add(c); // ignore any error so that long string parameters // just get truncated } break; } break; case jsStringEscape: // just had backslash in a string if (!fieldVal.full()) { switch (c) { case '"': case '\\': case '/': if (!fieldVal.add(c)) { state = JsError(); } break; case 'n': case 't': if (!fieldVal.add(' ')) // replace newline and tab by space { // parser_watcher::ProcessError(); state = JsError(); } break; case 'b': case 'f': case 'r': default: break; } } state = jsStringVal; break; case jsNegIntVal: // had '-' so expecting a integer value // TODO: report an error to the watcher state = (c >= '0' && c <= '9' && fieldVal.add(c)) ? jsIntVal : JsError(); break; case jsIntVal: // receiving an integer value switch (c) { case '.': state = (fieldVal.add(c)) ? jsFracVal : JsError(); break; case ',': ProcessField(); if (InArray()) { ++arrayIndices[arrayDepth - 1]; fieldVal.clear(); state = jsVal; } else { RemoveLastId(); state = jsExpectId; } break; case ']': if (InArray()) { ProcessField(); ++arrayIndices[arrayDepth - 1]; EndArray(); state = jsEndVal; } else { state = JsError(); } break; case '}': if (InArray()) { state = JsError(); } else { ProcessField(); RemoveLastId(); if (fieldId.size() == 0) { parser_watcher::EndReceivedMessage(); state = jsBegin; } else { RemoveLastIdChar(); state = jsEndVal; } } break; default: if (!(c >= '0' && c <= '9' && fieldVal.add(c))) { state = JsError(); } break; } break; case jsFracVal: // receiving a fractional value switch (c) { case ',': ProcessField(); if (InArray()) { ++arrayIndices[arrayDepth - 1]; state = jsVal; } else { RemoveLastId(); state = jsExpectId; } break; case ']': if (InArray()) { ProcessField(); ++arrayIndices[arrayDepth - 1]; EndArray(); state = jsEndVal; } else { state = JsError(); } break; case '}': if (InArray()) { state = JsError(); } else { ProcessField(); RemoveLastId(); if (fieldId.size() == 0) { parser_watcher::EndReceivedMessage(); state = jsBegin; } else { RemoveLastIdChar(); state = jsEndVal; } } break; default: if (!(c >= '0' && c <= '9' && fieldVal.add(c))) { state = JsError(); } break; } break; case jsEndVal: // had the end of a string or array value, expecting comma // or ] or } switch (c) { case ',': if (InArray()) { ++arrayIndices[arrayDepth - 1]; fieldVal.clear(); state = jsVal; } else { RemoveLastId(); state = jsExpectId; } break; case ']': if (InArray()) { ++arrayIndices[arrayDepth - 1]; EndArray(); } else { state = JsError(); } break; case '}': if (InArray()) { state = JsError(); } else { RemoveLastId(); if (fieldId.size() == 0) { parser_watcher::EndReceivedMessage(); state = jsBegin; } else { RemoveLastIdChar(); // state = jsEndVal; // not needed, state == jsEndVal already } } break; default: break; } break; case jsError: // Ignore all characters. State will be reset to jsBegin at the start of // this function when we receive a newline. break; } }