Try unicode decomposition when convertion fails

Registered by Yoichi

送信時に変換できなかった場合、Unicode compatibility decompositionで分解&合成を試行してから再変換を試みる。変換に成功した場合、送信。失敗した場合今まで通りエラーに。

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

Index: libloqui/loqui_codeconv.c
===================================================================
--- libloqui/loqui_codeconv.c (revision 1189)
+++ libloqui/loqui_codeconv.c (working copy)
@@ -354,7 +354,13 @@
 loqui_codeconv_to_server(LoquiCodeConv *codeconv, const gchar *input, GError **error)
 {
  LoquiCodeConvPrivate *priv;
- gchar *output;
+ GString *string;
+ const gchar *cur;
+ gsize bytes_read;
+ GError *tmp_err;
+ gunichar uc;
+ gchar *tmp;
+ gchar utf8_buf[10];

         g_return_val_if_fail(codeconv != NULL, NULL);
         g_return_val_if_fail(LOQUI_IS_CODECONV(codeconv), NULL);
@@ -366,14 +372,44 @@
  if (!priv->func && !LOQUI_CODECONV_G_ICONV_IS_VALID(codeconv->cd_to_server))
   return g_strdup(input);

- if (priv->func) {
- output = priv->func(codeconv, TRUE, input, error);
- } else {
- output = g_convert_with_iconv(input, strlen(input)+1, codeconv->cd_to_server,
- NULL, NULL, error);
+ if (priv->func)
+ return priv->func(codeconv, TRUE, input, error);
+
+ string = g_string_new(NULL);
+ cur = input;
+ while ((tmp = g_convert_with_iconv(cur, strlen(cur)+1, codeconv->cd_to_server, &bytes_read, NULL, &tmp_err)) == NULL) {
+ if (!tmp_err ||
+ tmp_err->domain != G_CONVERT_ERROR ||
+ tmp_err->code != G_CONVERT_ERROR_ILLEGAL_SEQUENCE) {
+ g_propagate_error(error, tmp_err);
+ return NULL;
+ }
+
+ if ((tmp = g_convert_with_iconv(cur, bytes_read, codeconv->cd_to_server, NULL, NULL, &tmp_err)) == NULL) {
+ g_propagate_error(error, tmp_err);
+ return NULL;
+ }
+ g_string_append(string, tmp);
+ g_free(tmp);
+
+ cur += bytes_read;
+ uc = g_utf8_get_char(cur);
+ g_unichar_to_utf8(uc, utf8_buf);
+ tmp = g_utf8_normalize(utf8_buf, -1, G_NORMALIZE_ALL_COMPOSE);
+
+ if ((tmp = g_convert_with_iconv(cur, bytes_read, codeconv->cd_to_server, NULL, NULL, &tmp_err)) == NULL) {
+ g_propagate_error(error, tmp_err);
+ return NULL;
+ }
+ g_string_append(string, tmp);
+ g_free(tmp);
+
+ cur = g_utf8_next_char(cur);
  }
+ g_string_append(string, tmp);
+ g_free(tmp);

- return output;
+ return g_string_free(string, FALSE);
 }

 static gchar *

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.