807
|
1 // strfns.cc -*- C++ -*- |
|
2 /* |
|
3 |
1009
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
807
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
807
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
1192
|
25 #include <config.h> |
807
|
26 #endif |
|
27 |
1355
|
28 #include <cctype> |
807
|
29 |
|
30 #include "dMatrix.h" |
|
31 |
1355
|
32 #include "defun.h" |
807
|
33 #include "error.h" |
|
34 #include "gripes.h" |
1355
|
35 #include "help.h" |
|
36 #include "oct-obj.h" |
|
37 #include "tree-const.h" |
807
|
38 #include "utils.h" |
|
39 |
|
40 DEFUN ("isstr", Fisstr, Sisstr, 1, 1, |
|
41 "isstr (X): return 1 if X is a string, 0 otherwise") |
|
42 { |
|
43 Octave_object retval; |
|
44 |
|
45 int nargin = args.length (); |
|
46 |
|
47 if (nargin == 1 && args(0).is_defined ()) |
|
48 retval = (double) args(0).is_string (); |
|
49 else |
|
50 print_usage ("isstr"); |
|
51 |
|
52 return retval; |
|
53 } |
|
54 |
|
55 DEFUN ("setstr", Fsetstr, Ssetstr, 1, 1, |
|
56 "setstr (V): convert a vector to a string") |
|
57 { |
|
58 Octave_object retval; |
|
59 |
|
60 int nargin = args.length (); |
|
61 |
|
62 if (nargin == 1 && args(0).is_defined ()) |
|
63 retval = args(0).convert_to_str (); |
|
64 else |
|
65 print_usage ("setstr"); |
|
66 |
|
67 return retval; |
|
68 } |
|
69 |
|
70 DEFUN ("toascii", Ftoascii, Stoascii, 1, 1, |
|
71 "toascii (STRING): return ASCII representation of STRING in a matrix") |
|
72 { |
|
73 Octave_object retval; |
|
74 |
|
75 int nargin = args.length (); |
|
76 |
|
77 if (nargin == 1) |
|
78 { |
808
|
79 tree_constant arg = args(0); |
807
|
80 |
|
81 if (arg.is_string ()) |
|
82 { |
1355
|
83 Octave_str_obj str = args(0).all_strings (); |
807
|
84 |
1355
|
85 int nr = str.num_strings (); |
|
86 int nc = str.max_length (); |
|
87 |
|
88 // XXX FIXME XXX -- should fill with user-specified value. |
807
|
89 |
1355
|
90 Matrix m (nr, nc, 0); |
807
|
91 |
1355
|
92 for (int i = 0; i < nr; i++) |
|
93 { |
|
94 nc = str.elem (i).length (); |
|
95 for (int j = 0; j < nc; j++) |
|
96 m (i, j) = toascii (str.elem (i) [j]); |
|
97 } |
807
|
98 |
|
99 retval = m; |
|
100 } |
|
101 else |
|
102 gripe_wrong_type_arg ("toascii", arg); |
|
103 } |
|
104 else |
|
105 print_usage ("toascii"); |
|
106 |
|
107 return retval; |
|
108 } |
|
109 |
|
110 /* |
|
111 ;;; Local Variables: *** |
|
112 ;;; mode: C++ *** |
|
113 ;;; page-delimiter: "^/\\*" *** |
|
114 ;;; End: *** |
|
115 */ |