| 11047 | } |
| 11048 | |
| 11049 | cbm_adr_sections_t cbm_adr_parse_sections(const char *content) { |
| 11050 | cbm_adr_sections_t result; |
| 11051 | memset(&result, 0, sizeof(result)); |
| 11052 | if (!content || !content[0]) { |
| 11053 | return result; |
| 11054 | } |
| 11055 | |
| 11056 | const char *p = content; |
| 11057 | char *current_section = NULL; |
| 11058 | char current_content[ST_SQL_BUF] = ""; |
| 11059 | int content_len = 0; |
| 11060 | |
| 11061 | while (*p) { |
| 11062 | const char *eol = strchr(p, '\n'); |
| 11063 | int line_len = eol ? (int)(eol - p) : (int)strlen(p); |
| 11064 | |
| 11065 | char *new_section = adr_try_section_header(p, line_len); |
| 11066 | if (new_section) { |
| 11067 | adr_save_section(&result, current_section, current_content, content_len); |
| 11068 | current_section = new_section; |
| 11069 | current_content[0] = '\0'; |
| 11070 | content_len = 0; |
| 11071 | } else if (current_section && (content_len > 0 || line_len > 0)) { |
| 11072 | adr_append_line(current_content, (int)sizeof(current_content), &content_len, p, |
| 11073 | line_len); |
| 11074 | } |
| 11075 | |
| 11076 | p = eol ? eol + SKIP_ONE : p + line_len; |
| 11077 | } |
| 11078 | |
| 11079 | adr_save_section(&result, current_section, current_content, content_len); |
| 11080 | return result; |
| 11081 | } |
| 11082 | |
| 11083 | /* Append a section to the render buffer. |
| 11084 | * |
no test coverage detected