Exemplo n.º 1
0
grn_ts_bool
grn_ts_str_is_name(grn_ts_str str)
{
  if (!str.size) {
    return GRN_FALSE;
  }
  return grn_ts_str_is_name_prefix(str);
}
Exemplo n.º 2
0
/* grn_ts_writer_parse() parses output expressions. */
static grn_rc
grn_ts_writer_parse(grn_ctx *ctx, grn_ts_writer *writer,
                    grn_obj *table, grn_ts_str str)
{
  grn_rc rc;
  grn_ts_str rest = str;
  rc = grn_ts_expr_parser_open(ctx, table, &writer->parser);
  for ( ; ; ) {
    grn_ts_str first = { NULL, 0 };
    rc = grn_ts_expr_parser_split(ctx, writer->parser, rest, &first, &rest);
    if (rc != GRN_SUCCESS) {
      return (rc == GRN_END_OF_DATA) ? GRN_SUCCESS : rc;
    }
    if ((first.ptr[first.size - 1] == '*') &&
        grn_ts_str_is_name_prefix((grn_ts_str){ first.ptr, first.size - 1 })) {
      rc = grn_ts_writer_expand(ctx, writer, table, first);
      if (rc != GRN_SUCCESS) {
        return rc;
      }
    } else if (grn_ts_str_is_key_name(first) &&
               !grn_ts_table_has_key(ctx, table)) {
      /*
       * Skip _key if the table has no _key, because the default output_columns
       * option contains _key.
       */
      GRN_TS_DEBUG("skip \"_key\" because the table has no _key");
    } else {
      rc = grn_vector_add_element(ctx, &writer->name_buf,
                                  first.ptr, first.size, 0, GRN_DB_TEXT);
      if (rc != GRN_SUCCESS) {
        return rc;
      }
    }
  }
  return GRN_SUCCESS;
}