annotate scripts/strings/erase.m @ 27918:b442ec6dda5c

use centralized file for copyright info for individual contributors * COPYRIGHT.md: New file. * In most other files, use "Copyright (C) YYYY-YYYY The Octave Project Developers" instead of tracking individual names in separate source files. The motivation is to reduce the effort required to update the notices each year. Until now, the Octave source files contained copyright notices that list individual contributors. I adopted these file-scope copyright notices because that is what everyone was doing 30 years ago in the days before distributed version control systems. But now, with many contributors and modern version control systems, having these file-scope copyright notices causes trouble when we update copyright years or refactor code. Over time, the file-scope copyright notices may become outdated as new contributions are made or code is moved from one file to another. Sometimes people contribute significant patches but do not add a line claiming copyright. Other times, people add a copyright notice for their contribution but then a later refactoring moves part or all of their contribution to another file and the notice is not moved with the code. As a practical matter, moving such notices is difficult -- determining what parts are due to a particular contributor requires a time-consuming search through the project history. Even managing the yearly update of copyright years is problematic. We have some contributors who are no longer living. Should we update the copyright dates for their contributions when we release new versions? Probably not, but we do still want to claim copyright for the project as a whole. To minimize the difficulty of maintaining the copyright notices, I would like to change Octave's sources to use what is described here: https://softwarefreedom.org/resources/2012/ManagingCopyrightInformation.html in the section "Maintaining centralized copyright notices": The centralized notice approach consolidates all copyright notices in a single location, usually a top-level file. This file should contain all of the copyright notices provided project contributors, unless the contribution was clearly insignificant. It may also credit -- without a copyright notice -- anyone who helped with the project but did not contribute code or other copyrighted material. This approach captures less information about contributions within individual files, recognizing that the DVCS is better equipped to record those details. As we mentioned before, it does have one disadvantage as compared to the file-scope approach: if a single file is separated from the distribution, the recipient won't see the contributors' copyright notices. But this can be easily remedied by including a single copyright notice in each file's header, pointing to the top-level file: Copyright YYYY-YYYY The Octave Project Developers See the COPYRIGHT file at the top-level directory of this distribution or at https://octave.org/COPYRIGHT.html. followed by the usual GPL copyright statement. For more background, see the discussion here: https://lists.gnu.org/archive/html/octave-maintainers/2020-01/msg00009.html Most files in the following directories have been skipped intentinally in this changeset: doc libgui/qterminal liboctave/external m4
author John W. Eaton <jwe@octave.org>
date Mon, 06 Jan 2020 15:38:17 -0500
parents ae1542fb58ba
children 1891570abac8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27918
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26577
diff changeset
1 ## Copyright (C) 2017-2019 The Octave Project Developers
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26577
diff changeset
2 ##
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26577
diff changeset
3 ## See the file COPYRIGHT.md in the top-level directory of this distribution
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26577
diff changeset
4 ## or <https://octave.org/COPYRIGHT.html/>.
b442ec6dda5c use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents: 26577
diff changeset
5 ##
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
6 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
7 ## This file is part of Octave.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
8 ##
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24473
diff changeset
9 ## Octave is free software: you can redistribute it and/or modify it
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
10 ## under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24473
diff changeset
11 ## the Free Software Foundation, either version 3 of the License, or
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
12 ## (at your option) any later version.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
13 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
14 ## Octave is distributed in the hope that it will be useful, but
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
15 ## WITHOUT ANY WARRANTY; without even the implied warranty of
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
17 ## GNU General Public License for more details.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
18 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
19 ## You should have received a copy of the GNU General Public License
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
20 ## along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 24473
diff changeset
21 ## <https://www.gnu.org/licenses/>.
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
22
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
23 ## -*- texinfo -*-
24985
d85b2485af9e doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24634
diff changeset
24 ## @deftypefn {} {@var{newstr} =} erase (@var{str}, @var{ptn})
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
25 ## Delete all occurrences of @var{ptn} within @var{str}.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
26 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
27 ## @var{str} and @var{ptn} can be ordinary strings, cell array of strings, or
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
28 ## character arrays.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
29 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
30 ## Examples
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
31 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
32 ## @example
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
33 ## @group
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
34 ## ## string, single pattern
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
35 ## erase ("Hello World!", " World")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
36 ## @result{} "Hello!"
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
37 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
38 ## ## cellstr, single pattern
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
39 ## erase (@{"Hello", "World!"@}, "World")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
40 ## @result{} @{"Hello", "!"@}
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
41 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
42 ## ## string, multiple patterns
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
43 ## erase ("The Octave interpreter is fabulous", ...
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
44 ## @{"interpreter ", "The "@})
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
45 ## @result{} "Octave is fabulous"
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
46 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
47 ## ## cellstr, multiple patterns
26577
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
48 ## erase (@{"The ", "Octave interpreter ", "is fabulous"@}, ...
ae1542fb58ba documentation: Avoid some overfull lines in the PDF manual.
Markus Mützel <markus.muetzel@gmx.de>
parents: 26376
diff changeset
49 ## @{"interpreter ", "The "@})
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
50 ## @result{} @{"", "Octave ", "is fabulous"@}
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
51 ## @end group
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
52 ## @end example
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
53 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
54 ## Programming Note: @code{erase} deletes the first instance of a pattern in a
24985
d85b2485af9e doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24634
diff changeset
55 ## string when there are overlapping occurrences. For example:
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
56 ##
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
57 ## @example
24985
d85b2485af9e doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24634
diff changeset
58 ## @group
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
59 ## erase ("abababa", "aba")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
60 ## @result{} "b"
24985
d85b2485af9e doc: grammarcheck m-files ahead of 4.4 release.
Rik <rik@octave.org>
parents: 24634
diff changeset
61 ## @end group
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
62 ## @end example
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
63 ##
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 ## See @code{strrep} for processing overlaps.
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
65 ##
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
66 ## @seealso{strrep, regexprep}
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
67 ## @end deftypefn
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
68
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
69 ## Author: Sahil Yadav <yadavsahil5198@gmail.com>
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
70
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
71
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
72 function newstr = erase (str, ptn)
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
73
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
74 if (nargin != 2)
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
75 print_usage ();
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
76 endif
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
77
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
78 ischarmatrix = false;
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79 if (ischar (str))
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
80 if (rows (str) > 1)
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
81 ## Convert to cell. Can't use cellstr which trims spaces.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
82 str = mat2cell (str, ones (1, rows (str)));
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
83 ischarmatrix = true;
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
84 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
85 elseif (! iscellstr (str))
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
86 error ("erase: STR must be a string or cell array of strings");
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
87 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
88
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
89 if (ischar (ptn))
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
90 if (rows (ptn) > 1)
24473
42d099b841aa erase.m: Add warning if a character array is used for PTN.
Rik <rik@octave.org>
parents: 24460
diff changeset
91 warning ("Octave:erase:chararray",
42d099b841aa erase.m: Add warning if a character array is used for PTN.
Rik <rik@octave.org>
parents: 24460
diff changeset
92 "erase: using character array for PTN is not recommended, consider cell array of strings instead");
24460
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
93 ## Convert to cell. Can't use cellstr which trims spaces.
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
94 ptn = mat2cell (ptn, ones (1, rows (ptn)));
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
95 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
96 elseif (! iscellstr (ptn))
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
97 error ("erase: PTN must be a string or cell array of strings");
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
98 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
99
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
100 nptn = ifelse (ischar (ptn), 1, numel (ptn));
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
101 if (nptn == 1)
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
102 newstr = strrep (str, ptn, "", "overlaps", false);
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
103 else
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
104 ptn = regexptranslate ("escape", ptn(:).');
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
105 ptn = strjoin (ptn, '|');
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
106 newstr = regexprep (str, ptn, "");
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
107 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
108
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
109 if (ischarmatrix)
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
110 newstr = char (newstr);
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
111 endif
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
112
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
113 endfunction
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
114
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
115
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
116 %!assert (erase ("Hello World!", " World"), "Hello!")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
117 %!assert (erase ({"Hello World!"}, " World"), {"Hello!"})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
118 %!assert (erase (char ("Hello", "World!"), "World"), char ("Hello ", "!"))
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
119 %!assert (erase ({"Hello", "World!"}, "World"), {"Hello", "!"})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
120 %!assert (erase ("Hello World!", {"o"; "World"; " "}), "Hell!")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
121
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
122 ## Test overlaps
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
123 ## from https://savannah.gnu.org/bugs/?52647#comment5
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
124 %!assert (erase ('ababa', 'aba'), 'ba')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
125 %!assert (erase ('abababa', 'aba'), 'b')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
126 %!assert (erase ('ababababa', 'aba'), 'bba')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
127 %!assert (erase ('ababababa', {'aba', 'bba'}), 'bba')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
128 %!assert (erase ('ababababa ', {'aba', 'bba'}), 'bba ')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
129 %!assert (erase ({' ababababa '}, {'aba', 'bba'}), {' bba '})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
130 %!assert (erase (' ababa ', {'aba', 'baba'}), ' ba ')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
131 %!assert (erase (' Hello World t ', {'t';'llo'}), ' He World ')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
132 %!assert (erase ({' Hello World t '}, [ 'o ']), {' HellWorld t '})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
133 %!assert (erase ( 'Hello World t ', {'ld '; 'o '}), 'HellWort ')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
134 %!assert (erase ('aba', 'aba'), '')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
135 %!assert (erase ({'aba'}, 'aba'), ({""}))
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
136 %!assert (erase ('', 'aba'), '')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
137 %!assert (erase ({'abbabbabba'},{'abba'}), {'bb'})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
138 %!assert (erase ({'ababababa';'abbabbabba'}, 'aba'), {'bba';'abbabbabba'})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
139 %!assert (erase ({''}, {''}), {''})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
140 %!assert (erase ({'pppppppp'}, 'p'), {''})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
141 %!assert (erase ('Hello World t ', {'ld '; 'o '}), 'HellWort ')
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
142 %!assert (erase ({'Hello World t '}, {'ld '; 'o '}), {'HellWort '})
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
143
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
144 ## Test input validation
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
145 %!error erase ()
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
146 %!error erase ("a")
892f7f096ffb erase.m: New string function for deleting substrings with a string.
Sahil Yadav
parents:
diff changeset
147 %!error erase ("a", "b", "c")
24634
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
148 %!error <STR must be a string> erase ([1], "foo")
ab2321d4ba03 maint: strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
149 %!error <PTN must be a string> erase ("foo", [1])
24473
42d099b841aa erase.m: Add warning if a character array is used for PTN.
Rik <rik@octave.org>
parents: 24460
diff changeset
150 %!warning <using character array for PTN is not recommended>
42d099b841aa erase.m: Add warning if a character array is used for PTN.
Rik <rik@octave.org>
parents: 24460
diff changeset
151 %! erase ("a", ["a";"b"]);