connwrap - initialize gnutls session in cw_connect
[centerim.git] / kkstrtext / kkstrtext.h
blob80ab60501e3d34ffe6542b7e019498b8b83f24c6
1 #ifndef __KONST_STRING_H_
2 #define __KONST_STRING_H_
4 #include <string>
5 #include <vector>
6 #include <fstream>
8 #include <sys/time.h>
9 #include <time.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdarg.h>
14 #include <ctype.h>
16 #include "conf.h"
18 #ifdef HAVE_ICONV
19 #include <iconv.h>
20 #endif
23 // Gives out a number with the both limits _included_
26 #define randlimit(l, h) ((int)((float)rand()/(float)RAND_MAX*(float)(h+1-l)+(float)l))
28 #define SWAPVAL(v1, v2) { \
29 int SWAPVAL__v = v2; \
30 v2 = v1, v1 = SWAPVAL__v; \
33 #define PRINTNULL(p) (p ? p : "")
34 #define TAB_SIZE 8
36 struct quotedblock {
37 int begin, end;
40 void charpointerfree(void *p);
41 void nothingfree(void *p);
42 int stringcompare(void *s1, void *s2);
43 int intcompare(void *s1, void *s2);
45 string leadcut(const string &base, const string &delim = "\t\n\r ");
46 string trailcut(const string &base, const string &delim = "\t\n\r ");
48 string getword(string &base, const string &delim = "\t\n\r ");
49 string getrword(string &base, const string &delim = "\t\n\r ");
51 string getwordquote(string &base, const string &quote = "\"", const string &delim = "\t\n\r ");
52 string getrwordquote(string &base, const string &quote = "\"", const string &delim = "\t\n\r ");
54 int rtabmargin(bool fake, int curpos, const char *p = 0);
55 int ltabmargin(bool fake, int curpos, const char *p = 0);
57 void breakintolines(string text, vector<string> &lst, int linelen);
58 void breakintolines(const string &text, vector<string> &lst);
60 void find_gather_quoted(vector<quotedblock> &lst, const string &str,
61 const string &quote, const string &escape);
63 int find_quoted(const string &str, const string &needle, int offs = 0,
64 const string &quote = "\"'", const string &escape = "\\");
66 int find_quoted_first_of(const string &str, const string &needle,
67 int offs = 0, const string &quote = "\"'",
68 const string &escape = "\\");
70 void splitlongtext(string text, vector<string> &lst,
71 int size = 440, const string cont = "\n[continued]");
73 string strdateandtime(time_t stamp, const string &fmt = "");
74 string strdateandtime(struct tm *tms, const string &fmt = "");
76 bool iswholeword(const string &s, int so, int eo);
78 int hex2int(const string &ahex);
80 vector<int> getquotelayout(const string &haystack, const string &qs,
81 const string &aescs);
83 vector<int> getsymbolpositions(const string &haystack,
84 const string &needles, const string &qoutes, const string &esc);
86 #define VGETSTRING(c, fmt) \
87 { \
88 va_list vgs__ap; char vgs__buf[1024]; \
89 va_start(vgs__ap, fmt); \
90 vsnprintf(vgs__buf, 1024, fmt, vgs__ap); c = vgs__buf; \
91 va_end(vgs__ap); \
94 string justfname(const string &fname);
95 string justpathname(const string &fname);
96 string textscreen(const string &text);
97 string i2str(int i);
98 string ui2str(int i);
100 bool getconf(string &st, string &buf, ifstream &f, bool passemptylines = false);
101 bool getstring(istream &f, string &buf);
103 string unmime(const string &text);
104 string mime(const string &text);
106 string toutf8(const string &text);
107 string fromutf8(const string &text);
109 string ruscase(const string &s, const string &mode);
110 string siconv(const string &text, const string &fromcs, const string &tocs);
112 const int chCutBR = 1;
113 const int chLeaveLinks = 2;
115 string cuthtml(const string &html, int flags = 0);
116 string striprtf(const string &s, const string &charset);
118 __KTOOL_BEGIN_C
120 char *strcut(char *strin, int frompos, int count);
122 char *trimlead(char *str, char *chr);
123 char *trimtrail(char *str, char *chr);
124 char *trim(char *str, char *chr);
126 char *strimlead(char *str);
127 char *strimtrail(char *str);
128 char *strim(char *str);
130 const char *strqpbrk(
131 const char *s, int offset,
132 const char *accept,
133 const char *q,
134 const char *esc = "");
136 const char *strqcasestr(
137 const char *s,
138 const char *str,
139 const char *q,
140 const char *esc = "");
142 const char *strqstr(const char *s,
143 const char *str,
144 const char *q,
145 const char *esc = "");
147 char *strccat(char *dest, char c);
148 char *strinsert(char *buf, int pos, char *ins);
149 char *strcinsert(char *buf, int pos, char ins);
151 int strchcount(char *s, char *accept);
152 int stralone(char *buf, char *startword, int wordlen, char *delim);
154 char *time2str(const time_t *t, char *mask, char *sout);
155 time_t str2time(char *sdate, char *mask, time_t *t);
157 char *unmime(char *text);
158 char *mime(char *dst, const char *src);
160 char *utf8_to_str(const char *pin);
161 char *str_to_utf8(const char *pin);
163 __KTOOL_END_C
165 #endif