7019
|
1 /* |
|
2 |
7081
|
3 Copyright (C) 2006, 2007 John W. Eaton |
7019
|
4 |
|
5 This file is part of Octave. |
|
6 |
7081
|
7 Octave is free software; you can redistribute it and/or |
|
8 modify it under the terms of the GNU General Public License |
|
9 as published by the Free Software Foundation; either |
|
10 version 3 of the License, or (at your option) any later |
|
11 version. |
7019
|
12 |
7081
|
13 Octave is distributed in the hope that it will be useful, |
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty |
|
15 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
16 See the GNU General Public License for more details. |
7019
|
17 |
7081
|
18 You should have received a copy of the GNU General Public |
|
19 License along with Octave; see the file COPYING. If not, |
|
20 see <http://www.gnu.org/licenses/>. |
7019
|
21 |
|
22 */ |
|
23 |
6572
|
24 #include <octave/oct.h> |
|
25 |
|
26 DEFUN_DLD (stringdemo, args, , "String Demo") |
|
27 { |
|
28 int nargin = args.length(); |
|
29 octave_value_list retval; |
|
30 |
|
31 if (nargin != 1) |
|
32 print_usage (); |
|
33 else |
|
34 { |
|
35 charMatrix ch = args(0).char_matrix_value (); |
|
36 |
|
37 if (! error_state) |
|
38 { |
|
39 if (args(0).is_sq_string ()) |
|
40 retval(1) = octave_value (ch, true); |
|
41 else |
|
42 retval(1) = octave_value (ch, true, '\''); |
|
43 |
|
44 octave_idx_type nr = ch.rows(); |
|
45 for (octave_idx_type i = 0; i < nr / 2; i++) |
|
46 { |
|
47 std::string tmp = ch.row_as_string (i); |
7081
|
48 ch.insert (ch.row_as_string(nr-i-1).c_str(), |
|
49 i, 0); |
6572
|
50 ch.insert (tmp.c_str(), nr-i-1, 0); |
|
51 } |
|
52 retval(0) = octave_value (ch, true); |
|
53 } |
|
54 } |
|
55 return retval; |
|
56 } |