X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Ftextprop.c;h=fc93e5826f26d1382df0b041f313a1e0c7e1ce6d;hb=8d9e63288b753b38ad5121a88e28cf7640a9ccb1;hp=e90f04a61e71e691dd5e96878e8423a13c3fc6a5;hpb=92102a8e77002a591a6e27708cc71d49258f6aec;p=m17n%2Fm17n-lib.git diff --git a/src/textprop.c b/src/textprop.c index e90f04a..fc93e58 100644 --- a/src/textprop.c +++ b/src/textprop.c @@ -512,7 +512,7 @@ adjust_intervals (MInterval *head, MInterval *tail, int diff) if (diff < 0) { - /* Adjust end poistions of properties starting before HEAD. */ + /* Adjust end positions of properties starting before HEAD. */ for (i = 0; i < head->nprops; i++) { prop = head->stack[i]; @@ -1021,20 +1021,19 @@ pop_all_properties (MTextPlist *plist, int from, int to) } -/* Delete volatile text properties between FROM and TO. If KEY is - Mnil, we are going to delete text, thus both strongly and weakly - volatile properties must be deleted. Otherwise we are going to - modify a text property KEY, thus only strongly volatile properties - whose key is not KEY must be deleted. */ +/* Delete volatile text properties between FROM and TO. If DELETING + is nonzero, we are going to delete text, thus both strongly and + weakly volatile properties must be deleted. Otherwise we are going + to modify a text property KEY, thus only strongly volatile + properties whose key is not KEY must be deleted. */ static void -prepare_to_modify (MText *mt, int from, int to, MSymbol key) +prepare_to_modify (MText *mt, int from, int to, MSymbol key, int deleting) { MTextPlist *plist = mt->plist, *prev = NULL; int mask_bits = MTEXTPROP_VOLATILE_STRONG; - int deleting = (key == Mnil) && (from < to); - if (key == Mnil) + if (deleting) mask_bits |= MTEXTPROP_VOLATILE_WEAK; while (plist) { @@ -1185,7 +1184,7 @@ dump_textplist (MTextPlist *plist, int indent) int mtext__prop_init () { - text_property_table.count = 0; + M17N_OBJECT_ADD_ARRAY (text_property_table, "Text property"); Mtext_prop_serializer = msymbol ("text-prop-serializer"); Mtext_prop_deserializer = msymbol ("text-prop-deserializer"); return 0; @@ -1203,7 +1202,6 @@ mtext__prop_fini () pool = next; } interval_pool_root.next = NULL; - mdebug__report_object ("Text property", &text_property_table); } @@ -1260,7 +1258,7 @@ mtext__adjust_plist_for_delete (MText *mt, int pos, int len) } to = pos + len; - prepare_to_modify (mt, pos, to, Mnil); + prepare_to_modify (mt, pos, to, Mnil, 1); for (plist = mt->plist; plist; plist = plist->next) { MInterval *interval = pop_all_properties (plist, pos, to); @@ -1300,7 +1298,7 @@ mtext__adjust_plist_for_insert (MText *mt, int pos, int nchars, return; } if (pos > 0 && pos < mtext_nchars (mt)) - prepare_to_modify (mt, pos, pos, Mnil); + prepare_to_modify (mt, pos, pos, Mnil, 0); for (pl_last = NULL, pl = mt->plist; pl; pl_last = pl, pl = pl->next) { @@ -1429,16 +1427,52 @@ mtext__adjust_plist_for_insert (MText *mt, int pos, int nchars, } } +/* len1 > 0 && len2 > 0 */ + void -mtext__adjust_plist_for_change (MText *mt, int from, int to) +mtext__adjust_plist_for_change (MText *mt, int pos, int len1, int len2) { - MTextPlist *plist; + int pos2 = pos + len1; - prepare_to_modify (mt, from, to, Mnil); - for (plist = mt->plist; plist; plist = plist->next) + prepare_to_modify (mt, pos, pos2, Mnil, 0); + + if (len1 < len2) { - pop_all_properties (plist, from, to); - xassert (check_plist (plist, 0) == 0); + int diff = len2 - len1; + MTextPlist *plist; + + for (plist = mt->plist; plist; plist = plist->next) + { + MInterval *head = find_interval (plist, pos2); + MInterval *tail = plist->tail; + MTextProperty *prop; + int i; + + if (head) + { + if (head->start == pos2) + head = head->prev; + while (tail != head) + { + for (i = 0; i < tail->nprops; i++) + { + prop = tail->stack[i]; + if (prop->start == tail->start) + prop->start += diff, prop->end += diff; + } + tail->start += diff; + tail->end += diff; + tail = tail->prev; + } + } + for (i = 0; i < tail->nprops; i++) + tail->stack[i]->end += diff; + tail->end += diff; + } + } + else if (len1 > len2) + { + mtext__adjust_plist_for_delete (mt, pos + len2, len1 - len2); } } @@ -1747,7 +1781,7 @@ mtext_put_prop (MText *mt, int from, int to, MSymbol key, void *val) M_CHECK_RANGE (mt, from, to, -1, 0); - prepare_to_modify (mt, from, to, key); + prepare_to_modify (mt, from, to, key, 0); plist = get_plist_create (mt, key, 1); interval = pop_all_properties (plist, from, to); prop = new_text_property (mt, from, to, key, val, 0); @@ -1808,7 +1842,7 @@ mtext_put_prop_values (MText *mt, int from, int to, M_CHECK_RANGE (mt, from, to, -1, 0); - prepare_to_modify (mt, from, to, key); + prepare_to_modify (mt, from, to, key, 0); plist = get_plist_create (mt, key, 1); interval = pop_all_properties (plist, from, to); if (num > 0) @@ -1906,7 +1940,7 @@ mtext_push_prop (MText *mt, int from, int to, M_CHECK_RANGE (mt, from, to, -1, 0); - prepare_to_modify (mt, from, to, key); + prepare_to_modify (mt, from, to, key, 0); plist = get_plist_create (mt, key, 1); /* Find an interval that covers the position FROM. */ @@ -2071,7 +2105,7 @@ mtext_pop_prop (MText *mt, int from, int to, MSymbol key) /* No property to pop. */ return 0; - prepare_to_modify (mt, from, to, key); + prepare_to_modify (mt, from, to, key, 0); /* If the found interval starts before FROM and has value(s), divide it at FROM. */ @@ -2515,7 +2549,7 @@ mtext_attach_property (MText *mt, int from, int to, MTextProperty *prop) M17N_OBJECT_REF (prop); if (prop->mt) mtext_detach_property (prop); - prepare_to_modify (mt, from, to, prop->key); + prepare_to_modify (mt, from, to, prop->key, 0); plist = get_plist_create (mt, prop->key, 1); xassert (check_plist (plist, 0) == 0); interval = pop_all_properties (plist, from, to); @@ -2559,7 +2593,7 @@ mtext_detach_property (MTextProperty *prop) if (! prop->mt) return 0; - prepare_to_modify (prop->mt, start, end, prop->key); + prepare_to_modify (prop->mt, start, end, prop->key, 0); plist = get_plist_create (prop->mt, prop->key, 0); xassert (plist); detach_property (plist, prop, NULL); @@ -2602,7 +2636,7 @@ mtext_push_property (MText *mt, int from, int to, MTextProperty *prop) M17N_OBJECT_REF (prop); if (prop->mt) mtext_detach_property (prop); - prepare_to_modify (mt, from, to, prop->key); + prepare_to_modify (mt, from, to, prop->key, 0); plist = get_plist_create (mt, prop->key, 1); prop->mt = mt; prop->start = from; @@ -2687,7 +2721,7 @@ mtext_push_property (MText *mt, int from, int to, MTextProperty *prop) pointer to an appropriate serializer function. @seealso - mtext_serialize (), MTextPropSerializeFunc + mtext_serialize (), #MTextPropSerializeFunc */ /***ja @@ -2699,7 +2733,7 @@ mtext_push_property (MText *mt, int from, int to, MTextProperty *prop) ¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£ @seealso - mtext_serialize (), MTextPropSerializeFunc + mtext_serialize (), #MTextPropSerializeFunc */ MSymbol Mtext_prop_serializer; @@ -2712,7 +2746,7 @@ MSymbol Mtext_prop_serializer; pointer to an appropriate deserializer function. @seealso - mtext_deserialize (), MTextPropSerializeFunc + mtext_deserialize (), #MTextPropSerializeFunc */ /***ja @@ -2724,7 +2758,7 @@ MSymbol Mtext_prop_serializer; ¥Ý¥¤¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£ @seealso - mtext_deserialize (), MTextPropSerializeFunc + mtext_deserialize (), #MTextPropSerializeFunc */ MSymbol Mtext_prop_deserializer; @@ -2766,7 +2800,7 @@ MSymbol Mtext_prop_deserializer; error code to the external variable #merror_code. @seealso - mtext_deserialize (), Mtext_prop_serializer */ + mtext_deserialize (), #Mtext_prop_serializer */ /***ja @brief M-text Ãæ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë. @@ -2806,7 +2840,7 @@ MSymbol Mtext_prop_deserializer; ¤òÀßÄꤹ¤ë¡£ @seealso - mtext_deserialize (), Mtext_prop_serializer */ + mtext_deserialize (), #Mtext_prop_serializer */ MText * mtext_serialize (MText *mt, int from, int to, MPlist *property_list) @@ -2821,6 +2855,11 @@ mtext_serialize (MText *mt, int from, int to, MPlist *property_list) int n; M_CHECK_RANGE (mt, from, to, NULL, NULL); + if (mt->format != MTEXT_FORMAT_US_ASCII + && mt->format != MTEXT_FORMAT_UTF_8) + mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8); + if (MTEXT_DATA (mt)[mtext_nbytes (mt)] != 0) + MTEXT_DATA (mt)[mtext_nbytes (mt)] = 0; doc = xmlParseMemory (XML_TEMPLATE, strlen (XML_TEMPLATE) + 1); node = xmlDocGetRootElement (doc); @@ -2848,7 +2887,7 @@ mtext_serialize (MText *mt, int from, int to, MPlist *property_list) if (! serialized_plist) continue; mtext_reset (work); - mplist__serialize (work, serialized_plist); + mplist__serialize (work, serialized_plist, 0); child = xmlNewChild (node, NULL, (xmlChar *) "property", NULL); xmlSetProp (child, (xmlChar *) "key", (xmlChar *) MSYMBOL_NAME (prop->key)); @@ -2895,7 +2934,7 @@ mtext_serialize (MText *mt, int from, int to, MPlist *property_list) @brief Deserialize text properties in an M-text. The mtext_deserialize () function deserializes M-text $MT. $MT - must be an XML having the followng DTD. + must be an XML having the following DTD. @verbatim