aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-08-29 03:50:02 +0000
committerRichard M. Stallman1996-08-29 03:50:02 +0000
commit21fbc8e5aec8803e1cd19c8c0eb7f5bae8df2ae4 (patch)
treed28ff5f12a565bc02185351c0ac61ecc7e7a509f /src
parentecc06779805efb671c41c524e24bc6ddd128f11f (diff)
downloademacs-21fbc8e5aec8803e1cd19c8c0eb7f5bae8df2ae4.tar.gz
emacs-21fbc8e5aec8803e1cd19c8c0eb7f5bae8df2ae4.zip
(Fsubstring): Handle vectors as well as strings.
Diffstat (limited to 'src')
-rw-r--r--src/fns.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/src/fns.c b/src/fns.c
index 64e2834bb1b..64969bc9cab 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -509,31 +509,49 @@ Elements of ALIST that are not conses are also shared.")
509DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0, 509DEFUN ("substring", Fsubstring, Ssubstring, 2, 3, 0,
510 "Return a substring of STRING, starting at index FROM and ending before TO.\n\ 510 "Return a substring of STRING, starting at index FROM and ending before TO.\n\
511TO may be nil or omitted; then the substring runs to the end of STRING.\n\ 511TO may be nil or omitted; then the substring runs to the end of STRING.\n\
512If FROM or TO is negative, it counts from the end.") 512If FROM or TO is negative, it counts from the end.\n\
513\n\
514This function allows vectors as well as strings.")
513 (string, from, to) 515 (string, from, to)
514 Lisp_Object string; 516 Lisp_Object string;
515 register Lisp_Object from, to; 517 register Lisp_Object from, to;
516{ 518{
517 Lisp_Object res; 519 Lisp_Object res;
520 int size;
521
522 if (! (STRINGP (string) || VECTORP (string)))
523 wrong_type_argument (Qarrayp, string);
518 524
519 CHECK_STRING (string, 0);
520 CHECK_NUMBER (from, 1); 525 CHECK_NUMBER (from, 1);
526
527 if (STRINGP (string))
528 size = XSTRING (string)->size;
529 else
530 size = XVECTOR (string)->size;
531
521 if (NILP (to)) 532 if (NILP (to))
522 to = Flength (string); 533 to = size;
523 else 534 else
524 CHECK_NUMBER (to, 2); 535 CHECK_NUMBER (to, 2);
525 536
526 if (XINT (from) < 0) 537 if (XINT (from) < 0)
527 XSETINT (from, XINT (from) + XSTRING (string)->size); 538 XSETINT (from, XINT (from) + size);
528 if (XINT (to) < 0) 539 if (XINT (to) < 0)
529 XSETINT (to, XINT (to) + XSTRING (string)->size); 540 XSETINT (to, XINT (to) + size);
530 if (!(0 <= XINT (from) && XINT (from) <= XINT (to) 541 if (!(0 <= XINT (from) && XINT (from) <= XINT (to)
531 && XINT (to) <= XSTRING (string)->size)) 542 && XINT (to) <= size))
532 args_out_of_range_3 (string, from, to); 543 args_out_of_range_3 (string, from, to);
533 544
534 res = make_string (XSTRING (string)->data + XINT (from), 545 if (STRINGP (string))
535 XINT (to) - XINT (from)); 546 {
536 copy_text_properties (from, to, string, make_number (0), res, Qnil); 547 res = make_string (XSTRING (string)->data + XINT (from),
548 XINT (to) - XINT (from));
549 copy_text_properties (from, to, string, make_number (0), res, Qnil);
550 }
551 else
552 res = Fvector (XINT (to) - XINT (from),
553 XVECTOR (string)->contents + XINT (from));
554
537 return res; 555 return res;
538} 556}
539 557