comparison examples/code/stringdemo.cc @ 20753:2f8500ca91d3

eliminate error_state from example files * addtwomatrices.cc, celldemo.cc, embedded.cc, fortrandemo.cc, funcdemo.cc, globaldemo.cc, helloworld.cc, make_int.cc, paramdemo.cc, stringdemo.cc, structdemo.cc, unwinddemo.cc: Eliminate use of global error_state variable.
author John W. Eaton <jwe@octave.org>
date Sat, 03 Oct 2015 16:05:27 -0400
parents c8240a60dd01
children
comparison
equal deleted inserted replaced
20752:c547458dc10e 20753:2f8500ca91d3
1 #include <octave/oct.h> 1 #include <octave/oct.h>
2 2
3 DEFUN_DLD (stringdemo, args, , "String Demo") 3 DEFUN_DLD (stringdemo, args, , "String Demo")
4 { 4 {
5 octave_value_list retval; 5 octave_value_list retval;
6 int nargin = args.length ();
7 6
8 if (nargin != 1) 7 if (args.length () != 1)
9 print_usage (); 8 print_usage ();
10 else 9
10 charMatrix ch = args(0).char_matrix_value ();
11
12 retval(1) = octave_value (ch, '\''); // Single Quote String
13
14 octave_idx_type nr = ch.rows ();
15
16 for (octave_idx_type i = 0; i < nr / 2; i++)
11 { 17 {
12 charMatrix ch = args(0).char_matrix_value (); 18 std::string tmp = ch.row_as_string (i);
13 19
14 if (! error_state) 20 ch.insert (ch.row_as_string (nr-i-1).c_str (), i, 0);
15 { 21 ch.insert (tmp.c_str (), nr-i-1, 0);
16 retval(1) = octave_value (ch, '\''); // Single Quote String 22 }
17 23
18 octave_idx_type nr = ch.rows (); 24 retval(0) = octave_value (ch, '"'); // Double Quote String
19 for (octave_idx_type i = 0; i < nr / 2; i++) 25
20 {
21 std::string tmp = ch.row_as_string (i);
22 ch.insert (ch.row_as_string (nr-i-1).c_str (), i, 0);
23 ch.insert (tmp.c_str (), nr-i-1, 0);
24 }
25 retval(0) = octave_value (ch, '"'); // Double Quote String
26 }
27 }
28 return retval; 26 return retval;
29 } 27 }