# HG changeset patch # User Aidan Kehoe # Date 1275420761 -3600 # Node ID 35c2b7e9c03f81755f3eff0fdcb2c27212bb8e65 # Parent acc4a6c9f5f93e478d86ff8366a3d934aa54cd2e Add #'substring-no-properties, omitting any extent data. 2010-06-01 Aidan Kehoe * fns.c (Fsubstring_no_properties): Add this function, API taken from GNU, though ours drops all extent data, not just properties. diff -r acc4a6c9f5f9 -r 35c2b7e9c03f src/ChangeLog --- 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 + + * 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 * glyphs.c (syms_of_glyphs): diff -r acc4a6c9f5f9 -r 35c2b7e9c03f src/fns.c --- 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); /* #### */ }