changeset 5224:35c2b7e9c03f

Add #'substring-no-properties, omitting any extent data. 2010-06-01 Aidan Kehoe <kehoea@parhasard.net> * fns.c (Fsubstring_no_properties): Add this function, API taken from GNU, though ours drops all extent data, not just properties.
author Aidan Kehoe <kehoea@parhasard.net>
date Tue, 01 Jun 2010 20:32:41 +0100
parents acc4a6c9f5f9
children 1086297242fe
files src/ChangeLog src/fns.c
diffstat 2 files changed, 32 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Tue Jun 01 20:31:11 2010 +0100
+++ b/src/ChangeLog	Tue Jun 01 20:32:41 2010 +0100
@@ -1,3 +1,9 @@
+2010-06-01  Aidan Kehoe  <kehoea@parhasard.net>
+
+	* fns.c (Fsubstring_no_properties):
+	Add this function, API taken from GNU, though ours drops all
+	extent data, not just properties.
+
 2010-06-01  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* glyphs.c (syms_of_glyphs):
--- a/src/fns.c	Tue Jun 01 20:31:11 2010 +0100
+++ b/src/fns.c	Tue Jun 01 20:32:41 2010 +0100
@@ -992,6 +992,9 @@
 The returned subsequence is always of the same type as SEQUENCE.
 If SEQUENCE is a string, relevant parts of the string-extent-data
 are copied to the new string.
+
+See also `substring-no-properties', which only operates on strings, and does
+not copy extent data.
 */
        (sequence, start, end))
 {
@@ -1080,6 +1083,28 @@
     }
 }
 
+DEFUN ("substring-no-properties", Fsubstring_no_properties, 1, 3, 0, /* 
+Return a substring of STRING, without copying the extents.
+END may be nil or omitted; then the substring runs to the end of STRING.
+If START or END is negative, it counts from the end.
+
+With one argument, copy STRING without its properties.
+*/
+       (string, start, end))
+{
+  Charcount ccstart, ccend;
+  Bytecount bstart, blen;
+  Lisp_Object val;
+
+  get_string_range_char (string, start, end, &ccstart, &ccend,
+                         GB_HISTORICAL_STRING_BEHAVIOR);
+  bstart = string_index_char_to_byte (string, ccstart);
+  blen = string_offset_char_to_byte_len (string, bstart, ccend - ccstart);
+  val = make_string (XSTRING_DATA (string) + bstart, blen);
+
+  return val;
+}
+
 /* Split STRING into a list of substrings.  The substrings are the
    parts of original STRING separated by SEPCHAR.
 
@@ -5609,6 +5634,7 @@
   DEFSUBR (Fbase64_decode_region);
   DEFSUBR (Fbase64_decode_string);
 
+  DEFSUBR (Fsubstring_no_properties);
   DEFSUBR (Fsplit_string_by_char);
   DEFSUBR (Fsplit_path);	/* #### */
 }