807
|
1 // strfns.cc -*- C++ -*- |
|
2 /* |
|
3 |
|
4 Copyright (C) 1992, 1993, 1994 John W. Eaton |
|
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 |
|
20 Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include "config.h" |
|
26 #endif |
|
27 |
|
28 #include <ctype.h> |
|
29 #include <string.h> |
|
30 |
|
31 #include "dMatrix.h" |
|
32 |
|
33 #include "tree-const.h" |
|
34 #include "oct-obj.h" |
|
35 #include "error.h" |
|
36 #include "gripes.h" |
|
37 #include "defun.h" |
|
38 #include "utils.h" |
|
39 #include "help.h" |
|
40 |
|
41 DEFUN ("isstr", Fisstr, Sisstr, 1, 1, |
|
42 "isstr (X): return 1 if X is a string, 0 otherwise") |
|
43 { |
|
44 Octave_object retval; |
|
45 |
|
46 int nargin = args.length (); |
|
47 |
|
48 if (nargin == 1 && args(0).is_defined ()) |
|
49 retval = (double) args(0).is_string (); |
|
50 else |
|
51 print_usage ("isstr"); |
|
52 |
|
53 return retval; |
|
54 } |
|
55 |
|
56 DEFUN ("setstr", Fsetstr, Ssetstr, 1, 1, |
|
57 "setstr (V): convert a vector to a string") |
|
58 { |
|
59 Octave_object retval; |
|
60 |
|
61 int nargin = args.length (); |
|
62 |
|
63 if (nargin == 1 && args(0).is_defined ()) |
|
64 retval = args(0).convert_to_str (); |
|
65 else |
|
66 print_usage ("setstr"); |
|
67 |
|
68 return retval; |
|
69 } |
|
70 |
|
71 DEFUN ("toascii", Ftoascii, Stoascii, 1, 1, |
|
72 "toascii (STRING): return ASCII representation of STRING in a matrix") |
|
73 { |
|
74 Octave_object retval; |
|
75 |
|
76 int nargin = args.length (); |
|
77 |
|
78 if (nargin == 1) |
|
79 { |
|
80 tree_constant arg = args(0).is_string (); |
|
81 |
|
82 if (arg.is_string ()) |
|
83 { |
|
84 char *str = args(0).string_value (); |
|
85 |
|
86 int len = strlen (str); |
|
87 |
|
88 Matrix m (1, len); |
|
89 |
|
90 for (int i = 0; i < len; i++) |
|
91 m (0, i) = toascii (str[i]); |
|
92 |
|
93 retval = m; |
|
94 } |
|
95 else |
|
96 gripe_wrong_type_arg ("toascii", arg); |
|
97 } |
|
98 else |
|
99 print_usage ("toascii"); |
|
100 |
|
101 return retval; |
|
102 } |
|
103 |
|
104 /* |
|
105 ;;; Local Variables: *** |
|
106 ;;; mode: C++ *** |
|
107 ;;; page-delimiter: "^/\\*" *** |
|
108 ;;; End: *** |
|
109 */ |