1 /* textprop.c -- text property module.
2 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 National Institute of Advanced Industrial Science and Technology (AIST)
4 Registration Number H15PRO112
6 This file is part of the m17n library.
8 The m17n library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public License
10 as published by the Free Software Foundation; either version 2.1 of
11 the License, or (at your option) any later version.
13 The m17n library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with the m17n library; if not, write to the Free
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 @addtogroup m17nTextProperty
25 @brief Function to handle text properties.
27 Each character in an M-text can have properties called @e text @e
28 properties. Text properties store various kinds of information
29 attached to parts of an M-text to provide application programs
30 with a unified view of those information. As rich information can
31 be stored in M-texts in the form of text properties, functions in
32 application programs can be simple.
34 A text property consists of a @e key and @e values, where key is a
35 symbol and values are anything that can be cast to <tt>(void *)
36 </tt>. Unlike other types of properties, a text property can
37 have multiple values. "The text property whose key is K" may be
38 shortened to "K property". */
41 @addtogroup m17nTextProperty
42 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÁàºî¤¹¤ë¤¿¤á¤Î´Ø¿ô.
44 M-text Æâ¤Î³Æʸ»ú¤Ï¡¢@e ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ ¤È¸Æ¤Ð¤ì¤ë¥×¥í¥Ñ¥Æ¥£¤ò
45 »ý¤Ä¤³¤È¤¬¤Ç¤¤ë¡£¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢M-text ¤Î³ÆÉô°Ì¤ËÉղ䵤ì
46 ¤¿¤µ¤Þ¤¶¤Þ¤Ê¾ðÊó¤òÊÝ»ý¤·¤Æ¤ª¤ê¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥à¤Ï¤½¤ì¤é
47 ¤Î¾ðÊó¤òÅý°ìŪ¤Ë°·¤¦¤³¤È¤¬¤Ç¤¤ë¡£M-text ¼«ÂΤ¬ËÉ٤ʾðÊó¤ò»ý¤Ä¤¿
48 ¤á¡¢¥¢¥×¥ê¥±¡¼¥·¥ç¥ó¥×¥í¥°¥é¥àÃæ¤Î´Ø¿ô¤ò´ÊÁDz½¤¹¤ë¤³¤È¤¬¤Ç¤¤ë¡£
50 ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï @e ¥¡¼ ¤È @e ÃÍ ¤«¤é¤Ê¤ë¡£¥¡¼¤Ï¥·¥ó¥Ü¥ë¤Ç¤¢
51 ¤ê¡¢ÃÍ¤Ï <tt>(void *)</tt> ·¿¤Ë¥¥ã¥¹¥È¤Ç¤¤ë¤â¤Î¤Ê¤é²¿¤Ç¤â¤è¤¤¡£
52 ¾¤Î¥¿¥¤¥×¤Î¥×¥í¥Ñ¥Æ¥£¤È°Û¤Ê¤ê¡¢°ì¤Ä¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Ê£¿ô¤ÎÃÍ
53 ¤ò»ý¤Ä¤³¤È¤¬µö¤µ¤ì¤ë¡£¡Ö¥¡¼¤¬ K ¤Ç¤¢¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¡×¤Î¤³¤È
54 ¤ò´Êñ¤Ë¡ÖK ¥×¥í¥Ñ¥Æ¥£¡×¤È¸Æ¤Ö¤³¤È¤¬¤¢¤ë¡£ */
58 #if !defined (FOR_DOXYGEN) || defined (DOXYGEN_INTERNAL_MODULE)
59 /*** @addtogroup m17nInternal
68 #include <libxml/tree.h>
69 #include <libxml/parser.h>
70 #include <libxml/xmlmemory.h>
71 #include <libxml/xpath.h>
75 #include "m17n-misc.h"
81 #define TEXT_PROP_DEBUG
84 #ifdef TEXT_PROP_DEBUG
85 #define xassert(X) do {if (!(X)) mdebug_hook ();} while (0)
87 #define xassert(X) (void) 0
88 #endif /* not FONTSET_DEBUG */
90 /* Hierarchy of objects (MText, MTextPlist, MInterval, MTextProperty)
94 +--> MTextPlist -> MTextPlist -> ... -> MTextPlist
96 | +- tail <-----------------------------------------+
98 | +- head <--> MInterval <--> ... <--> MInterval <--+
100 +- tail --------------------------------------------------------+
102 +- head --> MInterval <--> MInterval <--> ... <--> MInterval <--+
104 +---------------+------------> MTextProperty
111 MTextProperty a/A [AAAAAAAAAAAAAAAAAAAAA]
112 MTextProperty a/B [BBBBBBBBBBBBBBBBB]
113 MTextPlist a |--intvl1--|-intvl2-|-intvl3-|---intvl4---|-intvl5-|
116 MTextProperty b/A [AAAAAAAAAA]
117 MTextProperty b/B [BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB]
118 MTextPlist b |-intvl1-|--intvl2--|--intvl3--|-intvl4-|--intvl5--|
120 M-text |--------------------------------------------------|
126 /* The structure MTextProperty is defined in textprop.h. */
128 /** MInterval is the structure for an interval that holds text
129 properties of the same key in a specific range of M-text.
130 All intervals are stored in MIntervalPool. */
132 typedef struct MInterval MInterval;
136 /** Stack of pointers to text properties. If the interval does not
137 have any text properties, this member is NULL or contains random
139 MTextProperty **stack;
141 /** How many values are in <stack>. */
144 /** Length of <stack>. */
147 /** Start and end character positions of the interval. If <end> is
148 negative, this interval is not in use. */
151 /** Pointers to the previous and next intervals. If <start> is 0,
152 <prev> is NULL and this interval is pointed by MTextPlist->head.
153 If <end> is the size of the M-text, <next> is NULL, and this
154 interval is pointed by MTextPlist->tail. */
155 MInterval *prev, *next;
158 /** MTextPlist is a structure to hold text properties of an M-text by
159 chain. Each element in the chain is for a specific key. */
161 typedef struct MTextPlist MTextPlist;
165 /** Key of the property. */
168 /** The head and tail intervals. <head>->start is always 0.
169 <tail->end is always MText->nchars. */
170 MInterval *head, *tail;
172 /** Lastly accessed interval. */
175 /* Not yet implemented. */
176 int (*modification_hook) (MText *mt, MSymbol key, int from, int to);
178 /** Pointer to the next property in the chain, or NULL if the
179 property is the last one in the chain. */
184 /** How many intervals one interval-pool can contain. */
186 #define INTERVAL_POOL_SIZE 1024
188 typedef struct MIntervalPool MIntervalPool;
191 /** MIntervalPool is the structure for an interval-pool which store
192 intervals. Each interval-pool contains INTERVAL_POOL_SIZE number
193 of intervals, and is chained from the root #interval_pool. */
197 /** Array of intervals. */
198 MInterval intervals[INTERVAL_POOL_SIZE];
200 /** The smallest index to an unused interval. */
203 /** Pointer to the next interval-pool. */
208 /** Root of interval-pools. */
210 static MIntervalPool interval_pool_root;
214 static M17NObjectArray text_property_table;
216 /** Return a newly allocated interval pool. */
218 static MIntervalPool *
224 MSTRUCT_CALLOC (pool, MERROR_TEXTPROP);
225 for (i = 0; i < INTERVAL_POOL_SIZE; i++)
226 pool->intervals[i].end = -1;
233 /** Return a new interval for the region START and END. */
236 new_interval (int start, int end)
241 for (pool = &interval_pool_root;
242 pool->free_slot >= INTERVAL_POOL_SIZE;
246 pool->next = new_interval_pool ();
249 interval = &(pool->intervals[pool->free_slot]);
250 interval->stack = NULL;
251 interval->nprops = 0;
252 interval->stack_length = 0;
253 interval->prev = interval->next = NULL;
254 interval->start = start;
258 while (pool->free_slot < INTERVAL_POOL_SIZE
259 && pool->intervals[pool->free_slot].end >= 0)
266 /** Free INTERVAL and return INTERVAL->next. It assumes that INTERVAL
267 has no properties. */
270 free_interval (MInterval *interval)
272 MIntervalPool *pool = &interval_pool_root;
275 xassert (interval->nprops == 0);
277 free (interval->stack);
278 while ((interval < pool->intervals
279 || interval >= pool->intervals + INTERVAL_POOL_SIZE)
283 i = interval - pool->intervals;
285 if (i < pool->free_slot)
287 return interval->next;
291 /** If necessary, allocate a stack for INTERVAL so that it can contain
292 NUM number of text properties. */
294 #define PREPARE_INTERVAL_STACK(interval, num) \
296 if ((num) > (interval)->stack_length) \
298 MTABLE_REALLOC ((interval)->stack, (num), MERROR_TEXTPROP); \
299 (interval)->stack_length = (num); \
304 /** Return a copy of INTERVAL. The copy still shares text properties
305 with INTERVAL. If MASK_BITS is not zero, don't copy such text
306 properties whose control flags contains bits in MASK_BITS. */
309 copy_interval (MInterval *interval, int mask_bits)
311 MInterval *new = new_interval (interval->start, interval->end);
312 int nprops = interval->nprops;
313 MTextProperty **props = alloca (sizeof (MTextProperty *) * nprops);
316 for (i = n = 0; i < nprops; i++)
317 if (! (interval->stack[i]->control.flag & mask_bits))
318 props[n++] = interval->stack[i];
322 PREPARE_INTERVAL_STACK (new, n);
323 memcpy (new->stack, props, sizeof (MTextProperty *) * n);
330 /** Free text property OBJECT. */
333 free_text_property (void *object)
335 MTextProperty *prop = (MTextProperty *) object;
337 if (prop->key->managing_key)
338 M17N_OBJECT_UNREF (prop->val);
339 M17N_OBJECT_UNREGISTER (text_property_table, prop);
344 /** Return a newly allocated text property whose key is KEY and value
347 static MTextProperty *
348 new_text_property (MText *mt, int from, int to, MSymbol key, void *val,
353 M17N_OBJECT (prop, free_text_property, MERROR_TEXTPROP);
354 prop->control.flag = control_bits;
355 prop->attach_count = 0;
361 if (key->managing_key)
362 M17N_OBJECT_REF (val);
363 M17N_OBJECT_REGISTER (text_property_table, prop);
368 /** Return a newly allocated copy of text property PROP. */
370 #define COPY_TEXT_PROPERTY(prop) \
371 new_text_property ((prop)->mt, (prop)->start, (prop)->end, \
372 (prop)->key, (prop)->val, (prop)->control.flag)
375 /** Split text property PROP at position INTERVAL->start, and make all
376 the following intervals contain the copy of PROP instead of PROP.
377 It assumes that PROP starts before INTERVAL. */
380 split_property (MTextProperty *prop, MInterval *interval)
386 prop->end = interval->start;
387 copy = COPY_TEXT_PROPERTY (prop);
388 copy->start = interval->start;
390 /* Check all stacks of the following intervals, and if it contains
391 PROP, change it to the copy of it. */
392 for (; interval && interval->start < end; interval = interval->next)
393 for (i = 0; i < interval->nprops; i++)
394 if (interval->stack[i] == prop)
396 interval->stack[i] = copy;
397 M17N_OBJECT_REF (copy);
398 copy->attach_count++;
399 prop->attach_count--;
400 M17N_OBJECT_UNREF (prop);
402 M17N_OBJECT_UNREF (copy);
405 /** Divide INTERVAL of PLIST at POS if POS is in between the range of
409 divide_interval (MTextPlist *plist, MInterval *interval, int pos)
414 if (pos == interval->start || pos == interval->end)
416 new = copy_interval (interval, 0);
417 interval->end = new->start = pos;
418 new->prev = interval;
419 new->next = interval->next;
420 interval->next = new;
422 new->next->prev = new;
423 if (plist->tail == interval)
425 for (i = 0; i < new->nprops; i++)
427 new->stack[i]->attach_count++;
428 M17N_OBJECT_REF (new->stack[i]);
433 /** Check if INTERVAL of PLIST can be merged with INTERVAL->next. If
434 mergeable, extend INTERVAL to the end of INTEVAL->next, free
435 INTERVAL->next, and return INTERVAL. Otherwise, return
439 maybe_merge_interval (MTextPlist *plist, MInterval *interval)
441 int nprops = interval->nprops;
442 MInterval *next = interval->next;
445 if (! next || nprops != next->nprops)
448 for (i = 0; i < nprops; i++)
450 MTextProperty *prop = interval->stack[i];
451 MTextProperty *old = next->stack[i];
454 && (prop->val != old->val
455 || prop->end != old->start
456 || prop->control.flag & MTEXTPROP_NO_MERGE
457 || old->control.flag & MTEXTPROP_NO_MERGE))
458 return interval->next;
462 for (i = 0; i < nprops; i++)
464 MTextProperty *prop = interval->stack[i];
465 MTextProperty *old = next->stack[i];
471 for (tail = next->next; tail && tail->start < old->end;
473 for (j = 0; j < tail->nprops; j++)
474 if (tail->stack[j] == old)
477 xassert (old->attach_count);
478 tail->stack[j] = prop;
479 prop->attach_count++;
480 M17N_OBJECT_REF (prop);
482 xassert (old->attach_count == 1);
484 prop->end = old->end;
487 M17N_OBJECT_UNREF (old);
490 interval->end = next->end;
491 interval->next = next->next;
493 next->next->prev = interval;
494 if (plist->tail == next)
495 plist->tail = interval;
496 plist->cache = interval;
498 free_interval (next);
503 /** Adjust start and end positions of intervals between HEAD and TAIL
504 (both inclusive) by diff. Adjust also start and end positions
505 of text properties belonging to those intervals. */
508 adjust_intervals (MInterval *head, MInterval *tail, int diff)
515 /* Adjust end positions of properties starting before HEAD. */
516 for (i = 0; i < head->nprops; i++)
518 prop = head->stack[i];
519 if (prop->start < head->start)
523 /* Adjust start and end positions of properties starting at
524 HEAD, and adjust HEAD itself. */
527 for (i = 0; i < head->nprops; i++)
529 prop = head->stack[i];
530 if (prop->start == head->start)
531 prop->start += diff, prop->end += diff;
542 /* Adjust start poistions of properties ending after TAIL. */
543 for (i = 0; i < tail->nprops; i++)
545 prop = tail->stack[i];
546 if (prop->end > tail->end)
550 /* Adjust start and end positions of properties ending at
551 TAIL, and adjust TAIL itself. */
554 for (i = 0; i < tail->nprops; i++)
556 prop = tail->stack[i];
557 if (prop->end == tail->end)
558 prop->start += diff, prop->end += diff;
569 /* Return an interval of PLIST that covers the position POS. */
572 find_interval (MTextPlist *plist, int pos)
577 if (pos < plist->head->end)
579 if (pos >= plist->tail->start)
580 return (pos < plist->tail->end ? plist->tail : NULL);
582 interval = plist->cache;
584 if (pos < interval->start)
585 highest = interval->prev, interval = plist->head->next;
586 else if (pos < interval->end)
589 highest = plist->tail->prev, interval = interval->next;
591 if (pos - interval->start < highest->end - pos)
593 while (interval->end <= pos)
594 /* Here, we are sure that POS is not included in PLIST->tail,
595 thus, INTERVAL->next always points a valid next
597 interval = interval->next;
601 while (highest->start > pos)
602 highest = highest->prev;
605 plist->cache = interval;
609 /* Push text property PROP on the stack of INTERVAL. */
611 #define PUSH_PROP(interval, prop) \
613 int n = (interval)->nprops; \
615 PREPARE_INTERVAL_STACK ((interval), n + 1); \
616 (interval)->stack[n] = (prop); \
617 (interval)->nprops += 1; \
618 (prop)->attach_count++; \
619 M17N_OBJECT_REF (prop); \
620 if ((prop)->start > (interval)->start) \
621 (prop)->start = (interval)->start; \
622 if ((prop)->end < (interval)->end) \
623 (prop)->end = (interval)->end; \
627 /* Pop the topmost text property of INTERVAL from the stack. If it
628 ends after INTERVAL->end, split it. */
630 #define POP_PROP(interval) \
632 MTextProperty *prop; \
634 (interval)->nprops--; \
635 prop = (interval)->stack[(interval)->nprops]; \
636 xassert (prop->control.ref_count > 0); \
637 xassert (prop->attach_count > 0); \
638 if (prop->start < (interval)->start) \
640 if (prop->end > (interval)->end) \
641 split_property (prop, (interval)->next); \
642 prop->end = (interval)->start; \
644 else if (prop->end > (interval)->end) \
645 prop->start = (interval)->end; \
646 prop->attach_count--; \
647 if (! prop->attach_count) \
649 M17N_OBJECT_UNREF (prop); \
653 #define REMOVE_PROP(interval, prop) \
657 for (i = (interval)->nprops - 1; i >= 0; i--) \
658 if ((interval)->stack[i] == (prop)) \
662 (interval)->nprops--; \
663 for (; i < (interval)->nprops; i++) \
664 (interval)->stack[i] = (interval)->stack[i + 1]; \
665 (prop)->attach_count--; \
666 if (! (prop)->attach_count) \
668 M17N_OBJECT_UNREF (prop); \
672 #ifdef TEXT_PROP_DEBUG
674 check_plist (MTextPlist *plist, int start)
676 MInterval *interval = plist->head;
677 MInterval *cache = plist->cache;
680 if (interval->start != start
681 || interval->start >= interval->end)
682 return mdebug_hook ();
687 if (interval == interval->next)
688 return mdebug_hook ();
690 if (interval == cache)
693 if (interval->start >= interval->end)
694 return mdebug_hook ();
696 ? (interval->end != interval->next->start
697 || interval != interval->next->prev)
698 : interval != plist->tail))
699 return mdebug_hook ();
700 for (i = 0; i < interval->nprops; i++)
702 if (interval->stack[i]->start > interval->start
703 || interval->stack[i]->end < interval->end)
704 return mdebug_hook ();
706 if (! interval->stack[i]->attach_count)
707 return mdebug_hook ();
708 if (! interval->stack[i]->mt)
709 return mdebug_hook ();
710 if (interval->stack[i]->start == interval->start)
712 MTextProperty *prop = interval->stack[i];
713 int count = prop->attach_count - 1;
714 MInterval *interval2;
716 for (interval2 = interval->next;
717 interval2 && interval2->start < prop->end;
718 count--, interval2 = interval2->next)
720 return mdebug_hook ();
723 if (interval->stack[i]->end > interval->end)
725 MTextProperty *prop = interval->stack[i];
726 MInterval *interval2;
729 for (interval2 = interval->next;
730 interval2 && interval2->start < prop->end;
731 interval2 = interval2->next)
733 for (j = 0; j < interval2->nprops; j++)
734 if (interval2->stack[j] == prop)
736 if (j == interval2->nprops)
737 return mdebug_hook ();
740 if (interval->stack[i]->start < interval->start)
742 MTextProperty *prop = interval->stack[i];
743 MInterval *interval2;
746 for (interval2 = interval->prev;
747 interval2 && interval2->end > prop->start;
748 interval2 = interval2->prev)
750 for (j = 0; j < interval2->nprops; j++)
751 if (interval2->stack[j] == prop)
753 if (j == interval2->nprops)
754 return mdebug_hook ();
758 interval = interval->next;
761 return mdebug_hook ();
762 if (plist->head->prev || plist->tail->next)
763 return mdebug_hook ();
769 /** Return a copy of plist that contains intervals between FROM and TO
770 of PLIST. The copy goes to the position POS of M-text MT. */
773 copy_single_property (MTextPlist *plist, int from, int to, MText *mt, int pos)
776 MInterval *interval1, *interval2;
778 int diff = pos - from;
780 int mask_bits = MTEXTPROP_VOLATILE_STRONG | MTEXTPROP_VOLATILE_WEAK;
782 MSTRUCT_CALLOC (new, MERROR_TEXTPROP);
783 new->key = plist->key;
786 interval1 = find_interval (plist, from);
787 new->head = copy_interval (interval1, mask_bits);
788 for (interval1 = interval1->next, interval2 = new->head;
789 interval1 && interval1->start < to;
790 interval1 = interval1->next, interval2 = interval2->next)
792 interval2->next = copy_interval (interval1, mask_bits);
793 interval2->next->prev = interval2;
795 new->tail = interval2;
796 new->head->start = from;
798 for (interval1 = new->head; interval1; interval1 = interval1->next)
799 for (i = 0; i < interval1->nprops; i++)
800 if (interval1->start == interval1->stack[i]->start
801 || interval1 == new->head)
803 prop = interval1->stack[i];
804 interval1->stack[i] = COPY_TEXT_PROPERTY (prop);
805 interval1->stack[i]->mt = mt;
806 interval1->stack[i]->attach_count++;
807 if (interval1->stack[i]->start < from)
808 interval1->stack[i]->start = from;
809 if (interval1->stack[i]->end > to)
810 interval1->stack[i]->end = to;
811 for (interval2 = interval1->next; interval2;
812 interval2 = interval2->next)
813 for (j = 0; j < interval2->nprops; j++)
814 if (interval2->stack[j] == prop)
816 interval2->stack[j] = interval1->stack[i];
817 interval1->stack[i]->attach_count++;
818 M17N_OBJECT_REF (interval1->stack[i]);
821 adjust_intervals (new->head, new->tail, diff);
822 new->cache = new->head;
823 for (interval1 = new->head; interval1 && interval1->next;
824 interval1 = maybe_merge_interval (new, interval1));
825 xassert (check_plist (new, pos) == 0);
826 if (new->head == new->tail
827 && new->head->nprops == 0)
829 free_interval (new->head);
837 /** Return a newly allocated plist whose key is KEY on M-text MT. */
840 new_plist (MText *mt, MSymbol key)
844 MSTRUCT_MALLOC (plist, MERROR_TEXTPROP);
846 plist->head = new_interval (0, mtext_nchars (mt));
847 plist->tail = plist->head;
848 plist->cache = plist->head;
849 plist->next = mt->plist;
854 /* Free PLIST and return PLIST->next. */
857 free_textplist (MTextPlist *plist)
859 MTextPlist *next = plist->next;
860 MInterval *interval = plist->head;
864 while (interval->nprops > 0)
866 interval = free_interval (interval);
872 /** Return a plist that contains the property KEY of M-text MT. If
873 such a plist does not exist and CREATE is nonzero, create a new
874 plist and return it. */
877 get_plist_create (MText *mt, MSymbol key, int create)
882 while (plist && plist->key != key)
885 /* If MT does not have PROP, make one. */
886 if (! plist && create)
887 plist = new_plist (mt, key);
891 /* Detach PROP. INTERVAL (if not NULL) contains PROP. */
894 detach_property (MTextPlist *plist, MTextProperty *prop, MInterval *interval)
902 M17N_OBJECT_REF (prop);
904 while (interval->start > prop->start)
905 interval = interval->prev;
907 interval = find_interval (plist, prop->start);
911 REMOVE_PROP (interval, prop);
912 if (interval->end == to)
914 interval = interval->next;
916 xassert (prop->attach_count == 0 && prop->mt == NULL);
917 M17N_OBJECT_UNREF (prop);
919 while (head && head->end <= to)
920 head = maybe_merge_interval (plist, head);
921 xassert (check_plist (plist, 0) == 0);
924 /* Delete text properties of PLIST between FROM and TO. MASK_BITS
925 specifies what kind of properties to delete. If DELETING is
926 nonzero, delete such properties too that are completely included in
929 If the resulting PLIST still has any text properties, return 1,
933 delete_properties (MTextPlist *plist, int from, int to,
934 int mask_bits, int deleting)
938 int modified_from = from;
939 int modified_to = to;
943 for (interval = find_interval (plist, from);
944 interval && interval->start < to;
945 interval = interval->next)
946 for (i = 0; i < interval->nprops; i++)
948 MTextProperty *prop = interval->stack[i];
950 if (prop->control.flag & mask_bits)
952 if (prop->start < modified_from)
953 modified_from = prop->start;
954 if (prop->end > modified_to)
955 modified_to = prop->end;
956 detach_property (plist, prop, interval);
960 else if (deleting && prop->start >= from && prop->end <= to)
962 detach_property (plist, prop, interval);
970 interval = find_interval (plist, modified_from);
971 while (interval && interval->start < modified_to)
972 interval = maybe_merge_interval (plist, interval);
975 return (plist->head != plist->tail || plist->head->nprops > 0);
979 pop_interval_properties (MInterval *interval)
981 while (interval->nprops > 0)
987 pop_all_properties (MTextPlist *plist, int from, int to)
991 /* Be sure to have interval boundary at TO. */
992 interval = find_interval (plist, to);
993 if (interval && interval->start < to)
994 divide_interval (plist, interval, to);
996 /* Be sure to have interval boundary at FROM. */
997 interval = find_interval (plist, from);
998 if (interval->start < from)
1000 divide_interval (plist, interval, from);
1001 interval = interval->next;
1004 pop_interval_properties (interval);
1005 while (interval->end < to)
1007 MInterval *next = interval->next;
1009 pop_interval_properties (next);
1010 interval->end = next->end;
1011 interval->next = next->next;
1013 interval->next->prev = interval;
1014 if (next == plist->tail)
1015 plist->tail = interval;
1016 if (plist->cache == next)
1017 plist->cache = interval;
1018 free_interval (next);
1024 /* Delete volatile text properties between FROM and TO. If DELETING
1025 is nonzero, we are going to delete text, thus both strongly and
1026 weakly volatile properties must be deleted. Otherwise we are going
1027 to modify a text property KEY, thus only strongly volatile
1028 properties whose key is not KEY must be deleted. */
1031 prepare_to_modify (MText *mt, int from, int to, MSymbol key, int deleting)
1033 MTextPlist *plist = mt->plist, *prev = NULL;
1034 int mask_bits = MTEXTPROP_VOLATILE_STRONG;
1037 mask_bits |= MTEXTPROP_VOLATILE_WEAK;
1040 if (plist->key != key
1041 && ! delete_properties (plist, from, to, mask_bits, deleting))
1044 plist = prev->next = free_textplist (plist);
1046 plist = mt->plist = free_textplist (plist);
1049 prev = plist, plist = plist->next;
1054 extract_text_properties (MText *mt, int from, int to, MSymbol key,
1058 MTextPlist *list = get_plist_create (mt, key, 0);
1059 MInterval *interval;
1063 interval = find_interval (list, from);
1064 if (interval->nprops == 0
1065 && interval->start <= from && interval->end >= to)
1068 while (interval && interval->start < to)
1070 if (interval->nprops == 0)
1071 top = mplist_find_by_key (top, Mnil);
1074 MPlist *current = top, *place;
1077 for (i = 0; i < interval->nprops; i++)
1079 MTextProperty *prop = interval->stack[i];
1081 place = mplist_find_by_value (current, prop);
1083 current = MPLIST_NEXT (place);
1086 place = mplist_find_by_value (top, prop);
1090 if (MPLIST_NEXT (place) == MPLIST_NEXT (current))
1093 mplist_push (current, Mt, prop);
1094 current = MPLIST_NEXT (current);
1098 interval = interval->next;
1103 #define XML_TEMPLATE "<?xml version=\"1.0\" ?>\n\
1104 <!DOCTYPE mtext [\n\
1105 <!ELEMENT mtext (property*,body+)>\n\
1106 <!ELEMENT property EMPTY>\n\
1107 <!ELEMENT body (#PCDATA)>\n\
1108 <!ATTLIST property key CDATA #REQUIRED>\n\
1109 <!ATTLIST property value CDATA #REQUIRED>\n\
1110 <!ATTLIST property from CDATA #REQUIRED>\n\
1111 <!ATTLIST property to CDATA #REQUIRED>\n\
1112 <!ATTLIST property control CDATA #REQUIRED>\n\
1118 /* for debugging... */
1122 dump_interval (MInterval *interval, int indent)
1124 char *prefix = (char *) alloca (indent + 1);
1127 memset (prefix, 32, indent);
1130 fprintf (mdebug__output, "(interval %d-%d (%d)",
1131 interval->start, interval->end, interval->nprops);
1132 for (i = 0; i < interval->nprops; i++)
1133 fprintf (mdebug__output, "\n%s (%d %d/%d %d-%d 0x%x)",
1135 interval->stack[i]->control.ref_count,
1136 interval->stack[i]->attach_count,
1137 interval->stack[i]->start, interval->stack[i]->end,
1138 (unsigned) interval->stack[i]->val);
1139 fprintf (mdebug__output, ")");
1143 dump_textplist (MTextPlist *plist, int indent)
1145 char *prefix = (char *) alloca (indent + 1);
1147 memset (prefix, 32, indent);
1150 fprintf (mdebug__output, "(properties");
1152 fprintf (mdebug__output, ")\n");
1155 fprintf (mdebug__output, "\n");
1158 MInterval *interval = plist->head;
1160 fprintf (mdebug__output, "%s (%s", prefix, msymbol_name (plist->key));
1163 fprintf (mdebug__output, " (%d %d",
1164 interval->start, interval->end);
1165 if (interval->nprops > 0)
1169 for (i = 0; i < interval->nprops; i++)
1170 fprintf (mdebug__output, " 0x%x",
1171 (int) interval->stack[i]->val);
1173 fprintf (mdebug__output, ")");
1174 interval = interval->next;
1176 fprintf (mdebug__output, ")\n");
1177 xassert (check_plist (plist, 0) == 0);
1178 plist = plist->next;
1189 M17N_OBJECT_ADD_ARRAY (text_property_table, "Text property");
1190 Mtext_prop_serializer = msymbol ("text-prop-serializer");
1191 Mtext_prop_deserializer = msymbol ("text-prop-deserializer");
1198 MIntervalPool *pool = interval_pool_root.next;
1202 MIntervalPool *next = pool->next;
1206 interval_pool_root.next = NULL;
1210 /** Free all plists. */
1213 mtext__free_plist (MText *mt){
1215 MTextPlist *plist = mt->plist;
1218 plist = free_textplist (plist);
1223 /** Extract intervals between FROM and TO of all properties (except
1224 for volatile ones) in PLIST, and make a new plist from them for
1228 mtext__copy_plist (MTextPlist *plist, int from, int to, MText *mt, int pos)
1230 MTextPlist *copy, *this;
1234 for (copy = NULL; plist && ! copy; plist = plist->next)
1235 copy = copy_single_property (plist, from, to, mt, pos);
1238 for (; plist; plist = plist->next)
1239 if ((this = copy_single_property (plist, from, to, mt, pos)))
1249 mtext__adjust_plist_for_delete (MText *mt, int pos, int len)
1254 if (len == 0 || pos == mt->nchars)
1256 if (len == mt->nchars)
1258 mtext__free_plist (mt);
1263 prepare_to_modify (mt, pos, to, Mnil, 1);
1264 for (plist = mt->plist; plist; plist = plist->next)
1266 MInterval *interval = pop_all_properties (plist, pos, to);
1267 MInterval *prev = interval->prev, *next = interval->next;
1275 adjust_intervals (next, plist->tail, -len);
1281 next = maybe_merge_interval (plist, prev);
1282 plist->cache = next ? next : prev;
1283 free_interval (interval);
1284 xassert (check_plist (plist, 0) == 0);
1289 mtext__adjust_plist_for_insert (MText *mt, int pos, int nchars,
1292 MTextPlist *pl, *pl_last, *pl2, *p;
1294 MInterval *interval;
1296 if (mt->nchars == 0)
1298 mtext__free_plist (mt);
1302 if (pos > 0 && pos < mtext_nchars (mt))
1303 prepare_to_modify (mt, pos, pos, Mnil, 0);
1305 for (pl_last = NULL, pl = mt->plist; pl; pl_last = pl, pl = pl->next)
1307 MInterval *interval, *prev, *next, *head, *tail;
1310 prev = NULL, next = pl->head;
1311 else if (pos == mtext_nchars (mt))
1312 prev = pl->tail, next = NULL;
1315 next = find_interval (pl, pos);
1316 if (next->start < pos)
1318 divide_interval (pl, next, pos);
1321 for (i = 0; i < next->nprops; i++)
1322 if (next->stack[i]->start < pos)
1323 split_property (next->stack[i], next);
1327 xassert (check_plist (pl, 0) == 0);
1328 for (p = NULL, pl2 = plist; pl2 && pl->key != pl2->key;
1329 p = pl2, pl2 = p->next);
1332 xassert (check_plist (pl2, pl2->head->start) == 0);
1334 p->next = pl2->next;
1336 plist = plist->next;
1344 head = tail = new_interval (pos, pos + nchars);
1357 adjust_intervals (next, pl->tail, nchars);
1359 xassert (check_plist (pl, 0) == 0);
1360 if (prev && prev->nprops > 0)
1362 for (interval = prev;
1363 interval->next != next && interval->next->nprops == 0;
1364 interval = interval->next)
1365 for (i = 0; i < interval->nprops; i++)
1367 MTextProperty *prop = interval->stack[i];
1369 if (prop->control.flag & MTEXTPROP_REAR_STICKY)
1370 PUSH_PROP (interval->next, prop);
1373 xassert (check_plist (pl, 0) == 0);
1374 if (next && next->nprops > 0)
1376 for (interval = next;
1377 interval->prev != prev && interval->prev->nprops == 0;
1378 interval = interval->prev)
1379 for (i = 0; i < interval->nprops; i++)
1381 MTextProperty *prop = interval->stack[i];
1383 if (prop->control.flag & MTEXTPROP_FRONT_STICKY)
1384 PUSH_PROP (interval->prev, prop);
1388 interval = prev ? prev : pl->head;
1389 pl->cache = interval;
1390 while (interval && interval->start <= pos + nchars)
1391 interval = maybe_merge_interval (pl, interval);
1392 xassert (check_plist (pl, 0) == 0);
1396 pl_last->next = plist;
1400 for (; plist; plist = plist->next)
1402 plist->cache = plist->head;
1405 if (plist->head->nprops)
1407 interval = new_interval (0, pos);
1408 interval->next = plist->head;
1409 plist->head->prev = interval;
1410 plist->head = interval;
1413 plist->head->start = 0;
1415 if (pos < mtext_nchars (mt))
1417 if (plist->tail->nprops)
1419 interval = new_interval (pos + nchars,
1420 mtext_nchars (mt) + nchars);
1421 interval->prev = plist->tail;
1422 plist->tail->next = interval;
1423 plist->tail = interval;
1426 plist->tail->end = mtext_nchars (mt) + nchars;
1428 xassert (check_plist (plist, 0) == 0);
1432 /* len1 > 0 && len2 > 0 */
1435 mtext__adjust_plist_for_change (MText *mt, int pos, int len1, int len2)
1437 int pos2 = pos + len1;
1439 prepare_to_modify (mt, pos, pos2, Mnil, 0);
1443 int diff = len2 - len1;
1446 for (plist = mt->plist; plist; plist = plist->next)
1448 MInterval *head = find_interval (plist, pos2);
1449 MInterval *tail = plist->tail;
1450 MTextProperty *prop;
1455 if (head->start == pos2)
1457 while (tail != head)
1459 for (i = 0; i < tail->nprops; i++)
1461 prop = tail->stack[i];
1462 if (prop->start == tail->start)
1463 prop->start += diff, prop->end += diff;
1465 tail->start += diff;
1470 for (i = 0; i < tail->nprops; i++)
1471 tail->stack[i]->end += diff;
1475 else if (len1 > len2)
1477 mtext__adjust_plist_for_delete (mt, pos + len2, len1 - len2);
1483 #endif /* !FOR_DOXYGEN || DOXYGEN_INTERNAL_MODULE */
1488 /*** @addtogroup m17nTextProperty */
1493 @brief Get the value of the topmost text property.
1495 The mtext_get_prop () function searches the character at $POS in
1496 M-text $MT for the text property whose key is $KEY.
1499 If a text property is found, mtext_get_prop () returns the value
1500 of the property. If the property has multiple values, it returns
1501 the topmost one. If no such property is found, it returns @c NULL
1502 without changing the external variable #merror_code.
1504 If an error is detected, mtext_get_prop () returns @c NULL and
1505 assigns an error code to the external variable #merror_code.
1507 @note If @c NULL is returned without an error, there are two
1510 @li the character at $POS does not have a property whose key is $KEY, or
1512 @li the character does have such a property and its value is @c NULL.
1514 If you need to distinguish these two cases, use the
1515 mtext_get_prop_values () function instead. */
1518 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î°ìÈÖ¾å¤ÎÃͤòÆÀ¤ë.
1520 ´Ø¿ô mtext_get_prop () ¤Ï¡¢M-text $MT Æâ¤Î°ÌÃÖ $POS ¤Ë¤¢¤ëʸ»ú¤Î¥Æ
1521 ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£
1524 ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬¤ß¤Ä¤«¤ì¤Ð¡¢mtext_get_prop () ¤Ï¤½¤Î¥×¥í¥Ñ¥Æ¥£
1525 ¤ÎÃͤòÊÖ¤¹¡£Ãͤ¬Ê£¿ô¸ºß¤¹¤ë¤È¤¤Ï¡¢°ìÈÖ¾å¤ÎÃͤòÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±
1526 ¤ì¤Ð³°ÉôÊÑ¿ô #merror_code ¤òÊѹ¹¤¹¤ë¤³¤È¤Ê¤¯ @c NULL ¤òÊÖ¤¹¡£
1528 ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç mtext_get_prop () ¤Ï @c NULL ¤òÊÖ¤·¡¢³°ÉôÊÑ
1529 ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
1531 @note ¥¨¥é¡¼¤Ê¤·¤Ç @c NULL ¤¬ÊÖ¤µ¤ì¤¿¾ì¹ç¤Ë¤ÏÆó¤Ä¤Î²ÄǽÀ¤¬¤¢¤ë¡£
1533 @li $POS ¤Î°ÌÃÖ¤Îʸ»ú¤Ï $KEY ¤ò¥¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿¤Ê¤¤¡£
1535 @li ¤½¤Îʸ»ú¤Ï¤½¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Á¡¢¤½¤ÎÃͤ¬ @c NULL ¤Ç¤¢¤ë¡£
1537 ¤³¤ÎÆó¤Ä¤ò¶èÊ̤¹¤ëɬÍפ¬¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢´Ø¿ô mtext_get_prop_values ()
1538 ¤òÂå¤ï¤ê¤Ë»ÈÍѤ¹¤ë¤³¤È¡£
1540 @latexonly \IPAlabel{mtext_get_prop} @endlatexonly */
1544 @c MERROR_RANGE, @c MERROR_SYMBOL
1547 mtext_get_prop_values (), mtext_put_prop (), mtext_put_prop_values (),
1548 mtext_push_prop (), mtext_pop_prop (), mtext_prop_range () */
1551 mtext_get_prop (MText *mt, int pos, MSymbol key)
1554 MInterval *interval;
1557 M_CHECK_POS (mt, pos, NULL);
1559 plist = get_plist_create (mt, key, 0);
1563 interval = find_interval (plist, pos);
1564 val = (interval->nprops
1565 ? interval->stack[interval->nprops - 1]->val : NULL);
1572 @brief Get multiple values of a text property.
1574 The mtext_get_prop_values () function searches the character at
1575 $POS in M-text $MT for the property whose key is $KEY. If such
1576 a property is found, its values are stored in the memory area
1577 pointed to by $VALUES. $NUM limits the maximum number of stored
1581 If the operation was successful, mtext_get_prop_values () returns
1582 the number of actually stored values. If the character at $POS
1583 does not have a property whose key is $KEY, the return value is
1584 0. If an error is detected, mtext_get_prop_values () returns -1 and
1585 assigns an error code to the external variable #merror_code. */
1588 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊ£¿ô¸ÄÆÀ¤ë.
1590 ´Ø¿ô mtext_get_prop_values () ¤Ï¡¢M-text $MT Æâ¤Ç $POS ¤È¤¤¤¦°ÌÃÖ
1591 ¤Ë¤¢¤ëʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¤â¤Î¤òõ¤¹¡£¤â¤·¤½
1592 ¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ì¤Ð¡¢¤½¤ì¤¬»ý¤ÄÃÍ (Ê£¿ô²Ä) ¤ò $VALUES
1593 ¤Î»Ø¤¹¥á¥â¥êÎΰè¤Ë³ÊǼ¤¹¤ë¡£$NUM ¤Ï³ÊǼ¤¹¤ëÃͤοô¤Î¾å¸Â¤Ç¤¢¤ë¡£
1596 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_get_prop_values () ¤Ï¼ÂºÝ¤Ë¥á¥â¥ê¤Ë³ÊǼ¤µ
1597 ¤ì¤¿Ãͤοô¤òÊÖ¤¹¡£$POS ¤Î°ÌÃÖ¤Îʸ»ú¤¬ $KEY ¤ò¥¡¼¤È¤¹¤ë¥×¥í¥Ñ¥Æ¥£
1598 ¤ò»ý¤¿¤Ê¤±¤ì¤Ð 0 ¤òÊÖ¤¹¡£¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ï -1 ¤òÊÖ¤·¡¢³°Éô
1599 ÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
1601 @latexonly \IPAlabel{mtext_get_prop_values} @endlatexonly */
1605 @c MERROR_RANGE, @c MERROR_SYMBOL
1608 mtext_get_prop (), mtext_put_prop (), mtext_put_prop_values (),
1609 mtext_push_prop (), mtext_pop_prop (), mtext_prop_range () */
1612 mtext_get_prop_values (MText *mt, int pos, MSymbol key,
1613 void **values, int num)
1616 MInterval *interval;
1621 M_CHECK_POS (mt, pos, -1);
1623 plist = get_plist_create (mt, key, 0);
1627 interval = find_interval (plist, pos);
1628 /* It is assured that INTERVAL is not NULL. */
1629 nprops = interval->nprops;
1630 if (nprops == 0 || num <= 0)
1632 if (nprops == 1 || num == 1)
1634 values[0] = interval->stack[nprops - 1]->val;
1639 num = nprops, offset = 0;
1641 offset = nprops - num;
1642 for (i = 0; i < num; i++)
1643 values[i] = interval->stack[offset + i]->val;
1650 @brief Get a list of text property keys at a position of an M-text.
1652 The mtext_get_prop_keys () function creates an array whose
1653 elements are the keys of text properties found at position $POS in
1654 M-text $MT, and sets *$KEYS to the address of the created array.
1655 The user is responsible to free the memory allocated for
1659 If the operation was successful, mtext_get_prop_keys () returns
1660 the length of the key list. Otherwise it returns -1 and assigns
1661 an error code to the external variable #merror_code.
1666 @brief M-text ¤Î»ØÄꤷ¤¿°ÌÃ֤Υƥ¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤Î¥ê¥¹¥È¤òÆÀ¤ë.
1668 ´Ø¿ô mtext_get_prop_keys () ¤Ï¡¢M-text $MT Æâ¤Ç $POS ¤Î°ÌÃ֤ˤ¢¤ë
1669 ¤¹¤Ù¤Æ¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÍ×ÁǤȤ¹¤ëÇÛÎó¤òºî¤ê¡¢¤½¤ÎÇÛÎó¤Î
1670 ¥¢¥É¥ì¥¹¤ò *$KEYS ¤ËÀßÄꤹ¤ë¡£¤³¤ÎÇÛÎó¤Î¤¿¤á¤Ë³ÎÊݤµ¤ì¤¿¥á¥â¥ê¤ò²ò
1671 Êü¤¹¤ë¤Î¤Ï¥æ¡¼¥¶¤ÎÀÕǤ¤Ç¤¢¤ë¡£
1674 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_get_prop_keys () ¤ÏÆÀ¤é¤ì¤¿¥ê¥¹¥È¤ÎŤµ¤òÊÖ
1675 ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤ò
1684 mtext_get_prop (), mtext_put_prop (), mtext_put_prop_values (),
1685 mtext_get_prop_values (), mtext_push_prop (), mtext_pop_prop () */
1688 mtext_get_prop_keys (MText *mt, int pos, MSymbol **keys)
1693 M_CHECK_POS (mt, pos, -1);
1694 for (i = 0, plist = mt->plist; plist; i++, plist = plist->next);
1700 MTABLE_MALLOC (*keys, i, MERROR_TEXTPROP);
1701 for (i = 0, plist = mt->plist; plist; plist = plist->next)
1703 MInterval *interval = find_interval (plist, pos);
1705 if (interval->nprops)
1706 (*keys)[i++] = plist->key;
1714 @brief Set a text property.
1716 The mtext_put_prop () function sets a text property to the
1717 characters between $FROM (inclusive) and $TO (exclusive) in M-text
1718 $MT. $KEY and $VAL specify the key and the value of the text
1719 property. With this function,
1723 M-text: |<------------|-------- MT ---------|------------>|
1724 PROP : <------------------ OLD_VAL -------------------->
1731 M-text: |<------------|-------- MT ---------|------------>|
1732 PROP : <-- OLD_VAL-><-------- VAL -------><-- OLD_VAL-->
1736 If the operation was successful, mtext_put_prop () returns 0.
1737 Otherwise it returns -1 and assigns an error code to the external
1738 variable #merror_code. */
1741 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë.
1743 ´Ø¿ô mtext_put_prop () ¤Ï¡¢M-text $MT ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é
1744 $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¡¢¥¡¼¤¬ $KEY ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¤è
1745 ¤¦¤Ê¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ¤ë¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ
1750 M-text: |<------------|-------- MT ---------|------------>|
1751 PROP: <------------------ OLD_VAL -------------------->
1758 M-text: |<------------|-------- MT ---------|------------>|
1759 PROP: <-- OLD_VAL-><-------- VAL -------><-- OLD_VAL-->
1763 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð mtext_put_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1
1764 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
1766 @latexonly \IPAlabel{mtext_put_prop} @endlatexonly */
1770 @c MERROR_RANGE, @c MERROR_SYMBOL
1773 mtext_put_prop_values (), mtext_get_prop (),
1774 mtext_get_prop_values (), mtext_push_prop (),
1775 mtext_pop_prop (), mtext_prop_range () */
1778 mtext_put_prop (MText *mt, int from, int to, MSymbol key, void *val)
1781 MTextProperty *prop;
1782 MInterval *interval;
1784 M_CHECK_RANGE (mt, from, to, -1, 0);
1786 prepare_to_modify (mt, from, to, key, 0);
1787 plist = get_plist_create (mt, key, 1);
1788 interval = pop_all_properties (plist, from, to);
1789 prop = new_text_property (mt, from, to, key, val, 0);
1790 PUSH_PROP (interval, prop);
1791 M17N_OBJECT_UNREF (prop);
1793 maybe_merge_interval (plist, interval);
1795 maybe_merge_interval (plist, interval->prev);
1796 xassert (check_plist (plist, 0) == 0);
1803 @brief Set multiple text properties with the same key.
1805 The mtext_put_prop_values () function sets a text property to the
1806 characters between $FROM (inclusive) and $TO (exclusive) in M-text
1807 $MT. $KEY and $VALUES specify the key and the values of the text
1808 property. $NUM specifies the number of property values to be set.
1811 If the operation was successful, mtext_put_prop_values () returns
1812 0. Otherwise it returns -1 and assigns an error code to the
1813 external variable #merror_code. */
1816 @brief Ʊ¤¸¥¡¼¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÊ£¿ôÀßÄꤹ¤ë.
1818 ´Ø¿ô mtext_put_prop_values () ¤Ï¡¢M-Text $MT ¤Î$FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë
1819 ¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀßÄꤹ
1820 ¤ë¡£¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤Ï $KEY ¤Ë¤è¤Ã¤Æ¡¢ÃÍ(Ê£¿ô²Ä)¤Ï $VALUES
1821 ¤Ë¤è¤Ã¤Æ»ØÄꤵ¤ì¤ë¡£$NUM ¤ÏÀßÄꤵ¤ì¤ëÃͤθĿô¤Ç¤¢¤ë¡£
1824 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_put_prop_values () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
1825 ¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
1827 @latexonly \IPAlabel{mtext_put_prop_values} @endlatexonly */
1831 @c MERROR_RANGE, @c MERROR_SYMBOL
1834 mtext_put_prop (), mtext_get_prop (), mtext_get_prop_values (),
1835 mtext_push_prop (), mtext_pop_prop (), mtext_prop_range () */
1838 mtext_put_prop_values (MText *mt, int from, int to,
1839 MSymbol key, void **values, int num)
1842 MInterval *interval;
1845 M_CHECK_RANGE (mt, from, to, -1, 0);
1847 prepare_to_modify (mt, from, to, key, 0);
1848 plist = get_plist_create (mt, key, 1);
1849 interval = pop_all_properties (plist, from, to);
1852 PREPARE_INTERVAL_STACK (interval, num);
1853 for (i = 0; i < num; i++)
1856 = new_text_property (mt, from, to, key, values[i], 0);
1857 PUSH_PROP (interval, prop);
1858 M17N_OBJECT_UNREF (prop);
1862 maybe_merge_interval (plist, interval);
1864 maybe_merge_interval (plist, interval->prev);
1865 xassert (check_plist (plist, 0) == 0);
1872 @brief Push a text property.
1874 The mtext_push_prop () function pushes a text property whose key
1875 is $KEY and value is $VAL to the characters between $FROM
1876 (inclusive) and $TO (exclusive) in M-text $MT. With this
1881 M-text: |<------------|-------- MT ---------|------------>|
1882 PROP : <------------------ OLD_VAL -------------------->
1889 M-text: |<------------|-------- MT ---------|------------>|
1890 PROP : <------------------- OLD_VAL ------------------->
1891 PROP : <-------- VAL ------->
1895 If the operation was successful, mtext_push_prop () returns 0.
1896 Otherwise it returns -1 and assigns an error code to the external
1897 variable #merror_code. */
1900 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥×¥Ã¥·¥å¤¹¤ë.
1902 ´Ø¿ô mtext_push_prop () ¤Ï¡¢¥¡¼¤¬ $KEY ¤ÇÃͤ¬ $VAL ¤Ç¤¢¤ë¥Æ¥¥¹¥È
1903 ¥×¥í¥Ñ¥Æ¥£¤ò¡¢M-text $MT Ãæ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê
1904 ¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤Ë¥×¥Ã¥·¥å¤¹¤ë¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ
1908 M-text: |<------------|-------- MT ---------|------------>|
1909 PROP : <------------------ OLD_VAL -------------------->
1914 M-text: |<------------|-------- MT ---------|------------>|
1915 PROP : <------------------- OLD_VAL ------------------->
1916 PROP : <-------- VAL ------->
1920 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_push_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð
1921 -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
1923 @latexonly \IPAlabel{mtext_push_prop} @endlatexonly */
1927 @c MERROR_RANGE, @c MERROR_SYMBOL
1930 mtext_put_prop (), mtext_put_prop_values (),
1931 mtext_get_prop (), mtext_get_prop_values (),
1932 mtext_pop_prop (), mtext_prop_range () */
1935 mtext_push_prop (MText *mt, int from, int to,
1936 MSymbol key, void *val)
1939 MInterval *head, *tail, *interval;
1940 MTextProperty *prop;
1941 int check_head, check_tail;
1943 M_CHECK_RANGE (mt, from, to, -1, 0);
1945 prepare_to_modify (mt, from, to, key, 0);
1946 plist = get_plist_create (mt, key, 1);
1948 /* Find an interval that covers the position FROM. */
1949 head = find_interval (plist, from);
1951 /* If the found interval starts before FROM, divide it at FROM. */
1952 if (head->start < from)
1954 divide_interval (plist, head, from);
1961 /* Find an interval that ends at TO. If TO is not at the end of an
1962 interval, make one that ends at TO. */
1963 if (head->end == to)
1968 else if (head->end > to)
1970 divide_interval (plist, head, to);
1976 tail = find_interval (plist, to);
1982 else if (tail->start == to)
1989 divide_interval (plist, tail, to);
1994 prop = new_text_property (mt, from, to, key, val, 0);
1996 /* Push PROP to the current values of intervals between HEAD and TAIL
1997 (both inclusive). */
1998 for (interval = head; ; interval = interval->next)
2000 PUSH_PROP (interval, prop);
2001 if (interval == tail)
2005 M17N_OBJECT_UNREF (prop);
2007 /* If there is a possibility that TAIL now has the same value as the
2008 next one, check it and concatenate them if necessary. */
2009 if (tail->next && check_tail)
2010 maybe_merge_interval (plist, tail);
2012 /* If there is a possibility that HEAD now has the same value as the
2013 previous one, check it and concatenate them if necessary. */
2014 if (head->prev && check_head)
2015 maybe_merge_interval (plist, head->prev);
2017 xassert (check_plist (plist, 0) == 0);
2024 @brief Pop a text property.
2026 The mtext_pop_prop () function removes the topmost text property
2027 whose key is $KEY from the characters between $FROM (inclusive)
2028 and and $TO (exclusive) in $MT.
2030 This function does nothing if characters in the region have no
2031 such text property. With this function,
2035 M-text: |<------------|-------- MT ---------|------------>|
2036 PROP : <------------------ OLD_VAL -------------------->
2043 M-text: |<------------|-------- MT ---------|------------>|
2044 PROP : <--OLD_VAL-->| |<--OLD_VAL-->|
2048 If the operation was successful, mtext_pop_prop () return 0.
2049 Otherwise it returns -1 and assigns an error code to the external
2050 variable #merror_code. */
2053 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ý¥Ã¥×¤¹¤ë.
2055 ´Ø¿ô mtext_pop_prop () ¤Ï¡¢¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î
2056 ¤¦¤Á°ìÈÖ¾å¤Î¤â¤Î¤ò¡¢M-text $MT ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO¡Ê´Þ¤Þ
2057 ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎʸ»ú¤«¤é¼è¤ê½ü¤¯¡£
2059 »ØÄêÈϰϤÎʸ»ú¤¬¤½¤Î¤è¤¦¤Ê¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿¤Ê¤¤¤Ê¤é¤Ð¡¢¤³¤Î´Ø¿ô¤Ï²¿
2060 ¤â¤·¤Ê¤¤¡£¤³¤Î´Ø¿ô¤Ë¤è¤Ã¤Æ¡¢
2064 M-text: |<------------|-------- MT ---------|------------>|
2065 PROP : <------------------ OLD_VAL -------------------->
2067 ¤Ï°Ê²¼¤Î¤è¤¦¤Ë¤Ê¤ë¡£
2070 M-text: |<------------|-------- MT ---------|------------>|
2071 PROP : <--OLD_VAL-->| |<--OLD_VAL-->|
2075 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_pop_prop () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1
2076 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£
2078 @latexonly \IPAlabel{mtext_pop_prop} @endlatexonly */
2082 @c MERROR_RANGE, @c MERROR_SYMBOL
2085 mtext_put_prop (), mtext_put_prop_values (),
2086 mtext_get_prop (), mtext_get_prop_values (),
2087 mtext_push_prop (), mtext_prop_range () */
2090 mtext_pop_prop (MText *mt, int from, int to, MSymbol key)
2093 MInterval *head, *tail;
2097 MERROR (MERROR_TEXTPROP, -1);
2098 M_CHECK_RANGE (mt, from, to, -1, 0);
2099 plist = get_plist_create (mt, key, 0);
2103 /* Find an interval that covers the position FROM. */
2104 head = find_interval (plist, from);
2106 && head->nprops == 0)
2107 /* No property to pop. */
2110 prepare_to_modify (mt, from, to, key, 0);
2112 /* If the found interval starts before FROM and has value(s), divide
2114 if (head->start < from)
2116 if (head->nprops > 0)
2118 divide_interval (plist, head, from);
2126 /* Pop the topmost text property from each interval following HEAD.
2127 Stop at an interval that ends after TO. */
2128 for (tail = head; tail && tail->end <= to; tail = tail->next)
2129 if (tail->nprops > 0)
2134 if (tail->start < to)
2136 if (tail->nprops > 0)
2138 divide_interval (plist, tail, to);
2147 to = plist->tail->start;
2149 /* If there is a possibility that HEAD now has the same text
2150 properties as the previous one, check it and concatenate them if
2152 if (head->prev && check_head)
2154 while (head && head->end <= to)
2155 head = maybe_merge_interval (plist, head);
2157 xassert (check_plist (plist, 0) == 0);
2164 @brief Find the range where the value of a text property is the same.
2166 The mtext_prop_range () function investigates the extent where all
2167 characters have the same value for a text property. It first
2168 finds the value of the property specified by $KEY of the character
2169 at $POS in M-text $MT. Then it checks if adjacent characters have
2170 the same value for the property $KEY. The beginning and the end
2171 of the found range are stored to the variable pointed to by $FROM
2172 and $TO. The character position stored in $FROM is inclusive but
2173 that in $TO is exclusive; this fashion is compatible with the
2174 range specification in the mtext_put_prop () function, etc.
2176 If $DEEPER is not 0, not only the topmost but also all the stacked
2177 properties whose key is $KEY are compared.
2179 If $FROM is @c NULL, the beginning of range is not searched for. If
2180 $TO is @c NULL, the end of range is not searched for.
2184 If the operation was successful, mtext_prop_range () returns the
2185 number of values the property $KEY has at pos. Otherwise it
2186 returns -1 and assigns an error code to the external variable @c
2190 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬Æ±¤¸Ãͤò¤È¤ëÈϰϤòÄ´¤Ù¤ë.
2192 ´Ø¿ô mtext_prop_range () ¤Ï¡¢»ØÄꤷ¤¿¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬Æ±¤¸
2193 ¤Ç¤¢¤ëϢ³¤·¤¿Ê¸»ú¤ÎÈϰϤòÄ´¤Ù¤ë¡£¤Þ¤º M-text $MT ¤Î $POS ¤Î°ÌÃÖ¤Ë
2194 ¤¢¤ëʸ»ú¤Î¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á¡¢¥¡¼ $KEY ¤Ç»ØÄꤵ¤ì¤¿¤â¤ÎÃͤò¸«¤Ä¤±
2195 ¤ë¡£¤½¤·¤ÆÁ°¸å¤Îʸ»ú¤â $KEY ¤Î¥×¥í¥Ñ¥Æ¥£¤ÎÃͤ¬Æ±¤¸¤Ç¤¢¤ë¤«¤É¤¦¤«¤ò
2196 Ä´¤Ù¤ë¡£¸«¤Ä¤±¤¿ÈϰϤκǽé¤ÈºÇ¸å¤ò¡¢¤½¤ì¤¾¤ì $FROM ¤È $TO ¤Ë¥Ý¥¤¥ó
2197 ¥È¤µ¤ì¤ëÊÑ¿ô¤ËÊݸ¤¹¤ë¡£$FROM ¤ËÊݸ¤µ¤ì¤ëʸ»ú¤Î°ÌÃ֤ϸ«¤Ä¤±¤¿ÈÏ°Ï
2198 ¤Ë´Þ¤Þ¤ì¤ë¤¬¡¢$TO ¤Ï´Þ¤Þ¤ì¤Ê¤¤¡£¡Ê$TO ¤ÎÁ°¤ÇƱ¤¸Ãͤò¤È¤ëÈϰϤϽª¤ï
2199 ¤ë¡£¡Ë¤³¤ÎÈÏ°Ï»ØÄêË¡¤Ï¡¢´Ø¿ô mtext_put_prop () ¤Ê¤É¤È¶¦Ä̤Ǥ¢¤ë¡£
2201 $DEEPER ¤¬ 0 ¤Ç¤Ê¤±¤ì¤Ð¡¢$KEY ¤È¤¤¤¦¥¡¼¤ò»ý¤Ä¥×¥í¥Ñ¥Æ¥£¤Î¤¦¤Á°ìÈÖ
2202 ¾å¤Î¤â¤Î¤À¤±¤Ç¤Ê¤¯¡¢¥¹¥¿¥Ã¥¯Ãæ¤Î¤¹¤Ù¤Æ¤Î¤â¤Î¤¬Èæ³Ó¤µ¤ì¤ë¡£
2204 $FROM ¤¬ @c NULL ¤Ê¤é¤Ð¡¢ÈϰϤλϤޤê¤Ïõº÷¤·¤Ê¤¤¡£$TO ¤¬ @c NULL
2205 ¤Ê¤é¤Ð¡¢ÈϰϤνª¤ê¤Ïõº÷¤·¤Ê¤¤¡£
2208 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_prop_range () ¤Ï $KEY ¥×¥í¥Ñ¥Æ¥£¤ÎÃͤοô¤ò
2209 ÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð-1 ¤òÊÖ¤·¡¢ ³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼
2212 @latexonly \IPAlabel{mtext_prop_range} @endlatexonly */
2216 @c MERROR_RANGE, @c MERROR_SYMBOL
2219 mtext_put_prop (), mtext_put_prop_values (),
2220 mtext_get_prop (), mtext_get_prop_values (),
2221 mtext_pop_prop (), mtext_push_prop () */
2224 mtext_prop_range (MText *mt, MSymbol key, int pos,
2225 int *from, int *to, int deeper)
2228 MInterval *interval, *temp;
2232 M_CHECK_POS (mt, pos, -1);
2234 plist = get_plist_create (mt, key, 0);
2237 if (from) *from = 0;
2238 if (to) *to = mtext_nchars (mt);
2242 interval = find_interval (plist, pos);
2243 nprops = interval->nprops;
2244 if (deeper || ! nprops)
2246 if (from) *from = interval->start;
2247 if (to) *to = interval->end;
2248 return interval->nprops;
2251 val = nprops ? interval->stack[nprops - 1] : NULL;
2255 for (temp = interval;
2257 && (temp->prev->nprops
2259 && (val == temp->prev->stack[temp->prev->nprops - 1]))
2262 *from = temp->start;
2267 for (temp = interval;
2269 && (temp->next->nprops
2271 && val == temp->next->stack[temp->next->nprops - 1])
2281 @brief Create a text property.
2283 The mtext_property () function returns a newly allocated text
2284 property whose key is $KEY and value is $VAL. The created text
2285 property is not attached to any M-text, i.e. it is detached.
2287 $CONTROL_BITS must be 0 or logical OR of @c enum @c
2288 MTextPropertyControl. */
2291 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÀ¸À®¤¹¤ë.
2293 ´Ø¿ô mtext_property () ¤Ï $KEY ¤ò¥¡¼¡¢$VAL ¤òÃͤȤ¹¤ë¿·¤·¤¯³ä¤êÅö
2294 ¤Æ¤é¤ì¤¿¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÊÖ¤¹¡£À¸À®¤·¤¿¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¤¤«
2295 ¤Ê¤ë M-text ¤Ë¤âÉղ䵤ì¤Æ¤¤¤Ê¤¤¡¢¤¹¤Ê¤ï¤ÁʬΥ¤·¤Æ (detached) ¤¤¤ë¡£
2297 $CONTROL_BITS ¤Ï 0 ¤Ç¤¢¤ë¤« @c enum @c MTextPropertyControl ¤ÎÏÀÍý
2298 OR ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£ */
2301 mtext_property (MSymbol key, void *val, int control_bits)
2303 return new_text_property (NULL, 0, 0, key, val, control_bits);
2307 @brief Return the M-text of a text property.
2309 The mtext_property_mtext () function returns the M-text to which
2310 text property $PROP is attached. If $PROP is currently detached,
2311 NULL is returned. */
2314 @brief ¤¢¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä M-text ¤òÊÖ¤¹.
2316 ´Ø¿ô mtext_property_mtext () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£$PROP ¤¬Éղäµ
2317 ¤ì¤Æ¤¤¤ë M-text ¤òÊÖ¤¹¡£¤½¤Î»þÅÀ¤Ç $PROP ¤¬Ê¬Î¥¤·¤Æ¤¤¤ì¤Ð NULL ¤ò
2321 mtext_property_mtext (MTextProperty *prop)
2327 @brief Return the key of a text property.
2329 The mtext_property_key () function returns the key (symbol) of
2330 text property $PROP. */
2333 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î¥¡¼¤òÊÖ¤¹.
2335 ´Ø¿ô mtext_property_key () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î¥¡¼¡Ê¥·
2339 mtext_property_key (MTextProperty *prop)
2345 @brief Return the value of a text property.
2347 The mtext_property_value () function returns the value of text
2351 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ÎÃͤòÊÖ¤¹.
2353 ´Ø¿ô mtext_property_value () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤ÎÃͤòÊÖ
2357 mtext_property_value (MTextProperty *prop)
2363 @brief Return the start position of a text property.
2365 The mtext_property_start () function returns the start position of
2366 text property $PROP. The start position is a character position
2367 of an M-text where $PROP begins. If $PROP is detached, it returns
2371 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î³«»Ï°ÌÃÖ¤òÊÖ¤¹.
2373 ´Ø¿ô mtext_property_start () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î³«»Ï°Ì
2374 ÃÖ¤òÊÖ¤¹¡£³«»Ï°ÌÃÖ¤È¤Ï M-text Ãæ¤Ç $PROP ¤¬»Ï¤Þ¤ëʸ»ú°ÌÃ֤Ǥ¢¤ë¡£
2375 $PROP ¤¬Ê¬Î¥¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢-1 ¤òÊÖ¤¹¡£ */
2378 mtext_property_start (MTextProperty *prop)
2380 return (prop->mt ? prop->start : -1);
2384 @brief Return the end position of a text property.
2386 The mtext_property_end () function returns the end position of
2387 text property $PROP. The end position is a character position of
2388 an M-text where $PROP ends. If $PROP is detached, it returns
2392 @brief ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Î½ªÎ»°ÌÃÖ¤òÊÖ¤¹.
2394 ´Ø¿ô mtext_property_end () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤Î½ªÎ»°ÌÃÖ
2395 ¤òÊÖ¤¹¡£½ªÎ»°ÌÃÖ¤È¤Ï M-text Ãæ¤Ç $PROP ¤¬½ª¤ëʸ»ú°ÌÃ֤Ǥ¢¤ë¡£$PROP
2396 ¤¬Ê¬Î¥¤µ¤ì¤Æ¤¤¤ì¤Ð¡¢-1 ¤òÊÖ¤¹¡£ */
2399 mtext_property_end (MTextProperty *prop)
2401 return (prop->mt ? prop->end : -1);
2405 @brief Get the topmost text property.
2407 The mtext_get_property () function searches the character at
2408 position $POS in M-text $MT for a text property whose key is $KEY.
2411 If a text property is found, mtext_get_property () returns it. If
2412 there are multiple text properties, it returns the topmost one.
2413 If no such property is found, it returns @c NULL without changing
2414 the external variable #merror_code.
2416 If an error is detected, mtext_get_property () returns @c NULL and
2417 assigns an error code to the external variable #merror_code. */
2420 @brief °ìÈÖ¾å¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÆÀ¤ë.
2422 ´Ø¿ô mtext_get_property () ¤Ï M-text $MT ¤Î°ÌÃÖ $POS ¤Îʸ»ú¤¬¥¡¼
2423 ¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£
2426 ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤¬¸«¤Ä¤«¤ì¤Ð¡¢mtext_get_property () ¤Ï¤½¤ì¤òÊÖ¤¹¡£
2427 Ê£¿ô¤¢¤ë¾ì¹ç¤Ë¤Ï¡¢°ìÈÖ¾å¤Î¤â¤Î¤òÊÖ¤¹¡£¸«¤Ä¤«¤é¤Ê¤±¤ì¤Ð¡¢³°ÉôÊÑ¿ô
2428 #merror_code ¤òÊѤ¨¤ë¤³¤È¤Ê¤¯ @c NULL ¤òÊÖ¤¹¡£
2430 ¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç mtext_get_property () ¤Ï @c NULL ¤òÊÖ¤·¡¢³°
2431 ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
2434 mtext_get_property (MText *mt, int pos, MSymbol key)
2437 MInterval *interval;
2439 M_CHECK_POS (mt, pos, NULL);
2441 plist = get_plist_create (mt, key, 0);
2445 interval = find_interval (plist, pos);
2446 if (! interval->nprops)
2448 return interval->stack[interval->nprops - 1];
2452 @brief Get multiple text properties.
2454 The mtext_get_properties () function searches the character at
2455 $POS in M-text $MT for properties whose key is $KEY. If such
2456 properties are found, they are stored in the memory area pointed
2457 to by $PROPS. $NUM limits the maximum number of stored
2461 If the operation was successful, mtext_get_properties () returns
2462 the number of actually stored properties. If the character at
2463 $POS does not have a property whose key is $KEY, the return value
2464 is 0. If an error is detected, mtext_get_properties () returns -1
2465 and assigns an error code to the external variable #merror_code. */
2468 @brief Ê£¿ô¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÆÀ¤ë.
2470 ´Ø¿ô mtext_get_properties () ¤Ï M-text $MT ¤Î°ÌÃÖ $POS ¤Îʸ»ú¤¬¥¡¼
2471 ¤¬ $KEY ¤Ç¤¢¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò»ý¤Ä¤«¤É¤¦¤«¤òÄ´¤Ù¤ë¡£¤½¤Î¤è¤¦¤Ê
2472 ¥×¥í¥Ñ¥Æ¥£¤¬¤ß¤Ä¤«¤ì¤Ð¡¢$PROPS ¤¬»Ø¤¹¥á¥â¥êÎΰè¤ËÊݸ¤¹¤ë¡£$NUM ¤Ï
2473 Êݸ¤µ¤ì¤ë¥×¥í¥Ñ¥Æ¥£¤Î¿ô¤Î¾å¸Â¤Ç¤¢¤ë¡£
2476 ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_get_properties () ¤Ï¼ÂºÝ¤ËÊݸ¤·¤¿¥×¥í¥Ñ¥Æ¥£
2477 ¤Î¿ô¤òÊÖ¤¹¡£$POS ¤Î°ÌÃÖ¤Îʸ»ú¤¬¥¡¼¤¬ $KEY ¤Ç¤¢¤ë¥×¥í¥Ñ¥Æ¥£¤ò»ý¤¿
2478 ¤Ê¤±¤ì¤Ð¡¢0 ¤¬Ê֤롣¥¨¥é¡¼¤¬¸¡½Ð¤µ¤ì¤¿¾ì¹ç¤Ë¤Ï¡¢
2479 mtext_get_properties () ¤Ï -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼
2480 ¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
2483 mtext_get_properties (MText *mt, int pos, MSymbol key,
2484 MTextProperty **props, int num)
2487 MInterval *interval;
2492 M_CHECK_POS (mt, pos, -1);
2494 plist = get_plist_create (mt, key, 0);
2498 interval = find_interval (plist, pos);
2499 /* It is assured that INTERVAL is not NULL. */
2500 nprops = interval->nprops;
2501 if (nprops == 0 || num <= 0)
2503 if (nprops == 1 || num == 1)
2505 props[0] = interval->stack[nprops - 1];
2510 num = nprops, offset = 0;
2512 offset = nprops - num;
2513 for (i = 0; i < num; i++)
2514 props[i] = interval->stack[offset + i];
2519 @brief Attach a text property to an M-text.
2521 The mtext_attach_property () function attaches text property $PROP
2522 to the range between $FROM and $TO in M-text $MT. If $PROP is
2523 already attached to an M-text, it is detached before attached to
2527 If the operation was successful, mtext_attach_property () returns
2528 0. Otherwise it returns -1 and assigns an error code to the
2529 external variable #merror_code. */
2532 @brief M-text¤Ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òÉղ乤ë.
2534 ´Ø¿ô mtext_attach_property () ¤Ï¡¢M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ
2535 ¤Ç¤ÎÎΰè¤Ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤òÉղ乤롣¤â¤· $PROP ¤¬´û¤Ë
2536 M-text ¤ËÉղ䵤ì¤Æ¤¤¤ì¤Ð¡¢$MT ¤ËÉղ乤ëÁ°¤ËʬΥ¤µ¤ì¤ë¡£
2539 ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_attach_property () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
2540 ¤ì¤Ð -1 ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
2544 mtext_attach_property (MText *mt, int from, int to, MTextProperty *prop)
2547 MInterval *interval;
2549 M_CHECK_RANGE (mt, from, to, -1, 0);
2551 M17N_OBJECT_REF (prop);
2553 mtext_detach_property (prop);
2554 prepare_to_modify (mt, from, to, prop->key, 0);
2555 plist = get_plist_create (mt, prop->key, 1);
2556 xassert (check_plist (plist, 0) == 0);
2557 interval = pop_all_properties (plist, from, to);
2558 xassert (check_plist (plist, 0) == 0);
2562 PUSH_PROP (interval, prop);
2563 M17N_OBJECT_UNREF (prop);
2564 xassert (check_plist (plist, 0) == 0);
2566 maybe_merge_interval (plist, interval);
2568 maybe_merge_interval (plist, interval->prev);
2569 xassert (check_plist (plist, 0) == 0);
2574 @brief Detach a text property from an M-text.
2576 The mtext_detach_property () function makes text property $PROP
2580 This function always returns 0. */
2583 @brief M-text ¤«¤é¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤òʬΥ¤¹¤ë.
2585 ´Ø¿ô mtext_detach_property () ¤Ï¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤òʬΥ¤¹¤ë¡£
2588 ¤³¤Î´Ø¿ô¤Ï¾ï¤Ë 0 ¤òÊÖ¤¹¡£ */
2591 mtext_detach_property (MTextProperty *prop)
2594 int start = prop->start, end = prop->end;
2598 prepare_to_modify (prop->mt, start, end, prop->key, 0);
2599 plist = get_plist_create (prop->mt, prop->key, 0);
2601 detach_property (plist, prop, NULL);
2606 @brief Push a text property onto an M-text.
2608 The mtext_push_property () function pushes text property $PROP to
2609 the characters between $FROM (inclusive) and $TO (exclusive) in
2613 If the operation was successful, mtext_push_property () returns
2614 0. Otherwise it returns -1 and assigns an error code to the
2615 external variable #merror_code. */
2618 @brief M-text ¤Ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥×¥Ã¥·¥å¤¹¤ë.
2620 ´Ø¿ô mtext_push_property () ¤Ï¡¢¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£ $PROP ¤ò¡¢
2621 M-text $MT Ãæ¤Î $FROM ¡Ê´Þ¤Þ¤ì¤ë¡Ë¤«¤é $TO ¡Ê´Þ¤Þ¤ì¤Ê¤¤¡Ë¤ÎÈϰϤÎ
2622 ʸ»ú¤Ë¥×¥Ã¥·¥å¤¹¤ë¡£
2625 ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_push_property () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±
2626 ¤ì¤Ð -1 ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£ */
2630 mtext_push_property (MText *mt, int from, int to, MTextProperty *prop)
2633 MInterval *head, *tail, *interval;
2634 int check_head, check_tail;
2636 M_CHECK_RANGE (mt, from, to, -1, 0);
2638 M17N_OBJECT_REF (prop);
2640 mtext_detach_property (prop);
2641 prepare_to_modify (mt, from, to, prop->key, 0);
2642 plist = get_plist_create (mt, prop->key, 1);
2647 /* Find an interval that covers the position FROM. */
2648 head = find_interval (plist, from);
2650 /* If the found interval starts before FROM, divide it at FROM. */
2651 if (head->start < from)
2653 divide_interval (plist, head, from);
2660 /* Find an interval that ends at TO. If TO is not at the end of an
2661 interval, make one that ends at TO. */
2662 if (head->end == to)
2667 else if (head->end > to)
2669 divide_interval (plist, head, to);
2675 tail = find_interval (plist, to);
2681 else if (tail->start == to)
2688 divide_interval (plist, tail, to);
2693 /* Push PROP to the current values of intervals between HEAD and TAIL
2694 (both inclusive). */
2695 for (interval = head; ; interval = interval->next)
2697 PUSH_PROP (interval, prop);
2698 if (interval == tail)
2702 /* If there is a possibility that TAIL now has the same value as the
2703 next one, check it and concatenate them if necessary. */
2704 if (tail->next && check_tail)
2705 maybe_merge_interval (plist, tail);
2707 /* If there is a possibility that HEAD now has the same value as the
2708 previous one, check it and concatenate them if necessary. */
2709 if (head->prev && check_head)
2710 maybe_merge_interval (plist, head->prev);
2712 M17N_OBJECT_UNREF (prop);
2713 xassert (check_plist (plist, 0) == 0);
2718 @brief Symbol for specifying serializer functions.
2720 To serialize a text property, the user must supply a serializer
2721 function for that text property. This is done by giving a symbol
2722 property whose key is #Mtext_prop_serializer and value is a
2723 pointer to an appropriate serializer function.
2726 mtext_serialize (), #MTextPropSerializeFunc
2730 @brief ¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤ò»ØÄꤹ¤ë¥·¥ó¥Ü¥ë.
2732 ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤½¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ
2733 ¥Æ¥£ÍѤΥ·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤òÍ¿¤¨¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¶ñÂÎŪ¤Ë¤Ï¡¢
2734 #Mtext_prop_serializer ¤ò¥¡¼¤È¤·¡¢Å¬Àڤʥ·¥ê¥¢¥é¥¤¥º´Ø¿ô¤Ø¤Î¥Ý¥¤
2735 ¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£
2738 mtext_serialize (), #MTextPropSerializeFunc
2740 MSymbol Mtext_prop_serializer;
2743 @brief Symbol for specifying deserializer functions.
2745 To deserialize a text property, the user must supply a deserializer
2746 function for that text property. This is done by giving a symbol
2747 property whose key is #Mtext_prop_deserializer and value is a
2748 pointer to an appropriate deserializer function.
2751 mtext_deserialize (), #MTextPropSerializeFunc
2755 @brief ¥Ç¥·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤ò»ØÄꤹ¤ë¥·¥ó¥Ü¥ë.
2757 ¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¤¿¤á¤Ë¤Ï¡¢¤½¤Î¥Æ¥¥¹¥È¥×¥í
2758 ¥Ñ¥Æ¥£ÍѤΥǥ·¥ê¥¢¥é¥¤¥¶´Ø¿ô¤òÍ¿¤¨¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£¶ñÂÎŪ¤Ë¤Ï¡¢
2759 #Mtext_prop_deserializer ¤ò¥¡¼¤È¤·¡¢Å¬Àڤʥǥ·¥ê¥¢¥é¥¤¥º´Ø¿ô¤Ø¤Î
2760 ¥Ý¥¤¥ó¥¿¤òÃͤȤ¹¤ë¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£¤ò»ØÄꤹ¤ë¡£
2763 mtext_deserialize (), #MTextPropSerializeFunc
2765 MSymbol Mtext_prop_deserializer;
2768 @brief Serialize text properties in an M-text.
2770 The mtext_serialize () function serializes the text between $FROM
2771 and $TO in M-text $MT. The serialized result is an M-text in a
2772 form of XML. $PROPERTY_LIST limits the text properties to be
2773 serialized. Only those text properties whose key
2775 @li appears as the value of an element in $PROPERTY_LIST, and
2776 @li has the symbol property #Mtext_prop_serializer
2778 are serialized as a "property" element in the resulting XML
2781 The DTD of the generated XML is as follows:
2785 <!ELEMENT mtext (property*,body+)>
2786 <!ELEMENT property EMPTY>
2787 <!ELEMENT body (#PCDATA)>
2788 <!ATTLIST property key CDATA #REQUIRED>
2789 <!ATTLIST property value CDATA #REQUIRED>
2790 <!ATTLIST property from CDATA #REQUIRED>
2791 <!ATTLIST property to CDATA #REQUIRED>
2792 <!ATTLIST property control CDATA #REQUIRED>
2796 This function depends on the libxml2 library. If the m17n library
2797 is configured without libxml2, this function always fails.
2800 If the operation was successful, mtext_serialize () returns an
2801 M-text in the form of XML. Otherwise it returns @c NULL and assigns an
2802 error code to the external variable #merror_code.
2805 mtext_deserialize (), #Mtext_prop_serializer */
2808 @brief M-text Ãæ¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë.
2810 ´Ø¿ô mtext_serialize () ¤Ï M-text $MT ¤Î $FROM ¤«¤é $TO ¤Þ¤Ç¤Î¥Æ¥
2811 ¥¹¥È¤ò¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¡£¥·¥ê¥¢¥é¥¤¥º¤·¤¿·ë²Ì¤Ï XML ·Á¼°¤Î M-text ¤Ç
2812 ¤¢¤ë¡£ $PROPERTY_LIST ¤Ï¥·¥ê¥¢¥é¥¤¥º¤µ¤ì¤ë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¸ÂÄê
2813 ¤¹¤ë¡£ÂоݤȤʤë¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢¤½¤Î¥¡¼¤¬
2815 @li $PROPERTY_LIST ¤ÎÍ×ÁǤÎÃͤȤ·¤Æ¸½¤ï¤ì¡¢¤«¤Ä
2816 @li ¥·¥ó¥Ü¥ë¥×¥í¥Ñ¥Æ¥£ #Mtext_prop_serializer ¤ò»ý¤Ä
2818 ¤â¤Î¤Î¤ß¤Ç¤¢¤ë¡£¤³¤Î¾ò·ï¤òËþ¤¿¤¹¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¡¢À¸À®¤µ¤ì¤ë
2819 XML ɽ¸½Ãæ¤Ç "property" Í×ÁǤ˥·¥ê¥¢¥é¥¤¥º¤µ¤ì¤ë¡£
2821 À¸À®¤µ¤ì¤ë XML ¤Î DTD ¤Ï°Ê²¼¤ÎÄ̤ê:
2825 <!ELEMENT mtext (property*,body+)>
2826 <!ELEMENT property EMPTY>
2827 <!ELEMENT body (#PCDATA)>
2828 <!ATTLIST property key CDATA #REQUIRED>
2829 <!ATTLIST property value CDATA #REQUIRED>
2830 <!ATTLIST property from CDATA #REQUIRED>
2831 <!ATTLIST property to CDATA #REQUIRED>
2832 <!ATTLIST property control CDATA #REQUIRED>
2836 ¤³¤Î´Ø¿ô¤Ï libxml2 ¥é¥¤¥Ö¥é¥ê¤Ë°Í¸¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é¥ê¤¬libxml2
2837 ̵¤·¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤³¤Î´Ø¿ô¤Ï¾ï¤Ë¼ºÇÔ¤¹¤ë¡£
2840 ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_serialize () ¤Ï XML ·Á¼°¤Ç M-text ¤òÊÖ¤¹¡£
2841 ¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô#merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É
2845 mtext_deserialize (), #Mtext_prop_serializer */
2848 mtext_serialize (MText *mt, int from, int to, MPlist *property_list)
2852 MTextPropSerializeFunc func;
2859 M_CHECK_RANGE (mt, from, to, NULL, NULL);
2860 if (mt->format != MTEXT_FORMAT_US_ASCII
2861 && mt->format != MTEXT_FORMAT_UTF_8)
2862 mtext__adjust_format (mt, MTEXT_FORMAT_UTF_8);
2863 if (MTEXT_DATA (mt)[mtext_nbytes (mt)] != 0)
2864 MTEXT_DATA (mt)[mtext_nbytes (mt)] = 0;
2865 doc = xmlParseMemory (XML_TEMPLATE, strlen (XML_TEMPLATE) + 1);
2866 node = xmlDocGetRootElement (doc);
2869 MPLIST_DO (pl, property_list)
2871 MSymbol key = MPLIST_VAL (pl);
2873 func = ((MTextPropSerializeFunc)
2874 msymbol_get_func (key, Mtext_prop_serializer));
2876 extract_text_properties (mt, from, to, key, plist);
2880 MPLIST_DO (pl, plist)
2882 MTextProperty *prop = MPLIST_VAL (pl);
2884 MPlist *serialized_plist;
2887 func = ((MTextPropSerializeFunc)
2888 msymbol_get_func (prop->key, Mtext_prop_serializer));
2889 serialized_plist = (func) (prop->val);
2890 if (! serialized_plist)
2893 mplist__serialize (work, serialized_plist, 0);
2894 child = xmlNewChild (node, NULL, (xmlChar *) "property", NULL);
2895 xmlSetProp (child, (xmlChar *) "key",
2896 (xmlChar *) MSYMBOL_NAME (prop->key));
2897 xmlSetProp (child, (xmlChar *) "value", (xmlChar *) MTEXT_DATA (work));
2898 sprintf (buf, "%d", prop->start - from);
2899 xmlSetProp (child, (xmlChar *) "from", (xmlChar *) buf);
2900 sprintf (buf, "%d", prop->end - from);
2901 xmlSetProp (child, (xmlChar *) "to", (xmlChar *) buf);
2902 sprintf (buf, "%d", prop->control.flag);
2903 xmlSetProp (child, (xmlChar *) "control", (xmlChar *) buf);
2904 xmlAddChild (node, xmlNewText ((xmlChar *) "\n"));
2906 M17N_OBJECT_UNREF (serialized_plist);
2908 M17N_OBJECT_UNREF (plist);
2910 if (from > 0 || to < mtext_nchars (mt))
2911 mtext_copy (work, 0, mt, from, to);
2914 M17N_OBJECT_UNREF (work);
2917 for (from = 0, to = mtext_nchars (mt); from <= to; from++)
2919 ptr = MTEXT_DATA (mt) + POS_CHAR_TO_BYTE (mt, from);
2920 xmlNewTextChild (node, NULL, (xmlChar *) "body", (xmlChar *) ptr);
2921 from = mtext_character (mt, from, to, 0);
2926 xmlDocDumpMemoryEnc (doc, (xmlChar **) &ptr, &n, "UTF-8");
2929 mtext__cat_data (work, ptr, n, MTEXT_FORMAT_UTF_8);
2931 #else /* not HAVE_XML2 */
2932 MERROR (MERROR_TEXTPROP, NULL);
2933 #endif /* not HAVE_XML2 */
2937 @brief Deserialize text properties in an M-text.
2939 The mtext_deserialize () function deserializes M-text $MT. $MT
2940 must be an XML having the following DTD.
2944 <!ELEMENT mtext (property*,body+)>
2945 <!ELEMENT property EMPTY>
2946 <!ELEMENT body (#PCDATA)>
2947 <!ATTLIST property key CDATA #REQUIRED>
2948 <!ATTLIST property value CDATA #REQUIRED>
2949 <!ATTLIST property from CDATA #REQUIRED>
2950 <!ATTLIST property to CDATA #REQUIRED>
2951 <!ATTLIST property control CDATA #REQUIRED>
2955 This function depends on the libxml2 library. If the m17n library
2956 is configured without libxml2, this function always fail.
2959 If the operation was successful, mtext_deserialize () returns the
2960 resulting M-text. Otherwise it returns @c NULL and assigns an error
2961 code to the external variable #merror_code.
2964 mtext_serialize (), #Mtext_prop_deserializer */
2967 @brief M-text Ãæ¤Î¥Æ¥¥¹¥È¥×¥í¥Ñ¥Æ¥£¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë.
2969 ´Ø¿ô mtext_deserialize () ¤Ï M-text $MT ¤ò¥Ç¥·¥ê¥¢¥é¥¤¥º¤¹¤ë¡£$MT
2970 ¤Ï¼¡¤Î DTD ¤ò»ý¤Ä XML ¤Ç¤Ê¤¯¤Æ¤Ï¤Ê¤é¤Ê¤¤¡£
2974 <!ELEMENT mtext (property*,body+)>
2975 <!ELEMENT property EMPTY>
2976 <!ELEMENT body (#PCDATA)>
2977 <!ATTLIST property key CDATA #REQUIRED>
2978 <!ATTLIST property value CDATA #REQUIRED>
2979 <!ATTLIST property from CDATA #REQUIRED>
2980 <!ATTLIST property to CDATA #REQUIRED>
2981 <!ATTLIST property control CDATA #REQUIRED>
2985 ¤³¤Î´Ø¿ô¤Ï libxml2 ¥é¥¤¥Ö¥é¥ê¤Ë°Í¸¤¹¤ë¡£m17n ¥é¥¤¥Ö¥é¥ê¤¬libxml2
2986 ̵¤·¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¾ì¹ç¡¢¤³¤Î´Ø¿ô¤Ï¾ï¤Ë¼ºÇÔ¤¹¤ë¡£
2989 ½èÍý¤ËÀ®¸ù¤¹¤ì¤Ð¡¢mtext_serialize () ¤ÏÆÀ¤é¤ì¤¿ M-text ¤ò
2990 ÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð @c NULL ¤òÊÖ¤·¤Æ³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼
2994 mtext_serialize (), #Mtext_prop_deserializer */
2997 mtext_deserialize (MText *mt)
3002 xmlXPathContextPtr context;
3003 xmlXPathObjectPtr result;
3004 xmlChar *body_str, *key_str, *val_str, *from_str, *to_str, *ctl_str;
3007 if (mt->format > MTEXT_FORMAT_UTF_8)
3008 MERROR (MERROR_TEXTPROP, NULL);
3009 doc = xmlParseMemory ((char *) MTEXT_DATA (mt), mtext_nbytes (mt));
3011 MERROR (MERROR_TEXTPROP, NULL);
3012 node = xmlDocGetRootElement (doc);
3016 MERROR (MERROR_TEXTPROP, NULL);
3018 if (xmlStrcmp (node->name, (xmlChar *) "mtext"))
3021 MERROR (MERROR_TEXTPROP, NULL);
3024 context = xmlXPathNewContext (doc);
3025 result = xmlXPathEvalExpression ((xmlChar *) "//body", context);
3026 if (xmlXPathNodeSetIsEmpty (result->nodesetval))
3029 MERROR (MERROR_TEXTPROP, NULL);
3031 for (i = 0, mt = mtext (); i < result->nodesetval->nodeNr; i++)
3034 mtext_cat_char (mt, 0);
3035 node = (xmlNodePtr) result->nodesetval->nodeTab[i];
3036 body_str = xmlNodeListGetString (doc, node->xmlChildrenNode, 1);
3039 mtext__cat_data (mt, body_str, strlen ((char *) body_str),
3040 MTEXT_FORMAT_UTF_8);
3045 result = xmlXPathEvalExpression ((xmlChar *) "//property", context);
3046 if (! xmlXPathNodeSetIsEmpty (result->nodesetval))
3047 for (i = 0; i < result->nodesetval->nodeNr; i++)
3050 MTextPropDeserializeFunc func;
3051 MTextProperty *prop;
3053 int from, to, control;
3056 key_str = xmlGetProp (result->nodesetval->nodeTab[i],
3058 val_str = xmlGetProp (result->nodesetval->nodeTab[i],
3059 (xmlChar *) "value");
3060 from_str = xmlGetProp (result->nodesetval->nodeTab[i],
3061 (xmlChar *) "from");
3062 to_str = xmlGetProp (result->nodesetval->nodeTab[i],
3064 ctl_str = xmlGetProp (result->nodesetval->nodeTab[i],
3065 (xmlChar *) "control");
3067 key = msymbol ((char *) key_str);
3068 func = ((MTextPropDeserializeFunc)
3069 msymbol_get_func (key, Mtext_prop_deserializer));
3072 plist = mplist__from_string (val_str, strlen ((char *) val_str));
3075 if (sscanf ((char *) from_str, "%d", &from) != 1
3076 || from < 0 || from >= mtext_nchars (mt))
3078 if (sscanf ((char *) to_str, "%d", &to) != 1
3079 || to <= from || to > mtext_nchars (mt))
3081 if (sscanf ((char *) ctl_str, "%d", &control) != 1
3082 || control < 0 || control > MTEXTPROP_CONTROL_MAX)
3084 val = (func) (plist);
3085 M17N_OBJECT_UNREF (plist);
3086 prop = mtext_property (key, val, control);
3087 if (key->managing_key)
3088 M17N_OBJECT_UNREF (val);
3089 mtext_push_property (mt, from, to, prop);
3090 M17N_OBJECT_UNREF (prop);
3098 xmlXPathFreeContext (context);
3101 #else /* not HAVE_XML2 */
3102 MERROR (MERROR_TEXTPROP, NULL);
3103 #endif /* not HAVE_XML2 */