MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / is_ref

Function is_ref

libraries/hoedown/src/document.c:2584–2695  ·  view source on GitHub ↗

is_ref • returns whether a line is a reference or not */

Source from the content-addressed store, hash-verified

2582
2583/* is_ref • returns whether a line is a reference or not */
2584static int
2585is_ref(const uint8_t *data, size_t beg, size_t end, size_t *last, struct link_ref **refs)
2586{
2587/* int n; */
2588 size_t i = 0;
2589 size_t id_offset, id_end;
2590 size_t link_offset, link_end;
2591 size_t title_offset, title_end;
2592 size_t line_end;
2593
2594 /* up to 3 optional leading spaces */
2595 if (beg + 3 >= end) return 0;
2596 if (data[beg] == ' ') { i = 1;
2597 if (data[beg + 1] == ' ') { i = 2;
2598 if (data[beg + 2] == ' ') { i = 3;
2599 if (data[beg + 3] == ' ') return 0; } } }
2600 i += beg;
2601
2602 /* id part: anything but a newline between brackets */
2603 if (data[i] != '[') return 0;
2604 i++;
2605 id_offset = i;
2606 while (i < end && data[i] != '\n' && data[i] != '\r' && data[i] != ']')
2607 i++;
2608 if (i >= end || data[i] != ']') return 0;
2609 id_end = i;
2610
2611 /* spacer: colon (space | tab)* newline? (space | tab)* */
2612 i++;
2613 if (i >= end || data[i] != ':') return 0;
2614 i++;
2615 while (i < end && data[i] == ' ') i++;
2616 if (i < end && (data[i] == '\n' || data[i] == '\r')) {
2617 i++;
2618 if (i < end && data[i] == '\r' && data[i - 1] == '\n') i++; }
2619 while (i < end && data[i] == ' ') i++;
2620 if (i >= end) return 0;
2621
2622 /* link: spacing-free sequence, optionally between angle brackets */
2623 if (data[i] == '<')
2624 i++;
2625
2626 link_offset = i;
2627
2628 while (i < end && data[i] != ' ' && data[i] != '\n' && data[i] != '\r')
2629 i++;
2630
2631 if (data[i - 1] == '>') link_end = i - 1;
2632 else link_end = i;
2633
2634 /* optional spacer: (space | tab)* (newline | '\'' | '"' | '(' ) */
2635 while (i < end && data[i] == ' ') i++;
2636 if (i < end && data[i] != '\n' && data[i] != '\r'
2637 && data[i] != '\'' && data[i] != '"' && data[i] != '(')
2638 return 0;
2639 line_end = 0;
2640 /* computing end-of-line */
2641 if (i >= end || data[i] == '\r' || data[i] == '\n') line_end = i;

Callers 1

hoedown_document_renderFunction · 0.85

Calls 3

add_link_refFunction · 0.85
hoedown_buffer_newFunction · 0.85
hoedown_buffer_putFunction · 0.85

Tested by

no test coverage detected