text stringlengths 0 357 |
|---|
sqlite3_bind_text(stmt, 2, strLikeInText, -1, SQLITE_STATIC); |
sqlite3_bind_text(stmt, 3, strLikeBeg, -1, SQLITE_STATIC); |
} |
while (sqlite3_step(stmt)==SQLITE_ROW) { |
dc_array_add_id(ret, sqlite3_column_int(stmt, 0)); |
} |
success = 1; |
cleanup: |
free(strLikeInText); |
free(strLikeBeg); |
free(real_query); |
sqlite3_finalize(stmt); |
//dc_log_info(context, 0, "Message list for search \"%s\" in chat #%i created in %.3f ms.", query, chat_id, (double)(clock()-start)*1000.0/CLOCKS_PER_SEC); |
if (success) { |
return ret; |
} |
else { |
if (ret) { |
dc_array_unref(ret); |
} |
return NULL; |
} |
} |
``` |
Filename: dc_dehtml.c |
```c |
#include <stdlib.h> |
#include <string.h> |
#include "dc_context.h" |
#include "dc_dehtml.h" |
#include "dc_saxparser.h" |
#include "dc_tools.h" |
#include "dc_strbuilder.h" |
typedef struct dehtml_t |
{ |
dc_strbuilder_t strbuilder; |
#define DO_NOT_ADD 0 |
#define DO_ADD_REMOVE_LINEENDS 1 |
#define DO_ADD_PRESERVE_LINEENDS 2 |
int add_text; |
char* last_href; |
} dehtml_t; |
static void dehtml_starttag_cb(void* userdata, const char* tag, char** attr) |
{ |
dehtml_t* dehtml = (dehtml_t*)userdata; |
if (strcmp(tag, "p")==0 || strcmp(tag, "div")==0 || strcmp(tag, "table")==0 || strcmp(tag, "td")==0) |
{ |
dc_strbuilder_cat(&dehtml->strbuilder, "\n\n"); |
dehtml->add_text = DO_ADD_REMOVE_LINEENDS; |
} |
else if (strcmp(tag, "br")==0) |
{ |
dc_strbuilder_cat(&dehtml->strbuilder, "\n"); |
dehtml->add_text = DO_ADD_REMOVE_LINEENDS; |
} |
else if (strcmp(tag, "style")==0 || strcmp(tag, "script")==0 || strcmp(tag, "title")==0) |
{ |
dehtml->add_text = DO_NOT_ADD; |
} |
else if (strcmp(tag, "pre")==0) |
{ |
dc_strbuilder_cat(&dehtml->strbuilder, "\n\n"); |
dehtml->add_text = DO_ADD_PRESERVE_LINEENDS; |
} |
else if (strcmp(tag, "a")==0) |
{ |
free(dehtml->last_href); |
dehtml->last_href = dc_strdup_keep_null(dc_attr_find(attr, "href")); |
if (dehtml->last_href) { |
dc_strbuilder_cat(&dehtml->strbuilder, "["); |
} |
} |
else if (strcmp(tag, "b")==0 || strcmp(tag, "strong")==0) |
{ |
dc_strbuilder_cat(&dehtml->strbuilder, "*"); |
} |
else if (strcmp(tag, "i")==0 || strcmp(tag, "em")==0) |
{ |
dc_strbuilder_cat(&dehtml->strbuilder, "_"); |
} |
} |
static void dehtml_text_cb(void* userdata, const char* text, int len) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.