2 * Purple is the legal property of its developers, whose names are too numerous
3 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 /* This does two passes on the string. The first pass goes through
29 * and determine if all the structured text is properly balanced, and
30 * how many instances of each there is. The second pass goes and converts
31 * everything to HTML, depending on what's figured out by the first pass.
32 * It will short circuit once it knows it has no more replacements to make
34 char *jabber_google_format_to_html(const char *text
)
38 /* The start of the screen may be consdiered a space for this purpose */
39 gboolean preceding_space
= TRUE
;
41 gboolean in_bold
= FALSE
, in_italic
= FALSE
;
42 gboolean in_tag
= FALSE
;
44 gint bold_count
= 0, italic_count
= 0;
48 for (p
= text
; *p
!= '\0'; p
= g_utf8_next_char(p
)) {
49 gunichar c
= g_utf8_get_char(p
);
50 if (c
== '*' && !in_tag
) {
51 if (in_bold
&& (g_unichar_isspace(*(p
+1)) ||
56 } else if (preceding_space
&& !in_bold
&& !g_unichar_isspace(*(p
+1))) {
60 preceding_space
= TRUE
;
61 } else if (c
== '_' && !in_tag
) {
62 if (in_italic
&& (g_unichar_isspace(*(p
+1)) ||
67 } else if (preceding_space
&& !in_italic
&& !g_unichar_isspace(*(p
+1))) {
71 preceding_space
= TRUE
;
72 } else if (c
== '<' && !in_tag
) {
74 } else if (c
== '>' && in_tag
) {
77 if (g_unichar_isspace(c
))
78 preceding_space
= TRUE
;
80 preceding_space
= FALSE
;
84 str
= g_string_new(NULL
);
85 in_bold
= in_italic
= in_tag
= FALSE
;
86 preceding_space
= TRUE
;
88 for (p
= text
; *p
!= '\0'; p
= g_utf8_next_char(p
)) {
89 gunichar c
= g_utf8_get_char(p
);
91 if (bold_count
< 2 && italic_count
< 2 && !in_bold
&& !in_italic
) {
92 g_string_append(str
, p
);
93 return g_string_free(str
, FALSE
);
97 if (c
== '*' && !in_tag
) {
99 (g_unichar_isspace(*(p
+1))||*(p
+1)=='<')) { /* This is safe in UTF-8 */
100 str
= g_string_append(str
, "</b>");
103 } else if (preceding_space
&& bold_count
> 1 && !g_unichar_isspace(*(p
+1))) {
104 str
= g_string_append(str
, "<b>");
108 str
= g_string_append_unichar(str
, c
);
110 preceding_space
= TRUE
;
111 } else if (c
== '_' && !in_tag
) {
113 (g_unichar_isspace(*(p
+1))||*(p
+1)=='<')) {
114 str
= g_string_append(str
, "</i>");
117 } else if (preceding_space
&& italic_count
> 1 && !g_unichar_isspace(*(p
+1))) {
118 str
= g_string_append(str
, "<i>");
122 str
= g_string_append_unichar(str
, c
);
124 preceding_space
= TRUE
;
125 } else if (c
== '<' && !in_tag
) {
126 str
= g_string_append_unichar(str
, c
);
128 } else if (c
== '>' && in_tag
) {
129 str
= g_string_append_unichar(str
, c
);
131 } else if (!in_tag
) {
132 str
= g_string_append_unichar(str
, c
);
133 if (g_unichar_isspace(c
))
134 preceding_space
= TRUE
;
136 preceding_space
= FALSE
;
138 str
= g_string_append_unichar(str
, c
);
141 return g_string_free(str
, FALSE
);
146 void google_buddy_node_chat(PurpleBlistNode
*node
, gpointer data
)
149 PurpleConnection
*gc
;
153 gchar
*uuid
= purple_uuid_random();
155 g_return_if_fail(PURPLE_IS_BUDDY(node
));
157 buddy
= PURPLE_BUDDY(node
);
158 gc
= purple_account_get_connection(purple_buddy_get_account(buddy
));
159 g_return_if_fail(gc
!= NULL
);
160 js
= purple_connection_get_protocol_data(gc
);
162 room
= g_strdup_printf("private-chat-%s", uuid
);
163 chat
= jabber_join_chat(js
, room
, GOOGLE_GROUPCHAT_SERVER
, js
->user
->node
,
167 jabber_chat_invite(gc
, chat
->id
, "", purple_buddy_get_name(buddy
));