ext/iodine/mustache_parser.h
/* pushes text and padding instruction to the instruction array */
pushes text and padding instruction to the instruction array
pushes text and padding instruction to the instruction array
static inline int mustache__push_text_instruction(mustache__loader_stack_s *s,
                                                  uint32_t pos, uint32_t len) {
  for (;;) {
    char *start = s->data + pos;
    char *end = memchr(s->data + pos, '\n', len);
    if (!end)
      break;
    const size_t offset = (end - start) + 1;
    if (mustache__instruction_push(
            s,
            (mustache__instruction_s){
                .instruction = MUSTACHE_WRITE_TEXT,
                .data = {.name_pos = pos, .name_len = offset},
            }) == -1 ||
        mustache__instruction_push(s, (mustache__instruction_s){
                                          .instruction = MUSTACHE_PADDING_WRITE,
                                      }) == -1)
      return -1;
    pos += offset;
    len -= offset;
  }
  if (!len)
    return 0;
  return mustache__instruction_push(
      s, (mustache__instruction_s){
             .instruction = MUSTACHE_WRITE_TEXT,
             .data = {.name_pos = pos, .name_len = len},
         });
}
static inline int mustache__push_text_instruction ( mustache__loader_stack_s * s , uint32_t pos , uint32_t len ) { for ( ; ; ) { char * start = s -> data + pos ; char * end = memchr ( s -> data + pos , ' \n ' , len ) ; if ( ! end ) break ; const size_t offset = ( end - start ) + 1 ; if ( mustache__instruction_push ( s , ( mustache__instruction_s ) { . instruction = MUSTACHE_WRITE_TEXT , . data = { . name_pos = pos , . name_len = offset } , } ) == -1 || mustache__instruction_push ( s , ( mustache__instruction_s ) { . instruction = MUSTACHE_PADDING_WRITE , } ) == -1 ) return -1 ; pos += offset ; len -= offset ; } if ( ! len ) return 0 ; return mustache__instruction_push ( s , ( mustache__instruction_s ) { . instruction = MUSTACHE_WRITE_TEXT , . data = { . name_pos = pos , . name_len = len } , } ) ; }
pushes text and padding instruction to the instruction array
pushes text and padding instruction to the instruction array
/* always push padding instructions, in case or recursion with padding */ // if (!s->padding) { //   /* no padding, push text, as is */ //   return mustache__instruction_push( //       s, (mustache__instruction_s){ //              .instruction = MUSTACHE_WRITE_TEXT, //              .data = {.name_pos = pos, .name_len = len}, //          }); // } /* insert padding instruction after each new line */ /* seek new line markers */ /* offset marks the line's length */ /* push text and padding instructions */ /* done? */ /* write any text that doesn't terminate in the EOL marker */