#include "htf_common.hpp" extern "C" { #include "utils/builtins.h" #include "utils/elog.h" } namespace htf{ unsigned int symbol_digit(char *txtptr){ if(txtptr){ int encoding = GetDatabaseEncoding(); int char_len = pg_encoding_mblen(encoding, txtptr); if(char_len == 1) return (unsigned char)txtptr[0]; else{ pg_wchar wc_buf[2]; int conv = pg_mb2wchar_with_len(txtptr, wc_buf, char_len); if (conv > 0){ return (unsigned int)wc_buf[0]; } } } return 0; } char * escape_to_numeric_entity(text *input, bool full) { const char *data = VARDATA_ANY(input); int len = VARSIZE_ANY_EXHDR(input); StringInfoData result; /* Инициализация буфера для результата */ initStringInfo(&result); if (len == 0) return result.data; int encoding = GetDatabaseEncoding(); int byte_pos = 0; while (byte_pos < len) { int char_len = pg_encoding_mblen(encoding, data + byte_pos); if (char_len <= 0 || byte_pos + char_len > len) break; if (char_len == 1) { unsigned char c = data[byte_pos]; if(full) { if(c == '"'){ appendStringInfo(&result, """); byte_pos += char_len; continue; } if(c == '<'){ appendStringInfo(&result, "<"); byte_pos += char_len; continue; } if(c == '>'){ appendStringInfo(&result, ">"); byte_pos += char_len; continue; } if(c == '&'){ appendStringInfo(&result, "&"); byte_pos += char_len; continue; } if(c<='~'){ appendStringInfoChar(&result, c); byte_pos += char_len; continue; } } if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c == '-' || c == '.' || c == ',') { appendStringInfoChar(&result, c); byte_pos += char_len; continue; } } /* Для однобайтовых небезопасных и многобайтовых — декодируем */ pg_wchar wc_buf[2]; int conv = pg_mb2wchar_with_len(data + byte_pos, wc_buf, char_len); if (conv > 0){ int digits = 1; unsigned int temp = wc_buf[0]; while (temp > 15) { temp >>= 4; digits++; } // Если цифр нечётное - увеличиваем на 1 (добавим один ведущий ноль) if (digits % 2 != 0) { digits++; } appendStringInfo(&result, "&#x%0*X;", digits, (unsigned int) wc_buf[0]); } else appendStringInfoChar(&result, '?'); byte_pos += char_len; } return result.data; } char * escape_to_ltgt(text *input) { const char *data = VARDATA_ANY(input); int len = VARSIZE_ANY_EXHDR(input); StringInfoData result; /* Инициализация буфера для результата */ initStringInfo(&result); if (len == 0) return result.data; int encoding = GetDatabaseEncoding(); int byte_pos = 0; while (byte_pos < len) { int char_len = pg_encoding_mblen(encoding, data + byte_pos); if (char_len <= 0 || byte_pos + char_len > len) break; if (char_len == 1) { unsigned char c = data[byte_pos]; if(c == '<'){ appendStringInfo(&result, "<"); byte_pos += char_len; continue; } if(c == '>'){ appendStringInfo(&result, ">"); byte_pos += char_len; continue; } // просто добавление любого однобайтового символа appendStringInfoChar(&result, c); byte_pos += char_len; continue; } const char *sym = data + byte_pos; for(int i = 0; i"); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_address_tag(const char *cvalue, const char *cnowrap, const char *cclear, const char *cattr) { StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", cvalue ? cvalue : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_body_tag(const char *cbackground, const char *cattr) { StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_formselect_tag(const char *cname, const char *cprompt, const char *csize, const char *cattributes){ StringInfo result = makeStringInfo(); if(cprompt){ appendStringInfo(result, "%s", cprompt); } appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_map_tag(const char *cname, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_formtext_tag(const char *cname, const char *csize, const char *cmaxlength, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_textarea_tag(const char *cname, const char *crows, const char *ccols, const char * calign, const char *cattributes, const char *cwrap){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_formtextarea_tag(const char *cname, const char *crows, const char *ccolumns, const char *calign, const char *cattributes, const char *cwrap){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_anchor_tag(const char *curl, const char *ctext, const char *cname, const char *cattributes, const char *ctarget){ StringInfo result = makeStringInfo(); if(curl == NULL || cname == NULL){ appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_area_tag(const char *ccoord, const char *cshape, const char *chref, const char *cnohref, const char *ctarget, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_basefont_tag(const char *csize, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_bgsound_tag(const char *csrc, const char *cloop, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text* generate_big_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_blockquote_tag(bool cnowrap, const char *cclear, const char * cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_bold_tag(const char *ctext, const char *cattr){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_br_tag(const char *cclear, const char * cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_center_tag(const char *ctext){ StringInfo result = makeStringInfo(); appendStringInfo(result, "
"); appendStringInfo(result, "%s
", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_cite_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_code_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_comment_tag(const char *ctext){ StringInfo result = makeStringInfo(); appendStringInfo(result, "", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_dfn_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_div_tag(const char *calign, const char * cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_dlistdef_tag(const char *ctext, const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_dlistopen_tag(const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_dlistterm_tag(const char *ctext, const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_em_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_font_tag(const char *ccolor, const char *cface, const char *csize, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_tabledata_tag(const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); if (cvalue) { appendStringInfo(result, "%s", cvalue); } appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formcheckbox_tag(const char *cname, const char *cvalue, const char *cchecked, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formfile_tag(const char *cname, const char *caccept, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formhidden_tag(const char *cname, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formimage_tag(const char *cname, const char *cvalue, const char *calign, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formopen_tag(const char *curl, const char *cmethod, const char *ctarget, const char *cenctype, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formpassword_tag(const char *cname, const char *csize, const char *cmaxlength, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formradio_tag(const char *cname, const char *cvalue, const char *cchecked, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formreset_tag(const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formselectoption_tag(const char *cvalue, const char *cselected, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", cvalue ? cvalue : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_formsubmit_tag(const char *cname, const char *cvalue, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_frame_tag(const char *csrc, const char *cname, const char *cmarginwidth, const char *cmarginheight, const char *cscrolling, const char *cnoresize, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_frameset_tag(const char *crows, const char *ccols, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_header_tag(const char *clevel, const char *cheader, const char *calign, const char *cnowrap, const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", cheader ? cheader : "", clevel ? clevel : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_hr_tag(const char *cclear, const char *csrc, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_htitle_tag(const char *ctitle, const char *csize, const char *calign, const char *cnowrap, const char *cclear, const char *cattributes){ StringInfo result = makeStringInfo(); // Генерируем тег appendStringInfo(result, "<title>%s", ctitle ? ctitle : ""); // Генерируем тег appendStringInfo(result, "%s", ctitle ? ctitle : "", csize ? csize : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_img_tag(const char *csrc, const char *calign, const char *calt, const char *cismap, const char *cattributes, const char *cusemap){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_isindex_tag(const char *cprompt, const char *chref){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_italic_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_kbd_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_linkrel_tag(const char *crel, const char *curl, const char *ctitle, bool rel_is_rev){ StringInfo result = makeStringInfo(); appendStringInfo(result, ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_listheader_tag(const char *ctext, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } text *generate_listitem_tag(const char *ctext, const char *cclear, const char *cdingbat, const char *csrc, const char *cattributes){ StringInfo result = makeStringInfo(); appendStringInfo(result, "%s", ctext ? ctext : ""); text *ret = cstring_to_text(result->data); destroyStringInfo(result); return ret; } } // namespace htf extern "C" { } // extern "C"