コード例 #1
0
ファイル: json_utils.c プロジェクト: ChunHungLiu/cdogs-sdl
void LoadStr(char **value, json_t *node, const char *name)
{
	if (!TryLoadValue(&node, name))
	{
		return;
	}
	*value = json_unescape(node->text);
}
コード例 #2
0
ファイル: ScriptDialog.cpp プロジェクト: tasosbull/yewtic
void ScriptDialog::setScript(const QString &filename)
{
	json_t *root = BatDownUtils::readJsonFromFile(filename);
	json_t *idNode = json_find_first_label(root, "id");
	json_t *titleNode = json_find_first_label(root, "title");
	json_t *urlNode = json_find_first_label(root, "url");
	json_t *stepsNode = json_find_first_label(root, "steps");
	json_t *seqNode = json_find_first_label(stepsNode->child, "seq");

	m_id = QString(idNode->child->text);
	m_title = QString::fromLocal8Bit(titleNode->child->text);
	m_url = QString::fromLocal8Bit(urlNode->child->text);

	json_t *item = item=seqNode->child->child;
	m_stepSeq.clear();
	while( item ){
		m_stepSeq.append(item->text);
		item = item->next;
	}

	item = seqNode->next;
	m_steps.clear();
	while( item ){
		json_t *testNode	= item->child->child;
		json_t *scriptNode	= testNode->next;
		char *t = json_unescape(testNode->child->text);
		char *c = json_unescape(scriptNode->child->text);
		m_steps.insert( item->text, QString::fromLocal8Bit(c) );
		m_stepTests.insert( item->text, QString::fromLocal8Bit(t) );
		m_stepFuncs.append( 
			QString::fromLocal8Bit("Yew.%1=function(){%2};")
			.arg(item->text)
			.arg( QString::fromLocal8Bit(item->child->text) )
		);
		item = item->next;
	}

	json_free_value(&root);

	m_pSeqEdit->setText(m_stepSeq.join(","));
	m_pStepsEdit->addItems(m_stepSeq);
	setWindowTitle(m_title);
}
コード例 #3
0
ファイル: json_utils.c プロジェクト: ChunHungLiu/cdogs-sdl
char *GetString(json_t *node, const char *name)
{
	return json_unescape(json_find_first_label(node, name)->child->text);
}
コード例 #4
0
ファイル: internal.c プロジェクト: btbxbob/lwqq
char *json_unescape_s(char* str)
{
	if(str==NULL) return NULL;
	return json_unescape(str);
}
コード例 #5
0
static void
test_json_unescape (void)
{
  char* strings[][2] =
    {
      { /* make sure the test works */
        "simple ascii-conformant string",
        "simple ascii-conformant string"
      },
      { /* make sure we decode »\"« properly */
        "\\\"quoted string\\\"",
        "\"quoted string\""
      },
      { /* »\\« */
        "C:\\\\Windows\\\\win.com",
        "C:\\Windows\\win.com"
      },
      { /* »\/« */
        "\\/bin\\/true",
        "/bin/true"
      },
      { /* »\b« - backspace U+0008 */
        "\\b",
        "\x8"
      },
      {/* »\f« - form feed U+000C */
        "\\f",
        "\xC"
      },
      { /* »\n« - newline U+0010 */
        "\\n",
        "\n"
      },
      { /* »\r« - carriage return U+000D */
        "\\r",
        "\r"
      },
      { /* »\t« - tab U+0009 */
        "\\t",
        "\t"
      },
      { /* »\uXXXX« - UTF-8 BMP character */
        "\\u0041pfelb\\u00E4ume\\u2026",
        "Apfelb\303\244ume\342\200\246"
        /* Apfelbäume… */
      },
      { /* »\uXXXX\uXXXX« - UTF-16 surrogates */
        "\\uD835\\uDE79\\uD835\\uDE82\\uD835\\uDE7E\\uD835\\uDE7D",
        "\360\235\231\271\360\235\232\202\360\235\231\276\360\235\231\275"
        /* 𝙹𝚂𝙾𝙽 (From Unicode's "Mathematical Monospace Capitals") */ }
    };
  size_t i;

  printf ("test_json_unescape(): ");

  for (i = 0; i < (sizeof(strings)/sizeof(strings[0])); i++)
    {
      char* test = json_unescape (strings[i][0]);

      assert (test);
      if (strcmp (test, strings[i][1]))
        {
          printf ("\nerror unescaping: got »%s« (expected »%s«)\n",
                  test, strings[i][1]);
          assert (!strcmp (test, strings[i][1]));
        }

      printf (".");
      free (test);
    }

  printf ("\n");
}