Ejemplo n.º 1
0
static void
_scan_kv_pairs_implicit(const gchar *input, VAElement args[])
{
  KVScanner *scanner = kv_scanner_new();
  _scan_kv_pairs_scanner(scanner, input, args);
  kv_scanner_free(scanner);
}
Ejemplo n.º 2
0
/* NOTE: this is a very limited clone operation that doesn't allow
 * descendant types (e.g.  linux-audit scanner to have their own state */
KVScanner *
kv_scanner_clone(KVScanner *self)
{
  KVScanner *cloned = kv_scanner_new();
  cloned->parse_value = self->parse_value;
  return cloned;
}
Ejemplo n.º 3
0
static void
_test_transforms_values_if_parse_value_is_set(void)
{
  KVScanner *scanner = kv_scanner_new();
  scanner->parse_value = _parse_value_by_incrementing_all_bytes;
  TEST_KV_SCANNER(scanner, "foo=\"bar\"", "foo", "cbs");
  kv_scanner_free(scanner);
}
Ejemplo n.º 4
0
static void
_test_value_separator_with_whitespaces_around(void)
{
  KVScanner *scanner = kv_scanner_new();
  kv_scanner_set_value_separator(scanner, ':');

  TEST_KV_SCANNER(scanner, "key1: value1 key2 : value2 key3 :value3 ",
                  "key1", "");

  kv_scanner_free(scanner);
}
Ejemplo n.º 5
0
static void
_test_separator_in_key(void)
{
  KVScanner *scanner = kv_scanner_new();
  kv_scanner_set_value_separator(scanner, '-');

  TEST_KV_SCANNER(scanner, "k-v", "k", "v");
  TEST_KV_SCANNER(scanner, "k--v", "k", "-v");
  TEST_KV_SCANNER(scanner, "---", "-", "-");

  kv_scanner_free(scanner);
}
Ejemplo n.º 6
0
static void
_test_value_separator_is_used_to_separate_key_from_value(void)
{
  KVScanner *scanner = kv_scanner_new();
  kv_scanner_set_value_separator(scanner, ':');

  TEST_KV_SCANNER(scanner, "key1:value1 key2:value2 key3:value3 ",
                  "key1", "value1",
                  "key2", "value2",
                  "key3", "value3");

  kv_scanner_free(scanner);
}
Ejemplo n.º 7
0
static void
_test_value_separator_clone(void)
{
  KVScanner *scanner = kv_scanner_new();
  kv_scanner_set_value_separator(scanner, ':');
  KVScanner *cloned_scanner = kv_scanner_clone(scanner);
  kv_scanner_free(scanner);

  TEST_KV_SCANNER(cloned_scanner, "key1:value1 key2:value2 key3:value3 ",
                  "key1", "value1",
                  "key2", "value2",
                  "key3", "value3");
  kv_scanner_free(cloned_scanner);
}
Ejemplo n.º 8
0
static void
_scan_kv_pairs_quoted(const gchar *input, KVQContainer args)
{
  KVScanner *scanner = kv_scanner_new();

  g_assert(input);
  kv_scanner_input(scanner, input);
  gboolean expect_more = TRUE;
  for (gsize i = 0; i < args.n; i++)
    {
      if (!_compare_key_value(scanner, args.arg[i].key, args.arg[i].value, &expect_more))
        break;
      expect_gboolean(scanner->value_was_quoted, args.arg[i].quoted,
                      "mismatch in value_was_quoted for [%s/%s]",
                      args.arg[i].key, args.arg[i].value);
    }
  if (expect_more)
    _assert_no_more_tokens(scanner);
  kv_scanner_free(scanner);
}