| 7858 | } |
| 7859 | |
| 7860 | cbm_adr_sections_t cbm_adr_parse_sections(const char *content) { |
| 7861 | cbm_adr_sections_t result; |
| 7862 | memset(&result, 0, sizeof(result)); |
| 7863 | if (!content || !content[0]) { |
| 7864 | return result; |
| 7865 | } |
| 7866 | |
| 7867 | const char *p = content; |
| 7868 | char *current_section = NULL; |
| 7869 | char current_content[ST_SQL_BUF] = ""; |
| 7870 | int content_len = 0; |
| 7871 | |
| 7872 | while (*p) { |
| 7873 | const char *eol = strchr(p, '\n'); |
| 7874 | int line_len = eol ? (int)(eol - p) : (int)strlen(p); |
| 7875 | |
| 7876 | char *new_section = adr_try_section_header(p, line_len); |
| 7877 | if (new_section) { |
| 7878 | adr_save_section(&result, current_section, current_content, content_len); |
| 7879 | current_section = new_section; |
| 7880 | current_content[0] = '\0'; |
| 7881 | content_len = 0; |
| 7882 | } else if (current_section && (content_len > 0 || line_len > 0)) { |
| 7883 | adr_append_line(current_content, (int)sizeof(current_content), &content_len, p, |
| 7884 | line_len); |
| 7885 | } |
| 7886 | |
| 7887 | p = eol ? eol + SKIP_ONE : p + line_len; |
| 7888 | } |
| 7889 | |
| 7890 | adr_save_section(&result, current_section, current_content, content_len); |
| 7891 | return result; |
| 7892 | } |
| 7893 | |
| 7894 | /* Append a section to the render buffer. |
| 7895 | * |
no test coverage detected