[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: input フィールドの入力文字数制限



>>>>> In [emacs-w3m : No.02511] 
>>>>>	KURODA Chihiro <chee@subdimension.com> wrote:

黒> 例えば、www.google.com で size=31 maxlength=2048
黒> のところで日本語 15 文字 + 英字 1 文字以上を打ちこむと
黒> Wrong type argument: natnump -1

XEmacs では truncate-string が wide char を考慮しないためのようです。

XEmacs:
(truncate-string "012345678901234567890" 31)
 => "012345678901234567890"

GNU Emacs:
(truncate-string "012345678901234567890" 31)
 => "012345678901234"

以下の変更でどうでしょうか。
Index: w3m-form.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-form.el,v
retrieving revision 1.71
diff -u -r1.71 w3m-form.el
--- w3m-form.el	2001/12/17 07:19:37	1.71
+++ w3m-form.el	2002/01/11 03:41:20
@@ -597,7 +597,7 @@
 		      (make-string (length string) ?.)
 		    (mapconcat 'identity
 			       (split-string
-				(truncate-string string width) "\n")
+				(w3m-truncate-string string width) "\n")
 			       "")))
 	    (make-string (- width (string-width string)) ?\ ))
     (delete-region (point)
Index: w3m-util.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-util.el,v
retrieving revision 1.10
diff -u -r1.10 w3m-util.el
--- w3m-util.el	2002/01/07 00:34:59	1.10
+++ w3m-util.el	2002/01/11 03:41:20
@@ -354,5 +354,19 @@
 	(cancel-timer w3m-refresh-timer)
 	(setq w3m-refresh-timer nil)))))
 
+(defun w3m-truncate-string (str end-column)
+  "Truncate string STR to end at column END-COLUMN."
+  (let ((len (length str))
+	(column 0)
+	(idx 0))
+    (condition-case nil
+	(while (< column end-column)
+	  (setq column (+ column (char-width (aref str idx)))
+		idx (1+ idx)))
+      (args-out-of-range (setq idx len)))
+    (when (> column end-column)
+      (setq idx (1- idx)))
+    (substring str 0 idx)))
+
 (provide 'w3m-util)
 ;;; w3m-util.el ends here

-- 
有沢 明宏