annotate liboctave/chMatrix.cc @ 11273:bd2643f0ce57 ss-3-3-54

snapshot 3.3.54
author John W. Eaton <jwe@octave.org>
date Fri, 19 Nov 2010 16:05:58 -0500
parents a117dc8ea1b9
children fd0a3ac60b0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1993
1b57120c997b [project @ 1996-03-03 01:16:15 by jwe]
jwe
parents: 1948
diff changeset
1 // Matrix manipulations.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
2 /*
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
3
7017
a1dbe9d80eee [project @ 2007-10-12 21:27:11 by jwe]
jwe
parents: 7016
diff changeset
4 Copyright (C) 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2004, 2005,
8920
eb63fbe60fab update copyright notices
John W. Eaton <jwe@octave.org>
parents: 8774
diff changeset
5 2006, 2007, 2008, 2009 John W. Eaton
10521
4d1fc073fbb7 add some missing copyright stmts
Jaroslav Hajek <highegg@gmail.com>
parents: 10362
diff changeset
6 Copyright (C) 2010 VZLU Prague
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
7
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
8 This file is part of Octave.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
9
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
10 Octave is free software; you can redistribute it and/or modify it
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
11 under the terms of the GNU General Public License as published by the
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
12 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
13 option) any later version.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
14
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
15 Octave is distributed in the hope that it will be useful, but WITHOUT
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
17 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
18 for more details.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
19
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
20 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
21 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6979
diff changeset
22 <http://www.gnu.org/licenses/>.
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
23
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
24 */
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
25
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
26 #ifdef HAVE_CONFIG_H
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
27 #include <config.h>
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
28 #endif
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
29
7048
845ca0affec0 [project @ 2007-10-22 16:55:41 by jwe]
jwe
parents: 7017
diff changeset
30 #include <cstring>
845ca0affec0 [project @ 2007-10-22 16:55:41 by jwe]
jwe
parents: 7017
diff changeset
31
3503
d14c483b3c12 [project @ 2000-02-01 04:06:07 by jwe]
jwe
parents: 3225
diff changeset
32 #include <iostream>
1728
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1573
diff changeset
33 #include <string>
42b4f904f1af [project @ 1996-01-09 11:36:01 by jwe]
jwe
parents: 1573
diff changeset
34
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
35 #include "lo-error.h"
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
36 #include "str-vec.h"
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
37 #include "mx-base.h"
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
38 #include "mx-inlines.cc"
8774
b756ce0002db split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents: 8750
diff changeset
39 #include "mx-op-defs.h"
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
40
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
41 // charMatrix class.
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
42
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
43 charMatrix::charMatrix (char c)
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
44 : Array<char> ()
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
45 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
46 octave_idx_type nc = 1;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
47 octave_idx_type nr = 1;
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
48
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
49 resize (nr, nc);
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
50
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
51 elem (0, 0) = c;
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
52 }
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
53
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
54 charMatrix::charMatrix (const char *s)
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
55 : Array<char> ()
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
56 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
57 octave_idx_type nc = s ? strlen (s) : 0;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
58 octave_idx_type nr = s && nc > 0 ? 1 : 0;
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
59
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
60 resize (nr, nc);
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
61
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
62 for (octave_idx_type i = 0; i < nc; i++)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
63 elem (0, i) = s[i];
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
64 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
65
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
66 charMatrix::charMatrix (const std::string& s)
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
67 : Array<char> ()
1733
f236cc1c8bee [project @ 1996-01-11 05:51:25 by jwe]
jwe
parents: 1728
diff changeset
68 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
69 octave_idx_type nc = s.length ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
70 octave_idx_type nr = nc > 0 ? 1 : 0;
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
71
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
72 resize (nr, nc);
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
73
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
74 for (octave_idx_type i = 0; i < nc; i++)
1733
f236cc1c8bee [project @ 1996-01-11 05:51:25 by jwe]
jwe
parents: 1728
diff changeset
75 elem (0, i) = s[i];
f236cc1c8bee [project @ 1996-01-11 05:51:25 by jwe]
jwe
parents: 1728
diff changeset
76 }
f236cc1c8bee [project @ 1996-01-11 05:51:25 by jwe]
jwe
parents: 1728
diff changeset
77
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
78 charMatrix::charMatrix (const string_vector& s)
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
79 : Array<char> (s.length (), s.max_length (), 0)
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
80 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
81 octave_idx_type nr = rows ();
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
82
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
83 for (octave_idx_type i = 0; i < nr; i++)
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
84 {
9370
4ff6f8efdda2 fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
85 const std::string si = s(i);
4ff6f8efdda2 fix slow cellstr -> char matrix conversions
Jaroslav Hajek <highegg@gmail.com>
parents: 9227
diff changeset
86 octave_idx_type nc = si.length ();
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
87 for (octave_idx_type j = 0; j < nc; j++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
88 elem (i, j) = si[j];
2349
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
89 }
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
90 }
b369227ce3d2 [project @ 1996-07-27 07:59:20 by jwe]
jwe
parents: 2255
diff changeset
91
2384
d9147efd1a93 [project @ 1996-10-12 17:56:38 by jwe]
jwe
parents: 2350
diff changeset
92 bool
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
93 charMatrix::operator == (const charMatrix& a) const
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
94 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
95 if (rows () != a.rows () || cols () != a.cols ())
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
96 return 0;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
97
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
98 return mx_inline_equal (length (), data (), a.data ());
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
99 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
100
2384
d9147efd1a93 [project @ 1996-10-12 17:56:38 by jwe]
jwe
parents: 2350
diff changeset
101 bool
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
102 charMatrix::operator != (const charMatrix& a) const
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
103 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
104 return !(*this == a);
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
105 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
106
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
107 charMatrix&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
108 charMatrix::insert (const char *s, octave_idx_type r, octave_idx_type c)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
109 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
110 if (s)
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
111 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
112 octave_idx_type s_len = strlen (s);
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
113
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
114 if (r < 0 || r >= rows () || c < 0 || c + s_len - 1 > cols ())
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
115 {
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
116 (*current_liboctave_error_handler) ("range error for insert");
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
117 return *this;
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
118 }
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
119
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
120 for (octave_idx_type i = 0; i < s_len; i++)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
121 elem (r, c+i) = s[i];
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
122 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
123 return *this;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
124 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
125
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
126 charMatrix&
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
127 charMatrix::insert (const charMatrix& a, octave_idx_type r, octave_idx_type c)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
128 {
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
129 Array<char>::insert (a, r, c);
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
130 return *this;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
131 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
132
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
133 std::string
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
134 charMatrix::row_as_string (octave_idx_type r, bool strip_ws) const
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
135 {
3504
5eef8a2294bd [project @ 2000-02-01 10:06:51 by jwe]
jwe
parents: 3503
diff changeset
136 std::string retval;
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
137
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
138 octave_idx_type nr = rows ();
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
139 octave_idx_type nc = cols ();
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
140
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
141 if (r == 0 && nr == 0 && nc == 0)
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
142 return retval;
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
143
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
144 if (r < 0 || r >= nr)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
145 {
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
146 (*current_liboctave_error_handler) ("range error for row_as_string");
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
147 return retval;
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
148 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
149
2613
5bcee07be597 [project @ 1997-01-21 03:52:08 by jwe]
jwe
parents: 2493
diff changeset
150 retval.resize (nc, '\0');
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
151
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
152 for (octave_idx_type i = 0; i < nc; i++)
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
153 retval[i] = elem (r, i);
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
154
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
155 if (strip_ws)
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents: 2384
diff changeset
156 {
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
157 while (--nc >= 0)
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
158 {
11265
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
159 char c = retval[nc];
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
160 if (c && c != ' ')
a117dc8ea1b9 charMatrix::row_as_string: never strip trailing nul characters
John W. Eaton <jwe@octave.org>
parents: 10521
diff changeset
161 break;
10314
07ebe522dac2 untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents: 10267
diff changeset
162 }
3836
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3769
diff changeset
163
b8c1cb5b9fd9 [project @ 2001-05-31 19:30:49 by jwe]
jwe
parents: 3769
diff changeset
164 retval.resize (nc+1);
2493
8ed4362aa0d6 [project @ 1996-11-11 02:35:04 by jwe]
jwe
parents: 2384
diff changeset
165 }
1780
6101360af703 [project @ 1996-01-24 07:55:06 by jwe]
jwe
parents: 1733
diff changeset
166
1573
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
167 return retval;
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
168 }
403c60daa8c7 [project @ 1995-10-19 04:34:20 by jwe]
jwe
parents:
diff changeset
169
2255
fb9611cfc9d2 [project @ 1996-05-22 19:31:32 by jwe]
jwe
parents: 1993
diff changeset
170 charMatrix
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
171 charMatrix::extract (octave_idx_type r1, octave_idx_type c1, octave_idx_type r2, octave_idx_type c2) const
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
172 {
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
173 if (r1 > r2) { octave_idx_type tmp = r1; r1 = r2; r2 = tmp; }
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
174 if (c1 > c2) { octave_idx_type tmp = c1; c1 = c2; c2 = tmp; }
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
175
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
176 octave_idx_type new_r = r2 - r1 + 1;
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
177 octave_idx_type new_c = c2 - c1 + 1;
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
178
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
179 charMatrix result (new_r, new_c);
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
180
5275
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
181 for (octave_idx_type j = 0; j < new_c; j++)
23b37da9fd5b [project @ 2005-04-08 16:07:35 by jwe]
jwe
parents: 5105
diff changeset
182 for (octave_idx_type i = 0; i < new_r; i++)
3189
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
183 result.elem (i, j) = elem (r1+i, c1+j);
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
184
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
185 return result;
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
186 }
bef7b73c0724 [project @ 1998-10-16 18:05:26 by jwe]
jwe
parents: 3136
diff changeset
187
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6456
diff changeset
188 charMatrix
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6456
diff changeset
189 charMatrix::diag (octave_idx_type k) const
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6456
diff changeset
190 {
10351
5150ceb4dbb4 base charMatrix and boolMatrix on Array<char>
Jaroslav Hajek <highegg@gmail.com>
parents: 10314
diff changeset
191 return Array<char>::diag (k);
6979
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6456
diff changeset
192 }
2883ea1c5c18 [project @ 2007-10-08 20:23:48 by dbateman]
dbateman
parents: 6456
diff changeset
193
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5307
diff changeset
194 // FIXME Do these really belong here? Maybe they should be
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3836
diff changeset
195 // in a base class?
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
196
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3836
diff changeset
197 boolMatrix
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3836
diff changeset
198 charMatrix::all (int dim) const
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
199 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10351
diff changeset
200 return do_mx_red_op<bool, char> (*this, dim, mx_inline_all);
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
201 }
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
202
4015
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3836
diff changeset
203 boolMatrix
6476dd85a65f [project @ 2002-08-02 07:59:19 by jwe]
jwe
parents: 3836
diff changeset
204 charMatrix::any (int dim) const
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
205 {
10362
b47ab50a6aa8 simplify appliers in mx-inlines.cc
Jaroslav Hajek <highegg@gmail.com>
parents: 10351
diff changeset
206 return do_mx_red_op<bool, char> (*this, dim, mx_inline_any);
3136
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
207 }
af7ec9d3a5e6 [project @ 1998-02-01 20:11:06 by jwe]
jwe
parents: 2847
diff changeset
208
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
209 MS_CMP_OPS (charMatrix, char)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
210 MS_BOOL_OPS (charMatrix, char)
6456
7f5316cadaa2 [project @ 2007-03-26 16:18:26 by jwe]
jwe
parents: 5775
diff changeset
211
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
212 SM_CMP_OPS (char, charMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
213 SM_BOOL_OPS (char, charMatrix)
6456
7f5316cadaa2 [project @ 2007-03-26 16:18:26 by jwe]
jwe
parents: 5775
diff changeset
214
9578
7dafdb8b062f refactor comparison ops implementations
Jaroslav Hajek <highegg@gmail.com>
parents: 9550
diff changeset
215 MM_CMP_OPS (charMatrix, charMatrix)
9550
3d6a9aea2aea refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents: 9370
diff changeset
216 MM_BOOL_OPS (charMatrix, charMatrix)