コード例 #1
0
static cmark_node *function_link_match(cmark_syntax_extension *self,
                                cmark_parser *parser,
                                cmark_node *parent,
                                cmark_inline_parser *inline_parser)
{
  cmark_node *ret = NULL;
  delimiter *tmp_delim;
  int offset;
  int start;

  offset = cmark_inline_parser_get_offset(inline_parser);

  if (offset == 0)
    goto done;

  if (cmark_inline_parser_peek_at(inline_parser, offset + 1) != ')')
    goto done;

  start = offset - 1;

  if (!is_valid_c(cmark_inline_parser_peek_at(inline_parser, start)))
    goto done;

  while (start >= 0) {
    unsigned char c = cmark_inline_parser_peek_at(inline_parser, start);

    if (is_valid_c(c)) {
      start -= 1;
    } else {
      break;
    }
  }

  ret = fixup_nodes(inline_parser, parent, offset - start - 1);

  if (!ret)
    goto done;

  tmp_delim = cmark_inline_parser_get_last_delimiter(inline_parser);

  while (tmp_delim) {
    delimiter *prev = tmp_delim->previous;

    if (tmp_delim->position < start + 1) {
      break;
    }

    cmark_inline_parser_remove_delimiter(inline_parser, tmp_delim);
    tmp_delim = prev;
  }

  cmark_inline_parser_advance_offset(inline_parser);
  cmark_inline_parser_advance_offset(inline_parser);

done:
  return ret;
}
コード例 #2
0
static int is_valid_c_or_dbus(ParsingContext *context, int c, int pos) {
    if (is_valid_c(c, pos, context))
        return 1;


    if (c == '.') {
        char nc = cmark_inline_parser_peek_at(context->parser, pos + 1);

        if (!nc || is_valid_c(nc, pos + 1, context))
            return 0;

        if (pos > 0) {
            nc = cmark_inline_parser_peek_at(context->parser, pos - 1);
            return is_valid_c(nc, pos + 1, context);
        }

        return 1;
    }

    return 0;
}
コード例 #3
0
static int is_valid_symbol_name(int c, int pos, ParsingContext *context) {
    if (is_valid_c(c, pos, context))
        return 1;

    if (c == ':' || c == '-' || c == '.') {
        char nc = cmark_inline_parser_peek_at(context->parser, pos + 1);

        if (c == ':')
            context->allow_dashes = 1;
        else if (c == '-' && !context->allow_dashes)
            return 0;

        return (nc && is_valid_symbol_name(nc, pos + 1, context));
    }
    return 0;
}
コード例 #4
0
static int is_valid_symbol_name(int c) {
  return is_valid_c(c) || c == ':';
}