(enum MTextLineBreakOption): New enum.
[m17n/m17n-lib.git] / src / mtext.c
index 8821a31..e83e369 100644 (file)
@@ -1126,6 +1126,15 @@ mtext__eol (MText *mt, int pos)
 
 typedef int (*MTextWordsegFunc) (MText *mt, int pos, int *from, int *to);
 
+/* Find word boundaries around POS of MT.  Set *FROM to the word
+   boundary position at or previous to POS, and update *TO to the word
+   boundary position after POS.
+
+   @return If word boundaries were found successfully, return 1 (if
+   the character at POS is a part of a word) or 0 (otherwise).  If the
+   operation was not successful, return -1 without setting *FROM and
+   *TO.  */
+
 int
 mtext__word_segment (MText *mt, int pos, int *from, int *to)
 {
@@ -1135,7 +1144,6 @@ mtext__word_segment (MText *mt, int pos, int *from, int *to)
 
   if (func)
     return (func) (mt, pos, from, to);
-  *from = *to = pos;
   return -1;
 }
 
@@ -1650,19 +1658,7 @@ mtext_cat_char (MText *mt, int c)
 MText *
 mtext_dup (MText *mt)
 {
-  MText *new = mtext ();
-  int unit_bytes = UNIT_BYTES (mt->format);
-
-  *new = *mt;
-  if (mt->nchars > 0)
-    {
-      new->allocated = (mt->nbytes + 1) * unit_bytes;
-      MTABLE_MALLOC (new->data, new->allocated, MERROR_MTEXT);
-      memcpy (new->data, mt->data, new->allocated);
-      if (mt->plist)
-       new->plist = mtext__copy_plist (mt->plist, 0, mt->nchars, new, 0);
-    }
-  return new;
+  return mtext_duplicate (mt, 0, mtext_nchars (mt));
 }
 
 /*=*/
@@ -2025,7 +2021,7 @@ mtext_del (MText *mt, int from, int to)
 /***ja
     @brief M-text ¤òÊ̤ΠM-text ¤ËÁÞÆþ¤¹¤ë.
 
-    ´Ø¿ô mtext_ins () ¤Ï M-text $MT1 ¤Î $POS ¤Î°ÌÃ֤ˠÊ̤ΠM-text $MT2 
+    ´Ø¿ô mtext_ins () ¤Ï M-text $MT1 ¤Î $POS ¤Î°ÌÃÖ¤ËÊ̤ΠM-text $MT2 
     ¤òÁÞÆþ¤¹¤ë¡£¤³¤Î·ë²Ì $MT1 ¤ÎŤµ¤Ï $MT2 ¤ÎŤµÊ¬¤À¤±Áý¤¨¤ë¡£ÁÞÆþ¤ÎºÝ¡¢$MT2
     ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì¤ë¡£$MT2 ¤½¤Î¤â¤Î¤ÏÊѹ¹¤µ¤ì¤Ê¤¤¡£
 
@@ -2035,10 +2031,10 @@ mtext_del (MText *mt, int from, int to)
 
 /***
     @errors
-    @c MERROR_RANGE
+    @c MERROR_RANGE , @c MERROR_MTEXT
 
     @seealso
-    mtext_del ()  */
+    mtext_del () , mtext_insert ()  */
 
 int
 mtext_ins (MText *mt1, int pos, MText *mt2)
@@ -2067,6 +2063,26 @@ mtext_ins (MText *mt1, int pos, MText *mt2)
     0.  Otherwise, it returns -1 and assigns an error code to the
     external variable #merror_code.  */
 
+/***ja
+    @brief M-text ¤Î°ìÉô¤òÊ̤ΠM-text ¤ËÁÞÆþ¤¹¤ë.
+
+    ´Ø¿ô mtext_insert () ¤Ï M-text $MT1 Ãæ¤Î $POS ¤Î°ÌÃ֤ˡ¢Ê̤Π
+    M-text $MT2 ¤Î $FROM ¡Ê$FROM ¼«ÂΤâ´Þ¤à¡Ë¤«¤é $TO ¡Ê$TO ¼«ÂΤϴޤÞ
+    ¤Ê¤¤¡Ë¤Þ¤Ç¤Îʸ»ú¤òÁÞÆþ¤¹¤ë¡£·ë²ÌŪ¤Ë $MT1 ¤ÏŤµ¤¬ ($TO - $FROM) 
+    ¤À¤±¿­¤Ó¤ë¡£ÁÞÆþ¤ÎºÝ¡¢ $MT2 Ãæ¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£¤Ï¤¹¤Ù¤Æ·Ñ¾µ¤µ¤ì
+    ¤ë¡£
+
+    @return
+    ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢mtext_insert () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê¤±¤ì¤Ð -1 
+    ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_MTEXT , @c MERROR_RANGE
+
+    @seealso
+    mtext_ins ()  */
+
 int
 mtext_insert (MText *mt1, int pos, MText *mt2, int from, int to)
 {
@@ -2154,7 +2170,7 @@ mtext_ins_char (MText *mt, int pos, int c, int n)
   if (mt->cache_char_pos > pos)
     {
       mt->cache_char_pos += n;
-      mt->cache_byte_pos += nunits + n;
+      mt->cache_byte_pos += nunits * n;
     }
   memmove (mt->data + (pos_unit + nunits * n) * unit_bytes,
           mt->data + pos_unit * unit_bytes,
@@ -2199,6 +2215,25 @@ mtext_ins_char (MText *mt, int pos, int c, int n)
     0.  Otherwise, it returns -1 and assigns an error code to the
     external variable #merror_code.  */
 
+/***ja
+    @brief M-text ¤Î°ìÉô¤òÊ̤ΠM-text ¤Î°ìÉô¤ÇÃÖ´¹¤¹¤ë.
+
+    ´Ø¿ô mtext_replace () ¤Ï¡¢ M-text $MT1 ¤Î $FROM1 ¡Ê$FROM1 ¼«ÂΤâ´Þ
+    ¤à¡Ë¤«¤é $TO1 ¡Ê$TO1 ¼«ÂΤϴޤޤʤ¤¡Ë¤Þ¤Ç¤ò¡¢ M-text $MT2 ¤Î 
+    $FROM2 ¡Ê$FROM2 ¼«ÂΤâ´Þ¤à¡Ë¤«¤é $TO2 ¡Ê$TO2 ¼«ÂΤϴޤޤʤ¤¡Ë¤ÇÃÖ
+    ¤­´¹¤¨¤ë¡£¿·¤·¤¯ÁÞÆþ¤µ¤ì¤¿Éôʬ¤Ï¡¢ÃÖ¤­´¹¤¨¤ëÁ°¤Î¥Æ¥­¥¹¥È¥×¥í¥Ñ¥Æ¥£
+    ¤¹¤Ù¤Æ¤ò·Ñ¾µ¤¹¤ë¡£
+
+    @return ½èÍý¤¬À®¸ù¤¹¤ì¤Ð¡¢ mtext_replace () ¤Ï 0 ¤òÊÖ¤¹¡£¤½¤¦¤Ç¤Ê
+    ¤±¤ì¤Ð -1 ¤òÊÖ¤·¡¢³°ÉôÊÑ¿ô #merror_code ¤Ë¥¨¥é¡¼¥³¡¼¥É¤òÀßÄꤹ¤ë¡£  */
+
+/***
+    @errors
+    @c MERROR_MTEXT , @c MERROR_RANGE
+
+    @seealso
+    mtext_insert ()  */
+
 int
 mtext_replace (MText *mt1, int from1, int to1,
               MText *mt2, int from2, int to2)