Ejemplo n.º 1
0
void compareMetaData(QByteArray data, const QString &expected, int otherFlags = 0)
{
    QString decoded;

    // needs to be in in one map, with the entry called "v"
    data = "\xa1\x61v" + data;

    {
        CborParser parser;
        CborValue first;
        CborError err = cbor_parser_init(reinterpret_cast<const quint8 *>(data.constData()), data.length(), 0, &parser, &first);
        QVERIFY2(!err, QByteArrayLiteral(": Got error \"") + cbor_error_string(err) + "\"");

        err = parseOne(&first, &decoded, CborConvertAddMetadata | otherFlags);
        QVERIFY2(!err, QByteArrayLiteral(": Got error \"") + cbor_error_string(err) +
                 "\"; decoded stream:\n" + decoded.toLatin1());

        // check that we consumed everything
        QCOMPARE((void*)first.ptr, (void*)data.constEnd());
    }

    QVERIFY(decoded.startsWith("{\"v\":"));
    QVERIFY(decoded.endsWith('}'));
//    qDebug() << "was" << decoded;

    // extract just the metadata
    static const char needle[] = "\"v$cbor\":{";
    int pos = decoded.indexOf(needle);
    QCOMPARE(pos == -1, expected.isEmpty());
    if (pos != -1) {
        decoded.chop(2);
        decoded = std::move(decoded).mid(pos + strlen(needle));
        QCOMPARE(decoded, expected);
    }
}
Ejemplo n.º 2
0
 Expected<COFFModuleDefinition> parse() {
   do {
     if (Error Err = parseOne())
       return std::move(Err);
   } while (Tok.K != Eof);
   return Info;
 }
Ejemplo n.º 3
0
static void parseCase(const char* const xmlFile)
{
    //
    //  Create our SAX handler object and install it on the parser, as the
    //  document and error handler.
    //
    if (!handler)
        handler = new XSerializerHandlers();

    BinOutputStream* myOut = new BinMemOutputStream(BufSize);
    Janitor<BinOutputStream> janOut(myOut);

    if (!parseOne(myOut, xmlFile))
        return;

    BinInputStream*  myIn  = new BinMemInputStream(
                                                   ((BinMemOutputStream*)myOut)->getRawBuffer()
                                                 , ((BinMemOutputStream*)myOut)->getSize()
                                                 , BinMemInputStream::BufOpt_Reference
                                                  );
    Janitor<BinInputStream> janIn(myIn);

    parseTwo(myIn, xmlFile);

}
Ejemplo n.º 4
0
	void parse(char* str, char* dltTag = TAG_DLT, char* endTag = TAG_END)
	{
		if (NULL == str)
		{
			return;
		}
		parseOne(m_pArr, &str, endTag, dltTag);
	}
Ejemplo n.º 5
0
bool Parser::parse(std::vector<Directive *> &ret) {
  for (;;) {
    Directive *dir = nullptr;
    if (!parseOne(dir))
      return false;
    if (!dir)
      return true;
    ret.push_back(dir);
  }
}
Ejemplo n.º 6
0
bool pscli::LexParser::parse(void){
    bool success=true;
    
    if(tokens_.size() > 0)
    	return true;

    for(auto input_element : input_){
        success &= parseOne(input_element);
    }
    
    return success;
}
Ejemplo n.º 7
0
void tst_ToJson::nonStringKeyMaps()
{
    QFETCH(QByteArray, data);
    QFETCH(QString, expected);

    data = "\xa1" + data + "\1";
    compareOne(data, "{\"" + expected + "\":1}", CborConvertStringifyMapKeys);

    // and verify that they fail if we use CborConvertRequireMapStringKeys
    CborParser parser;
    CborValue first;
    QString decoded;
    cbor_parser_init(reinterpret_cast<const quint8 *>(data.constData()), data.length(), 0, &parser, &first);
    CborError err = parseOne(&first, &decoded, CborConvertRequireMapStringKeys);
    QCOMPARE(err, CborErrorJsonObjectKeyNotString);
}
Ejemplo n.º 8
0
	void parseOne(_Node_t_* pHead, char** str, char* endTag, char* dltTag )
	{
		char* lineEnd = *str;
		_Node_t_* pTmp = NULL;
		_Node_t_* pArr = pHead;

		if (0 != strncmp(*str, TAG_STR, strlen(TAG_STR)) 
			&& 0 != strncmp(*str + strlen(*str) - strlen(endTag), endTag, strlen(endTag)))
		{
			return;
		}
		*str += strlen(TAG_STR);

		while ( NULL!= *str&& NULL != lineEnd &&  0 != strncmp(*str, endTag, strlen(endTag)) )
		{
			lineEnd = strstr(*str, dltTag);
			if (NULL == lineEnd)
			{
				lineEnd = strstr(*str, endTag);
			}
			if (NULL != lineEnd)
			{
				pTmp = new _Node_t_();
				if (0 != strncmp(*str, TAG_STR, strlen(TAG_STR)))
				{
					pTmp->type = TYPE_NUM;
					pTmp->nValue = str2int(*str, dltTag);

					*str = lineEnd + strlen(dltTag);
				}
				else
				{  
					pTmp->type = TYPE_ARR;
					pTmp->aValue = new _Node_t_();
					parseOne(pTmp->aValue, str, endTag ,dltTag);
				}

				pArr->next = pTmp;
				pArr = pTmp;

				if (0 == strncmp(lineEnd - strlen(endTag), endTag, strlen(endTag)))
				{
					return;
				}
			}
		}
	}
Ejemplo n.º 9
0
int main()
{
	cJSON *rootOne = cJSON_CreateObject();
	createOne(rootOne);
	char * jsonStr = cJSON_Print(rootOne);
	printf("jsonStr is %s\n",jsonStr);
	//free(jsonStr);
	parseOne(jsonStr);
	printf("+++++++++++++++++++++++++++++++\n");
	cJSON *rootTwo= cJSON_CreateObject();
	createTwo(rootTwo);
	jsonStr = cJSON_Print(rootTwo);
	printf("jsonStr is %s\n",jsonStr);
	parseTwo(jsonStr);

	return 0;
}
Ejemplo n.º 10
0
void compareOne_real(const QByteArray &data, const QString &expected, int flags, int line)
{
    compareFailed = true;
    CborParser parser;
    CborValue first;
    CborError err = cbor_parser_init(reinterpret_cast<const quint8 *>(data.constData()), data.length(), 0, &parser, &first);
    QVERIFY2(!err, QByteArray::number(line) + ": Got error \"" + cbor_error_string(err) + "\"");

    QString decoded;
    err = parseOne(&first, &decoded, flags);
    QVERIFY2(!err, QByteArray::number(line) + ": Got error \"" + cbor_error_string(err) +
                   "\"; decoded stream:\n" + decoded.toLatin1());
    QCOMPARE(decoded, expected);

    // check that we consumed everything
    QCOMPARE((void*)first.ptr, (void*)data.constEnd());

    compareFailed = false;
}