2 # include "elementary_config.h"
4 #include <Elementary.h>
8 _str_ncpy(char *dest, const char *src, size_t count)
10 if ((!dest) || (!src)) return NULL;
11 return strncpy(dest, src, count);
15 _str_append(char *str, const char *txt, int *len, int *alloc)
17 int txt_len = strlen(txt);
19 if (txt_len <= 0) return str;
20 if ((*len + txt_len) >= *alloc)
25 alloc2 = *alloc + txt_len + 128;
26 str2 = realloc(str, alloc2);
27 if (!str2) return str;
31 strcpy(str + *len, txt);
37 _elm_util_mkup_to_text(const char *mkup)
40 int str_len = 0, str_alloc = 0;
42 char *tag_start, *tag_end, *esc_start, *esc_end, *ts;
44 if (!mkup) return NULL;
45 tag_start = tag_end = esc_start = esc_end = NULL;
51 (tag_end) || (esc_end) ||
52 (tag_start) || (esc_start))
58 ttag = malloc(tag_end - tag_start);
61 _str_ncpy(ttag, tag_start + 1, tag_end - tag_start - 1);
62 ttag[tag_end - tag_start - 1] = 0;
63 if (!strcmp(ttag, "br"))
64 str = _str_append(str, "\n", &str_len, &str_alloc);
65 else if (!strcmp(ttag, "\n"))
66 str = _str_append(str, "\n", &str_len, &str_alloc);
67 else if (!strcmp(ttag, "\\n"))
68 str = _str_append(str, "\n", &str_len, &str_alloc);
69 else if (!strcmp(ttag, "\t"))
70 str = _str_append(str, "\t", &str_len, &str_alloc);
71 else if (!strcmp(ttag, "\\t"))
72 str = _str_append(str, "\t", &str_len, &str_alloc);
73 else if (!strcmp(ttag, "ps")) /* Unicode paragraph separator */
74 str = _str_append(str, "\xE2\x80\xA9", &str_len, &str_alloc);
77 tag_start = tag_end = NULL;
81 ts = malloc(esc_end - esc_start + 1);
85 _str_ncpy(ts, esc_start, esc_end - esc_start);
86 ts[esc_end - esc_start] = 0;
87 esc = evas_textblock_escape_string_get(ts);
89 str = _str_append(str, esc, &str_len, &str_alloc);
92 esc_start = esc_end = NULL;
94 else if ((!*p) && (s))
96 ts = malloc(p - s + 1);
99 _str_ncpy(ts, s, p - s);
101 str = _str_append(str, ts, &str_len, &str_alloc);
110 if ((s) && (!esc_start))
114 ts = malloc(p - s + 1);
117 _str_ncpy(ts, s, p - s);
119 str = _str_append(str, ts, &str_len, &str_alloc);
135 if ((s) && (!tag_start))
139 ts = malloc(p - s + 1);
142 _str_ncpy(ts, s, p - s);
144 str = _str_append(str, ts, &str_len, &str_alloc);
164 _elm_util_text_to_mkup(const char *text)
167 int str_len = 0, str_alloc = 0;
168 int ch, pos = 0, pos2 = 0;
170 if (!text) return NULL;
174 pos2 = evas_string_char_next_get((char *)(text), pos2, &ch);
175 if ((ch <= 0) || (pos2 <= 0)) break;
177 str = _str_append(str, "<br>", &str_len, &str_alloc);
179 str = _str_append(str, "<\t>", &str_len, &str_alloc);
181 str = _str_append(str, "<", &str_len, &str_alloc);
183 str = _str_append(str, ">", &str_len, &str_alloc);
185 str = _str_append(str, "&", &str_len, &str_alloc);
186 else if (ch == 0x2029) /* PS */
187 str = _str_append(str, "<ps>", &str_len, &str_alloc);
192 _str_ncpy(tstr, text + pos, pos2 - pos);
193 tstr[pos2 - pos] = 0;
194 str = _str_append(str, tstr, &str_len, &str_alloc);