static gchar* convertUniCharToUTF8(const UChar* characters, gint length, int from, int to) { gint newLength = 0; GOwnPtr<gchar> utf8Text(utf16ToUtf8(characters, length, newLength)); if (!utf8Text) return 0; gchar* pos = utf8Text.get(); if (from > 0) { // discard the first 'from' characters // FIXME: we should do this before the conversion probably pos = g_utf8_offset_to_pointer(utf8Text.get(), from); } gint len = strlen(pos); GString* ret = g_string_new_len(NULL, len); // replace line break by space while (len > 0) { gint index, start; pango_find_paragraph_boundary(pos, len, &index, &start); g_string_append_len(ret, pos, index); if (index == start) break; g_string_append_c(ret, ' '); pos += start; len -= start; } return g_string_free(ret, FALSE); }
static gchar* convertUniCharToUTF8(const UChar* characters, gint length, int from, int to) { gchar* utf8 = 0; gint new_length = 0; utf16_to_utf8(characters, length, utf8, new_length); if (!utf8) return NULL; if (from > 0) { // discard the first 'from' characters // FIXME: we should do this before the conversion probably gchar* str_left = g_utf8_offset_to_pointer(utf8, from); gchar* tmp = g_strdup(str_left); g_free(utf8); utf8 = tmp; } gchar* pos = utf8; gint len = strlen(pos); GString* ret = g_string_new_len(NULL, len); // replace line break by space while (len > 0) { gint index, start; pango_find_paragraph_boundary(pos, len, &index, &start); g_string_append_len(ret, pos, index); if (index == start) break; g_string_append_c(ret, ' '); pos += start; len -= start; } return g_string_free(ret, FALSE); }
static VALUE rg_s_find_paragraph_boundary(G_GNUC_UNUSED VALUE self, VALUE text) { gint paragraph_delimiter_index, next_paragraph_start; StringValue(text); pango_find_paragraph_boundary(RSTRING_PTR(text), RSTRING_LEN(text), ¶graph_delimiter_index, &next_paragraph_start); return rb_ary_new3(2, INT2NUM(paragraph_delimiter_index), INT2NUM(next_paragraph_start)); }