summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorSamuel GOUGEON <sgougeon@free.fr>2021-05-04 20:12:07 +0200
committerClément David <clement.david@esi-group.com>2021-05-28 15:13:42 +0200
commit1214043db932e524bb440717ba963ac86126fa9a (patch)
tree8cb5cf25eb68ed31114bf31366ee535c7e11e632 /scilab/modules
parentdc59e40ebf08b54c0495422fa522e050eb3521f5 (diff)
downloadscilab-1214043db932e524bb440717ba963ac86126fa9a.zip
scilab-1214043db932e524bb440717ba963ac86126fa9a.tar.gz
* Bugs 16438 16685: asciimat(text) fixed + various lengths + UTF8
asciimat() proposed page (PDF): http://bugzilla.scilab.org/attachment.cgi?id=5266 http://bugzilla.scilab.org/16438 : Support to strings of distinct lengths added. Support to strings including UTF8 extended characters added. http://bugzilla.scilab.org/16685 : asciimat(['ab';'';'ab']) result was wrongly shaped. asciimat(['a';'';'b']) yielded an error. asciimat(stringHypermat) squeezed dim#2 of the result and so did not cope with Matlab/Octave's behavior. test_run string asciimat test_run string bug_14976 test_run statistics histc To keep track of its files changes, asciimat() will be moved in [m2sci] only later. In addition, an option could be implemented later, to make asciimat(text) fully working in an elementwise way (as first proposed @ https://codereview.scilab.org/21566 ) Change-Id: I3183fc3d05491066816034802e8f09645261d76e
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/core/macros/whos.sci2
-rw-r--r--scilab/modules/overloading/macros/%c_b_c.sci16
-rw-r--r--scilab/modules/overloading/macros/%c_b_s.sci14
-rw-r--r--scilab/modules/statistics/tests/unit_tests/histc.tst6
-rw-r--r--scilab/modules/string/help/en_US/asciimat.xml342
-rw-r--r--scilab/modules/string/help/fr_FR/asciimat.xml61
-rw-r--r--scilab/modules/string/help/ja_JP/asciimat.xml66
-rw-r--r--scilab/modules/string/help/ru_RU/asciimat.xml352
-rw-r--r--scilab/modules/string/macros/asciimat.sci97
-rw-r--r--scilab/modules/string/tests/nonreg_tests/bug_14976.tst10
-rw-r--r--scilab/modules/string/tests/unit_tests/asciimat.tst145
11 files changed, 829 insertions, 282 deletions
diff --git a/scilab/modules/core/macros/whos.sci b/scilab/modules/core/macros/whos.sci
index c2a182d..36cb5ff 100644
--- a/scilab/modules/core/macros/whos.sci
+++ b/scilab/modules/core/macros/whos.sci
@@ -21,7 +21,7 @@ function whos(%_opt,%_sel)
21 // Gathering locals + globals 21 // Gathering locals + globals
22 %_nams_all = [%_nams ; %_nams_global]; 22 %_nams_all = [%_nams ; %_nams_global];
23 %_vol_all = [%_vol ; %_vol_global]; 23 %_vol_all = [%_vol ; %_vol_global];
24 %_LG_all = [asciimat(76*ones(%_vol(:))) ; asciimat(71*ones(%_vol_global(:)))]; 24 %_LG_all = [emptystr(%_vol(:))+"L" ; emptystr(%_vol_global(:))+"G"];
25 25
26 // Sorting the whole set w/o.r.t. the case 26 // Sorting the whole set w/o.r.t. the case
27 [trash, k] = gsort(convstr(%_nams_all,"l"),"g","i"); 27 [trash, k] = gsort(convstr(%_nams_all,"l"),"g","i");
diff --git a/scilab/modules/overloading/macros/%c_b_c.sci b/scilab/modules/overloading/macros/%c_b_c.sci
index 89f5b92..f81c5a1 100644
--- a/scilab/modules/overloading/macros/%c_b_c.sci
+++ b/scilab/modules/overloading/macros/%c_b_c.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -10,17 +10,19 @@
10// For more information, see the COPYING file which you should have received 10// For more information, see the COPYING file which you should have received
11// along with this program. 11// along with this program.
12 12
13function r=%c_b_c(varargin) 13function r = %c_b_c(varargin)
14 if size(varargin)==2 then 14 if size(varargin)==2 then
15 if type(varargin(1))==10 & type(varargin(2))==10 then 15 if type(varargin(1))==10 & type(varargin(2))==10 then
16 r = asciimat(asciimat(varargin(1)):asciimat(varargin(2))) 16 s = ascii(varargin(1))
17 end 17 e = ascii(varargin(2))
18 elseif size(varargin)==3 then 18 if s>e, step = -1, else step = 1, end
19 if type(varargin(1))==10 & type(varargin(2))==10 & type(varargin(3))==10 then 19 r = ascii(s:step:e)
20 r = asciimat(asciimat(varargin(1)):asciimat(varargin(2)):asciimat(varargin(3)))
21 end 20 end
22 else 21 else
23 msg = _("%s: Non implemented feature.\n"); 22 msg = _("%s: Non implemented feature.\n");
24 error(msprintf(msg, "char:char")); 23 error(msprintf(msg, "char:char"));
25 end 24 end
26endfunction 25endfunction
26//assert_checkequal("a":"z", "abcdefghijklmnopqrstuvwxyz");
27//assert_checkequal("z":"a", "zyxwvutsrqponmlkjihgfedcba");
28
diff --git a/scilab/modules/overloading/macros/%c_b_s.sci b/scilab/modules/overloading/macros/%c_b_s.sci
index 10c54b0..2627bf0 100644
--- a/scilab/modules/overloading/macros/%c_b_s.sci
+++ b/scilab/modules/overloading/macros/%c_b_s.sci
@@ -1,7 +1,7 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) INRIA 2// Copyright (C) INRIA
3//
4// Copyright (C) 2012 - 2016 - Scilab Enterprises 3// Copyright (C) 2012 - 2016 - Scilab Enterprises
4// Copyright (C) 2021 - Samuel GOUGEON
5// 5//
6// This file is hereby licensed under the terms of the GNU GPL v2.0, 6// This file is hereby licensed under the terms of the GNU GPL v2.0,
7// pursuant to article 5.3.4 of the CeCILL v.2.1. 7// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,12 +11,16 @@
11// along with this program. 11// along with this program.
12 12
13function r = %c_b_s(varargin) 13function r = %c_b_s(varargin)
14 if size(varargin)==3 then 14 if size(varargin)==3 & type(varargin(3))==10 & ..
15 if type(varargin(1))==10 & type(varargin(2))==1 & type(varargin(3))==10 then 15 length(ascii(varargin(1)))==1 & length(ascii(varargin(3)))==1
16 r=asciimat(asciimat(varargin(1)):varargin(2):asciimat(varargin(3))) 16 r = ascii(ascii(varargin(1)):varargin(2):ascii(varargin(3)))
17 end
18 else 17 else
19 msg = _("%s: Non implemented feature.\n"); 18 msg = _("%s: Non implemented feature.\n");
20 error(msprintf(msg, "char:num")); 19 error(msprintf(msg, "char:num"));
21 end 20 end
22endfunction 21endfunction
22//assert_checkequal("a":2:"z", "acegikmoqsuwy");
23//assert_checkequal("z":-1:"a", "zyxwvutsrqponmlkjihgfedcba");
24//assert_checkequal("z":-2:"a", "zxvtrpnljhfdb");
25//assert_checkequal("a":-1:"z", "");
26//assert_checkequal("z":2:"a", "");
diff --git a/scilab/modules/statistics/tests/unit_tests/histc.tst b/scilab/modules/statistics/tests/unit_tests/histc.tst
index 1880096..57e6c7c 100644
--- a/scilab/modules/statistics/tests/unit_tests/histc.tst
+++ b/scilab/modules/statistics/tests/unit_tests/histc.tst
@@ -64,7 +64,8 @@ assert_checkequal(size(j),[1,5]);
64assert_checkequal(size(b),[1,5]); 64assert_checkequal(size(b),[1,5]);
65assert_checkequal(size(i),[2,9]); 65assert_checkequal(size(i),[2,9]);
66// Texts 66// Texts
67t = matrix(asciimat(grand(20,1,"uin",ascii("a"), ascii("z"))), 2, 10); 67t = grand(20,1,"uin",ascii("a"), ascii("z"));
68t = matrix(strsplit(ascii(t)), 2, 10);
68[h,j,b,i] = histc(t, ["e" "i" "o" "u"]); 69[h,j,b,i] = histc(t, ["e" "i" "o" "u"]);
69assert_checkequal(size(h),[1,3]); 70assert_checkequal(size(h),[1,3]);
70assert_checkequal(size(j),[1,3]); 71assert_checkequal(size(j),[1,3]);
@@ -386,7 +387,7 @@ t = [
386[h,j,b,i] = histc(t); 387[h,j,b,i] = histc(t);
387assert_checkequal(h, [3 3 2 3 1 5 1 7 6 4 2 4 2 4 8 5]); 388assert_checkequal(h, [3 3 2 3 1 5 1 7 6 4 2 4 2 4 8 5]);
388assert_checkequal(j, [0 0 0]); 389assert_checkequal(j, [0 0 0]);
389assert_checkequal(b, asciimat((97:112)')'); 390assert_checkequal(b, strsplit("a":"p")');
390iref = [ 391iref = [
3913 14 8 9 2 9 6 9 16 12 16 4 6 9 12 3923 14 8 9 2 9 6 9 16 12 16 4 6 9 12
3922 13 5 15 15 6 16 15 8 6 8 8 3 11 15 3932 13 5 15 15 6 16 15 8 6 8 8 3 11 15
@@ -440,6 +441,7 @@ jref = [37 0 7];
440assert_checkequal(h, href/N); 441assert_checkequal(h, href/N);
441assert_checkequal(j, jref/N); 442assert_checkequal(j, jref/N);
442[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: empty"); 443[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: empty");
444
443assert_checkequal(h, href/N); 445assert_checkequal(h, href/N);
444assert_checkequal(j, jref/N); 446assert_checkequal(j, jref/N);
445[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: out"); 447[h,j,b,i] = histc(t2, [bref ""], "discrete,countsNorm,normWith: out");
diff --git a/scilab/modules/string/help/en_US/asciimat.xml b/scilab/modules/string/help/en_US/asciimat.xml
index e598403..d69e33d 100644
--- a/scilab/modules/string/help/en_US/asciimat.xml
+++ b/scilab/modules/string/help/en_US/asciimat.xml
@@ -1,9 +1,9 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<!-- 2<!--
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT 4 * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2020 - 2021 - Samuel GOUGEON
7 * 7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,37 +11,44 @@
11 * and continues to be available under such terms. 11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received 12 * For more information, see the COPYING file which you should have received
13 * along with this program. 13 * along with this program.
14 * 14 *
15 --> 15-->
16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="asciimat"> 16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:db="http://docbook.org/ns/docbook"
18 xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="asciimat">
17 <refnamediv> 19 <refnamediv>
18 <refname>asciimat</refname> 20 <refname>asciimat</refname>
19 <refpurpose>string matrix ASCII conversions</refpurpose> 21 <refpurpose>
22 Converts an array of text into ASCII/UTF8 codes, and reciprocally
23 </refpurpose>
20 </refnamediv> 24 </refnamediv>
21 <refsynopsisdiv> 25 <refsynopsisdiv>
22 <title>Syntax</title> 26 <title>Syntax</title>
23 <synopsis> 27 <synopsis>
24 a = asciimat(txt) 28 unicodes = asciimat(text)
25 txt = asciimat(a) 29 text = asciimat(unicodes)
26 </synopsis> 30 </synopsis>
27 </refsynopsisdiv> 31 </refsynopsisdiv>
28 <refsection> 32 <refsection>
29 <title>Arguments</title> 33 <title>Arguments</title>
30 <variablelist> 34 <variablelist>
31 <varlistentry> 35 <varlistentry>
32 <term>txt</term> 36 <term>text</term>
33 <listitem> 37 <listitem>
34 <para> 38 single text, or vector, matrix or hypermatrix of texts.
35 a character string or matrix of strings. 39 Text elements may have various lengths, and may include UTF-8 extended characters.
36 </para> 40 <para/>
41 <literal>asciimat(…)</literal> always concatenates the columns of
42 <varname>text</varname> along rows, as input or output argument.
43 <para/>
37 </listitem> 44 </listitem>
38 </varlistentry> 45 </varlistentry>
39 <varlistentry> 46 <varlistentry>
40 <term>a</term> 47 <term>unicodes</term>
41 <listitem> 48 <listitem>
42 <para> 49 single integer ASCII code, or vector, matrix or hypermatrix of ASCII or unicode
43 a vector or matrix of integer ASCII codes. 50 1-byte numbers.
44 </para> 51 <para/>
45 </listitem> 52 </listitem>
46 </varlistentry> 53 </varlistentry>
47 </variablelist> 54 </variablelist>
@@ -49,18 +56,311 @@
49 <refsection> 56 <refsection>
50 <title>Description</title> 57 <title>Description</title>
51 <para> 58 <para>
52 This function converts Scilab string to ASCII code or a 59 <literal>asciimat(…)</literal> converts an array of <varname>text</varname>
53 matrix of ASCII code to Scilab string. Output is a matrix 60 into an array of related 1-byte ascii or UTF-8 <varname>unicodes</varname>,
54 having the same number of rows than input, what is not the 61 and reciprocally.
55 case with <function>ascii</function>. 62 </para>
63 <para>
64 <literal>asciimat(…)</literal> is an Octave/Matlab compatibility function,
65 aiming to provide in the m2sci
66 Matlab-to-Scilab code converter an equivalence for the addition and
67 subtraction between some character strings or with numbers. Thus,
68 <screen><![CDATA[
69>> ['ab' 'c' ; 'd' 'ef'] + 4
70ans =
71 101 102 103
72 104 105 106
73
74>> ['ab';'cd'] + ['ef';'gh']
75ans =
76 198 200
77 202 204
78
79>> ['ab';'cd'] - ['ef';'gh']
80ans =
81 -4 -4
82 -4 -4
83]]></screen>
84 </para>
85 <para>
86 can be performed by the Matlab-to-Scilab converter with
87 </para>
88 <para>
89 <programlisting role="example"><![CDATA[
90asciimat(['ab' 'c' ; 'd' 'ef']) + 4
91asciimat(['ab';'cd']) + asciimat(['ef';'gh'])
92asciimat(['ab';'cd']) - asciimat(['ef';'gh'])
93 ]]></programlisting>
94 </para>
95 <para>
96 <warning>
97 <literal>asciimat(…)</literal> should not be used out of the M2Sci converter.
98 </warning>
99 </para>
100 <refsect3>
101 <title>unicodes = asciimat(text)</title>
102 <para>
103 <emphasis role="bold">For a scalar or row</emphasis> <varname>text</varname>,
104 <literal>asciimat(text)</literal> is equal to <literal>ascii(text)</literal>.
105 All strings are glued together before building the row vector of codes of their
106 characters.
107 </para>
108 <para>
109 <warning>
110 <emphasis role="bold">For any <varname>text</varname> array of any sizes,
111 made only of empty strings ""</emphasis>, <literal>asciimat(text)</literal>
112 returns []. Indeed, <literal>asciimat(…)</literal> considers "" as a void vector
113 of (indexed) characters as in Octave/Matlab, not as a Scilab text object.
114 </warning>
115 </para>
116 <para>
117 <emphasis role="bold">For a 2D matrix</emphasis> <varname>text</varname>,
118 <literal>asciimat(text)</literal> builds a unique column of text by gluing
119 <varname>text</varname> columns along rows.
120 </para>
121 <para>
122 Then, for each row/string of the column, the row vector of ASCII or
123 UTF-8 codes of all its characters is computed.
124 </para>
125 <para>
126 Finally, all resulting row vectors of codes are vertically concatenated to
127 build the <varname>unicodes</varname> matrix. Too short vectors of codes
128 are beforehand padded with the ascii(" ")==32 code.
129 </para>
130 <para>
131 <emphasis role="bold">For an hypermatrix</emphasis> of <varname>text</varname>,
132 the processing is basically the same, as if all <varname>text</varname>
133 rows over all dimensions > 2 were beforehand stacked into a 2D matrix.
134 The resulting 2D <varname>unicodes</varname> matrix is finally reshaped into
135 an hypermatrix..
136 </para>
137 <para>
138 The sizes of <varname>unicodes</varname> and <varname>text</varname> arrays
139 differ only by their number of columns.
140 </para>
141 </refsect3>
142 <refsect3>
143 <title>text = asciimat(unicodes)</title>
144 <para>
145 <emphasis role="bold">For a scalar or a row </emphasis> <varname>unicodes</varname>,
146 <literal>asciimat(unicodes)</literal> is equal to <literal>ascii(unicodes)</literal>.
147 It returns the character string whose characters have the given codes.
148 <warning>
149 Zeros stand for the code of the empty character "", as the true
150 ascii(0) character is currently not supported in Scilab 6.
151 </warning>
152 </para>
153 <para>
154 <emphasis role="bold">For a column, matrix or hypermatrix</emphasis>
155 <varname>unicodes</varname>, each <varname>unicodes</varname> row is
156 processed separately and builds a single Scilab character string.
157 </para>
158 <para>
159 All trailing ascii(32) spaces of built character strings are trimmed.
160 </para>
161 <para>
162 Finally, <varname>text</varname> has the size of <varname>unicodes</varname>,
163 except that <literal>size(text,2)==1</literal>.
164 </para>
165 </refsect3>
166 </refsection>
167 <refsection>
168 <title>Examples</title>
169 <programlisting role="example"><![CDATA[
170asciimat([])
171asciimat("")
172asciimat(0)
173
174r = asciimat("A")
175asciimat(r)
176
177// With an input ROW:
178r = asciimat(["A" "BC"])
179asciimat(r)
180
181r = asciimat(["A" "" "BC"]) // "" in rows are ignored
182asciimat(r)
183 ]]></programlisting>
184 <screen><![CDATA[
185--> asciimat([])
186 ans =
187 []
188--> asciimat("")
189 ans =
190 []
191--> asciimat(0)
192 ans =
193 ""
194
195--> r = asciimat("A")
196 r =
197 65.
198--> asciimat(r)
199 ans =
200 "A"
201
202--> // With an input ROW:
203--> r = asciimat(["A" "BC"])
204 r =
205 65. 66. 67.
206
207--> asciimat(r)
208 ans =
209 "ABC"
210
211--> r = asciimat(["A" "" "BC"]) // "" in rows are ignored
212 r =
213 65. 66. 67.
214
215--> asciimat(r)
216 ans =
217 "ABC"
218]]></screen>
219 <para>
220 With an input column:
221 </para>
222 <programlisting role="example"><![CDATA[
223asciimat(["" ; ""])
224asciimat((97:110)')'
225strsplit("a":"n")'
226
227r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
228asciimat(r)
229r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
230asciimat(r) // Trailing ascii(32) spaces are trimmed
231 ]]></programlisting>
232 <screen><![CDATA[
233--> asciimat(["" ; ""])
234 ans =
235 []
236
237--> asciimat((97:110)')'
238 ans =
239 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
240
241--> strsplit("a":"n")'
242 ans =
243 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
244
245--> r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
246 r =
247 65. 66. 67.
248 32. 32. 32.
249 68. 32. 32.
250
251--> asciimat(r)
252 ans =
253 "ABC"
254 ""
255 "D"
256
257--> r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
258 r =
259 65. 66. 32. 32.
260 206. 177. 206. 178.
261
262--> asciimat(r) // Trailing ascii(32) spaces are trimmed
263 ans =
264 "AB"
265 "αβ"
266]]></screen>
267 <para>
268 With a 2D input matrix:
56 </para> 269 </para>
270 <programlisting role="example"><![CDATA[
271r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
272asciimat(r)
273 ]]></programlisting>
274 <screen><![CDATA[
275--> r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
276 r =
277 32. 65. 66. 32. 67. 68. 32.
278 206. 177. 206. 178. 206. 179. 32.
279
280--> asciimat(r)
281 ans =
282 " AB CD"
283 "αβγ"
284]]></screen>
285 <para>
286 With a 3D input hypermatrix:
287 </para>
288 <programlisting role="example"><![CDATA[
289x = ["a €" "bδ " ; "" "" ; "" "" ];
290x2 = [" α" "βδc" ; "" "" ; "ε4" ""];
291h = cat(3, x, x2)
292r = asciimat(h)
293asciimat(r)
294 ]]></programlisting>
295 <screen><![CDATA[
296--> h = cat(3, x, x2)
297 h =
298(:,:,1)
299 "a €" "bδ "
300 "" ""
301 "" ""
302(:,:,2)
303 " α" "βδc"
304 "" ""
305 "ε4" ""
306
307--> r = asciimat(h)
308 r =
309(:,:,1)
310 97. 32. 226. 130. 172. 98. 206. 180. 32.
311 32. 32. 32. 32. 32. 32. 32. 32. 32.
312 32. 32. 32. 32. 32. 32. 32. 32. 32.
313(:,:,2)
314 32. 206. 177. 206. 178. 206. 180. 99. 32.
315 32. 32. 32. 32. 32. 32. 32. 32. 32.
316 206. 181. 52. 32. 32. 32. 32. 32. 32.
317
318--> asciimat(r)
319 ans =
320(:,:,1)
321 "a €bδ"
322 ""
323 ""
324(:,:,2)
325 " αβδc"
326 ""
327 "ε4"
328]]></screen>
57 </refsection> 329 </refsection>
330
58 <refsection role="see also"> 331 <refsection role="see also">
59 <title>See also</title> 332 <title>See also</title>
60 <simplelist type="inline"> 333 <simplelist type="inline">
61 <member> 334 <member>
62 <link linkend="ascii">ascii</link> 335 <link linkend="ascii">ascii</link>
63 </member> 336 </member>
337 <member>
338 <link linkend="char">char</link>
339 </member>
64 </simplelist> 340 </simplelist>
65 </refsection> 341 </refsection>
342
343 <refsection role="history">
344 <title>History</title>
345 <revhistory>
346 <revision>
347 <revnumber>6.1.1</revnumber>
348 <revdescription>
349 <itemizedlist>
350 <listitem>
351 Text components with various lengths or/and including UTF-8 characters
352 are accepted. Padding with the ascii(" ")==32 code implemented.
353 </listitem>
354 <listitem>
355 asciimat(unicodes) trims all trailing spaces.
356 </listitem>
357 <listitem>
358 For any unicodes hypermatrix, r = asciimat(unicodes) no longer squeezes
359 size(r,2).
360 </listitem>
361 </itemizedlist>
362 </revdescription>
363 </revision>
364 </revhistory>
365 </refsection>
66</refentry> 366</refentry>
diff --git a/scilab/modules/string/help/fr_FR/asciimat.xml b/scilab/modules/string/help/fr_FR/asciimat.xml
deleted file mode 100644
index 39a7707..0000000
--- a/scilab/modules/string/help/fr_FR/asciimat.xml
+++ /dev/null
@@ -1,61 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2002-2004 - INRIA - Vincent COUVERT
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
14 *
15 -->
16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="asciimat">
17 <refnamediv>
18 <refname>asciimat</refname>
19 <refpurpose>conversion d'une matrice de chaînes ASCII</refpurpose>
20 </refnamediv>
21 <refsynopsisdiv>
22 <title>Séquence d'appel</title>
23 <synopsis>
24 a = asciimat(txt)
25 txt = asciimat(a)
26 </synopsis>
27 </refsynopsisdiv>
28 <refsection>
29 <title>Paramètres</title>
30 <variablelist>
31 <varlistentry>
32 <term>txt</term>
33 <listitem>
34 <para>chaîne de caractères ou matrice de chaînes</para>
35 </listitem>
36 </varlistentry>
37 <varlistentry>
38 <term>a</term>
39 <listitem>
40 <para>vecteur ou matrice de codes ASCII</para>
41 </listitem>
42 </varlistentry>
43 </variablelist>
44 </refsection>
45 <refsection>
46 <title>Description</title>
47 <para>
48 Cette fonction convertit une chaîne de caractères Scilab en codes ASCII ou une matrice de codes ASCII en chaîne de caractères Scilab.
49 La valeur retournée est une matrice ayant le même nombre de lignes que l'entrée,
50 ce qui n'est pas le cas de la fonction <function>ascii</function>.
51 </para>
52 </refsection>
53 <refsection role="see also">
54 <title>Voir aussi</title>
55 <simplelist type="inline">
56 <member>
57 <link linkend="ascii">ascii</link>
58 </member>
59 </simplelist>
60 </refsection>
61</refentry>
diff --git a/scilab/modules/string/help/ja_JP/asciimat.xml b/scilab/modules/string/help/ja_JP/asciimat.xml
deleted file mode 100644
index 6e5794d..0000000
--- a/scilab/modules/string/help/ja_JP/asciimat.xml
+++ /dev/null
@@ -1,66 +0,0 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<!--
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
14 *
15 -->
16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ja" xml:id="asciimat">
17 <refnamediv>
18 <refname>asciimat</refname>
19 <refpurpose>文字列行列アスキー変換</refpurpose>
20 </refnamediv>
21 <refsynopsisdiv>
22 <title>呼び出し手順</title>
23 <synopsis>
24 a = asciimat(txt)
25 txt = asciimat(a)
26 </synopsis>
27 </refsynopsisdiv>
28 <refsection>
29 <title>引数</title>
30 <variablelist>
31 <varlistentry>
32 <term>txt</term>
33 <listitem>
34 <para>
35 文字列または文字列の行列.
36 </para>
37 </listitem>
38 </varlistentry>
39 <varlistentry>
40 <term>a</term>
41 <listitem>
42 <para>
43 整数アスキーコードのベクトルまたは行列.
44 </para>
45 </listitem>
46 </varlistentry>
47 </variablelist>
48 </refsection>
49 <refsection>
50 <title>説明</title>
51 <para>
52 この関数は,Scilab文字列をアスキーコードに変換または
53 アスキーコードの行列をScilab文字列に変換します.
54 出力は,<function>ascii</function>の場合と異なり,
55 入力と同じ行数を有する行列です.
56 </para>
57 </refsection>
58 <refsection role="see also">
59 <title>参照</title>
60 <simplelist type="inline">
61 <member>
62 <link linkend="ascii">ascii</link>
63 </member>
64 </simplelist>
65 </refsection>
66</refentry>
diff --git a/scilab/modules/string/help/ru_RU/asciimat.xml b/scilab/modules/string/help/ru_RU/asciimat.xml
index ad3a886..19d8651 100644
--- a/scilab/modules/string/help/ru_RU/asciimat.xml
+++ b/scilab/modules/string/help/ru_RU/asciimat.xml
@@ -1,9 +1,9 @@
1<?xml version="1.0" encoding="UTF-8"?> 1<?xml version="1.0" encoding="UTF-8"?>
2<!-- 2<!--
3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 3 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT 4 * Copyright (C) 2004-2007 - INRIA - Vincent COUVERT
5 *
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises 5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2020 - 2021 - Samuel GOUGEON
7 * 7 *
8 * This file is hereby licensed under the terms of the GNU GPL v2.0, 8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1. 9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -11,37 +11,45 @@
11 * and continues to be available under such terms. 11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received 12 * For more information, see the COPYING file which you should have received
13 * along with this program. 13 * along with this program.
14 * 14 *
15 --> 15-->
16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:lang="ru" xml:id="asciimat"> 16<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17 xmlns:svg="http://www.w3.org/2000/svg" xmlns:db="http://docbook.org/ns/docbook"
18 xmlns:scilab="http://www.scilab.org" xml:lang="ru" xml:id="asciimat">
17 <refnamediv> 19 <refnamediv>
18 <refname>asciimat</refname> 20 <refname>asciimat</refname>
19 <refpurpose>преобразование матрицы строк в ASCII-коды и обратно</refpurpose> 21 <refpurpose>
22 Преобразует массив текста в коды ASCII/UTF8 и обратно
23 </refpurpose>
20 </refnamediv> 24 </refnamediv>
21 <refsynopsisdiv> 25 <refsynopsisdiv>
22 <title>Синтаксис</title> 26 <title>Синтаксис</title>
23 <synopsis> 27 <synopsis>
24 a = asciimat(txt) 28 unicodes = asciimat(text)
25 txt = asciimat(a) 29 text = asciimat(unicodes)
26 </synopsis> 30 </synopsis>
27 </refsynopsisdiv> 31 </refsynopsisdiv>
28 <refsection> 32 <refsection>
29 <title>Аргументы</title> 33 <title>Аргументы</title>
30 <variablelist> 34 <variablelist>
31 <varlistentry> 35 <varlistentry>
32 <term>txt</term> 36 <term>text</term>
33 <listitem> 37 <listitem>
34 <para> 38 отдельный текст, или вектор, матрица или гиперматрица текстов.
35 символьная строка или матрица строк. 39 Элементы текста могут иметь разную длину и могут включать в
36 </para> 40 себя расширенные символы UTF-8.
41 <para/>
42 <literal>asciimat(…)</literal> всегда конкатенирует столбцы текста
43 <varname>text</varname> вдоль строк, как входной или выходной аргумент.
44 <para/>
37 </listitem> 45 </listitem>
38 </varlistentry> 46 </varlistentry>
39 <varlistentry> 47 <varlistentry>
40 <term>a</term> 48 <term>unicodes</term>
41 <listitem> 49 <listitem>
42 <para> 50 отдельный целочисленный ASCII-код, вектор, матрица или гиперматрица
43 т или марица елоисных ASCII-кодв. 51 1-т чисе ASCII ли юниод.
44 </para> 52 <para/>
45 </listitem> 53 </listitem>
46 </varlistentry> 54 </varlistentry>
47 </variablelist> 55 </variablelist>
@@ -49,19 +57,319 @@
49 <refsection> 57 <refsection>
50 <title>Описание</title> 58 <title>Описание</title>
51 <para> 59 <para>
52 Эта функция преобразует Scilab-строку в ASCII-код или 60 <literal>asciimat(…)</literal> преобразует массив текста <varname>text</varname>
53 матрицу ASCII-кодов в Scilab-строку. Аргумент на выходе 61 в массив соответствующих 1-байтных кодов ascii или UTF-8 <varname>unicodes</varname>,
54 является матрицей, у которой то же количество строк, что и у 62 и наоборот.
55 матрицы на входе, что является отличием от функции 63 </para>
56 <function>ascii</function>. 64 <para>
65 <literal>asciimat(…)</literal> является функцией совместимости с Octave/Matlab,
66 с целью обеспечить в преобразователе кода Matlab-в-Scilab m2sci
67 эквивалентность для суммирования и вычитания некоторых
68 строковых символов или с числами. Таким образом,
69 <screen><![CDATA[
70>> ['ab' 'c' ; 'd' 'ef'] + 4
71ans =
72 101 102 103
73 104 105 106
74
75>> ['ab';'cd'] + ['ef';'gh']
76ans =
77 198 200
78 202 204
79
80>> ['ab';'cd'] - ['ef';'gh']
81ans =
82 -4 -4
83 -4 -4
84]]></screen>
85 </para>
86 <para>
87 может быть преобразовано преобразователем Matlab-в-Scilab с
88 </para>
89 <para>
90 <programlisting role="example"><![CDATA[
91asciimat(['ab' 'c' ; 'd' 'ef']) + 4
92asciimat(['ab';'cd']) + asciimat(['ef';'gh'])
93asciimat(['ab';'cd']) - asciimat(['ef';'gh'])
94 ]]></programlisting>
95 </para>
96 <para>
97 <warning>
98 <literal>asciimat(…)</literal> не следует использовать без преобразователя.
99 </warning>
100 </para>
101 <refsect3>
102 <title>unicodes = asciimat(text)</title>
103 <para>
104 <emphasis role="bold">Для скаляра или строки</emphasis> <varname>text</varname>,
105 <literal>asciimat(text)</literal> эквивалентно <literal>ascii(text)</literal>.
106 Все строчки склеиваются друг с другом перед построением вектора-строки
107 кодов их символов.
108 </para>
109 <para>
110 <warning>
111 <emphasis role="bold">Для любого массива <varname>text</varname> любых
112 размеров, сделанных только из пустых строк <literal>""</literal></emphasis>,
113 <literal>asciimat(text)</literal> возвращает <literal>[]</literal>.
114 Действительно, <literal>asciimat(…)</literal> считает <literal>""</literal>
115 как пустой вектор (индексированных) символов как в Octave/Matlab, а не
116 как текстовый объект Scilab.
117 </warning>
118 </para>
119 <para>
120 <emphasis role="bold">Для двумерных матриц</emphasis> <varname>text</varname>,
121 <literal>asciimat(text)</literal> строит уникальный столбец текста,
122 склеивая столбцы <varname>text</varname> вдоль строк.
123 </para>
124 <para>
125 Затем для каждой строки/строчки столбца вычисляется вектор-строка
126 кодов ASCII или UTF-8 всех её символов.
127 </para>
128 <para>
129 Наконец, все результирующие вектор-строки кодов конкатенируются
130 по вертикали для построения матрицы <varname>unicodes</varname>.
131 Слишком короткие векторы кодов предварительно дополняются кодом
132 ascii(" ")==32.
133 </para>
134 <para>
135 <emphasis role="bold">Для гиперматрицы</emphasis> <varname>text</varname>,
136 обработка, в основном, та же самая, как если бы все строки
137 <varname>text</varname> по всем размерностям больше двух были предварительно
138 составлены в двумерную матрицу. Результирующая двумерная матрица
139 <varname>unicodes</varname>, наконец, преобразуется в гиперматрицу.
140 </para>
141 <para>
142 Размеры массивов <varname>unicodes</varname> и <varname>text</varname>
143 отличаются только по количеству их столбцов.
144 </para>
145 </refsect3>
146 <refsect3>
147 <title>text = asciimat(unicodes)</title>
148 <para>
149 <emphasis role="bold">Для скаляра или строки</emphasis>
150 <varname>unicodes</varname>,
151 <literal>asciimat(unicodes)</literal> эквивалентна
152 <literal>ascii(unicodes)</literal>.
153 Она возвращает символьные строки, чьи символы имеют указанные коды.
154 <warning>
155 Нули стоят для кода пустого символа <literal>""</literal>, поскольку
156 настоящий символ <literal>ascii(0)</literal> пока что не поддерживается
157 в Scilab 6.
158 </warning>
159 </para>
160 <para>
161 <emphasis role="bold">Для столбца, матрицы или гиперматрицы</emphasis>
162 <varname>unicodes</varname>, каждая строка <varname>unicodes</varname>
163 обрабатывается отдельно и строит отдельную символьную строку Scilab.
164 </para>
165 <para>
166 Все завершающие пробелы <literal>ascii(32)</literal> построенных
167 символьных строк отсекаются.
168 </para>
169 <para>
170 Наконец, <varname>text</varname> имеет размер <varname>unicodes</varname>,
171 за исключением <literal>size(text,2)==1</literal>.
172 </para>
173 </refsect3>
174 </refsection>
175 <refsection>
176 <title>Примеры</title>
177 <programlisting role="example"><![CDATA[
178asciimat([])
179asciimat("")
180asciimat(0)
181
182r = asciimat("A")
183asciimat(r)
184
185// Со СТРОКОЙ на входе:
186r = asciimat(["A" "BC"])
187asciimat(r)
188
189r = asciimat(["A" "" "BC"]) // "" в строках игнорируются
190asciimat(r)
191 ]]></programlisting>
192 <screen><![CDATA[
193--> asciimat([])
194 ans =
195 []
196--> asciimat("")
197 ans =
198 []
199--> asciimat(0)
200 ans =
201 ""
202
203--> r = asciimat("A")
204 r =
205 65.
206--> asciimat(r)
207 ans =
208 "A"
209
210--> // With an input ROW:
211--> r = asciimat(["A" "BC"])
212 r =
213 65. 66. 67.
214
215--> asciimat(r)
216 ans =
217 "ABC"
218
219--> r = asciimat(["A" "" "BC"]) // "" in rows are ignored
220 r =
221 65. 66. 67.
222
223--> asciimat(r)
224 ans =
225 "ABC"
226]]></screen>
227 <para>
228 Со столбцом на входе:
229 </para>
230 <programlisting role="example"><![CDATA[
231asciimat(["" ; ""])
232asciimat((97:110)')'
233strsplit("a":"n")'
234
235r = asciimat(["ABC" ; "" ; "D"]) // Дополнение коротких строк с помощью 32
236asciimat(r)
237r = asciimat(["AB" ; "αβ"]) // используется 1-байтный код UTF-8
238asciimat(r) // завершающие пробелы ascii(32) отсекаются
239 ]]></programlisting>
240 <screen><![CDATA[
241--> asciimat(["" ; ""])
242 ans =
243 []
244
245--> asciimat((97:110)')'
246 ans =
247 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
248
249--> strsplit("a":"n")'
250 ans =
251 "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n"
252
253--> r = asciimat(["ABC" ; "" ; "D"]) // Padding short rows with 32
254 r =
255 65. 66. 67.
256 32. 32. 32.
257 68. 32. 32.
258
259--> asciimat(r)
260 ans =
261 "ABC"
262 ""
263 "D"
264
265--> r = asciimat(["AB" ; "αβ"]) // 1-byte UTF-8 coding is used
266 r =
267 65. 66. 32. 32.
268 206. 177. 206. 178.
269
270--> asciimat(r) // Trailing ascii(32) spaces are trimmed
271 ans =
272 "AB"
273 "αβ"
274]]></screen>
275 <para>
276 С двумерной матрицей на входе:
57 </para> 277 </para>
278 <programlisting role="example"><![CDATA[
279r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
280asciimat(r)
281 ]]></programlisting>
282 <screen><![CDATA[
283--> r = asciimat([" AB", " ", "CD " ; "α", "βγ", " "])
284 r =
285 32. 65. 66. 32. 67. 68. 32.
286 206. 177. 206. 178. 206. 179. 32.
287
288--> asciimat(r)
289 ans =
290 " AB CD"
291 "αβγ"
292]]></screen>
293 <para>
294 С трёхмерной гиперматрицей на входе:
295 </para>
296 <programlisting role="example"><![CDATA[
297x = ["a €" "bδ " ; "" "" ; "" "" ];
298x2 = [" α" "βδc" ; "" "" ; "ε4" ""];
299h = cat(3, x, x2)
300r = asciimat(h)
301asciimat(r)
302 ]]></programlisting>
303 <screen><![CDATA[
304--> h = cat(3, x, x2)
305 h =
306(:,:,1)
307 "a €" "bδ "
308 "" ""
309 "" ""
310(:,:,2)
311 " α" "βδc"
312 "" ""
313 "ε4" ""
314
315--> r = asciimat(h)
316 r =
317(:,:,1)
318 97. 32. 226. 130. 172. 98. 206. 180. 32.
319 32. 32. 32. 32. 32. 32. 32. 32. 32.
320 32. 32. 32. 32. 32. 32. 32. 32. 32.
321(:,:,2)
322 32. 206. 177. 206. 178. 206. 180. 99. 32.
323 32. 32. 32. 32. 32. 32. 32. 32. 32.
324 206. 181. 52. 32. 32. 32. 32. 32. 32.
325
326--> asciimat(r)
327 ans =
328(:,:,1)
329 "a €bδ"
330 ""
331 ""
332(:,:,2)
333 " αβδc"
334 ""
335 "ε4"
336]]></screen>
58 </refsection> 337 </refsection>
338
59 <refsection role="see also"> 339 <refsection role="see also">
60 <title>Смотрите также</title> 340 <title>Смотрите также</title>
61 <simplelist type="inline"> 341 <simplelist type="inline">
62 <member> 342 <member>
63 <link linkend="ascii">ascii</link> 343 <link linkend="ascii">ascii</link>
64 </member> 344 </member>
345 <member>
346 <link linkend="char">char</link>
347 </member>
65 </simplelist> 348 </simplelist>
66 </refsection> 349 </refsection>
350
351 <refsection role="history">
352 <title>История</title>
353 <revhistory>
354 <revision>
355 <revnumber>6.1.1</revnumber>
356 <revdescription>
357 <itemizedlist>
358 <listitem>
359 Принимаются текстовые компоненты различной длины или/и
360 включая символы UTF-8. Реализовано дополнение кодами
361 ascii(" ")==32.
362 </listitem>
363 <listitem>
364 asciimat(unicodes) отсекает все завершающие пробелы.
365 </listitem>
366 <listitem>
367 Для любых гиперматрицы unicodes, r = asciimat(unicodes)
368 больше не сжимает size(r,2).
369 </listitem>
370 </itemizedlist>
371 </revdescription>
372 </revision>
373 </revhistory>
374 </refsection>
67</refentry> 375</refentry>
diff --git a/scilab/modules/string/macros/asciimat.sci b/scilab/modules/string/macros/asciimat.sci
index 3ac4b9a..f59eed5 100644
--- a/scilab/modules/string/macros/asciimat.sci
+++ b/scilab/modules/string/macros/asciimat.sci
@@ -1,9 +1,8 @@
1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 1// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2// Copyright (C) ???? - INRIA - Scilab 2// Copyright (C) ???? - INRIA - Scilab
3// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre 3// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
4// Copyright (C) 2017 - Samuel GOUGEON
5//
6// Copyright (C) 2012 - 2016 - Scilab Enterprises 4// Copyright (C) 2012 - 2016 - Scilab Enterprises
5// Copyright (C) 2017 - 2021 - Samuel GOUGEON
7// 6//
8// This file is hereby licensed under the terms of the GNU GPL v2.0, 7// This file is hereby licensed under the terms of the GNU GPL v2.0,
9// pursuant to article 5.3.4 of the CeCILL v.2.1. 8// pursuant to article 5.3.4 of the CeCILL v.2.1.
@@ -19,60 +18,66 @@ function y = asciimat(x)
19 // Returned value have same size as input value instead of second dims ! 18 // Returned value have same size as input value instead of second dims !
20 // Fonction created because ascii() Scilab function returns a row vector 19 // Fonction created because ascii() Scilab function returns a row vector
21 20
21 y = []
22 if x==[] then 22 if x==[] then
23 y=[]
24 return 23 return
25 end 24 end
26 25
27 dims = size(x);
28 if typeof(x) == "string" // convert string to ascii code 26 if typeof(x) == "string" // convert string to ascii code
29 if size(dims,"*") > 2 // hypermatrix case 27 dims = size(x)
30 colref = 0; 28 x = strcat(matrix(permute(x,[2 1 3:length(dims)]), dims(2), -1),"","r")'
31 lastDim = dims($); 29 tmp = ascii(1:127);
32 dims($) = []; 30 for c = ["\" "/" "]"]
33 l=list(); 31 tmp = strsubst(tmp, c, "\"+c);
34 for i=1:size(dims,"*") 32 end
35 l(i) = 1:$; 33 kUTF = grep(x, "/[^" + tmp + "]/", "regexp")
34 if kUTF == [] then
35 L = length(x)
36 m = max(L)
37 if or(length(x)<>m) then
38 // Padding with spaces (like Octave, unlike Matlab)
39 x = part(x(:),1:m)
40 end
41 y = matrix(ascii(x)', [length(x(1)), dims(1), dims(3:$)])
42 y = permute(y, [2 1 3:length(dims)])
43 else
44 ext = []
45 for k = kUTF
46 a = ascii(x(k));
47 ext($+1,1:length(a)) = a;
36 end 48 end
37 for i=1:lastDim 49 ext(ext==0) = 32; // Padding with spaces
38 res=asciimat(x(l(:), i)); 50
39 if colref == 0 then 51 noUTF = x(:)
40 colref=size(res,"c"); 52 noUTF(kUTF) = ""
41 else 53 m = max(size(ext,2), max(length(noUTF)))
42 if colref <> size(res,"c") 54 noUTF = part(noUTF, 1:m)
43 msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n") 55 y = matrix(ascii(noUTF),m,-1)'
44 error(msprintf(msg, "asciimat", 1)); 56 if size(ext,2)<m
45 return 57 ext(1,m) = 32 // extends a to m columns
46 end
47 end
48 y(l(:), i) = res;
49 end 58 end
50 else // 2D matrix case | ["a" "bc";"de" "f"] => [97 98 99;100 101 102] 59 for i = 1:length(kUTF)
51 x=x'; 60 y(kUTF(i),:) = ext(i,:) ;
52 a = ascii(x(:));
53 aSize = size(a, "*");
54 dims(2) = 1;
55 p = prod(dims);
56 if modulo(aSize, p)
57 msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n")
58 error(msprintf(msg, "asciimat", 1));
59 end 61 end
60 dims(2) = dims(1); 62 y = permute(matrix(y',[m dims(1) dims(3:$)]), [2 1 3:length(dims)])
61 dims(1) = aSize/p;
62 y = matrix(a, dims)';
63 end 63 end
64
64 else // convert ascii codes to string 65 else // convert ascii codes to string
65 x = permute(x,[2 1 3:ndims(x)]); 66 dims = size(x)
66 y = ascii(x); 67 x = permute(x, [2 1 3:ndims(x)]);
67 Ly = length(y) 68 x = matrix(x,size(x,1),-1);
68 rlength = Ly / (prod(dims)/dims(2)) 69 // Tags the EOL:
69 if dims(1)>1 70 for c = ascii("$€£")
70 if modulo(Ly, rlength) 71 x($+1,:) = c;
71 msg = gettext("%s: Wrong input argument #%d: Inconsistent size.\n")
72 error(msprintf(msg,"asciimat", 1))
73 end
74 y = strsplit(y, rlength:rlength:(Ly-1));
75 end 72 end
76 y = matrix(y, [dims(1) dims(3:$)]); 73 //
74 x = matrix(x,1,-1)
75 // Any zero will block ascii(): http://bugzilla.scilab.org/15101
76 x(x==0) = [] // 0 <=> ""
77 x = [x, 65] // works around http://bugzilla.scilab.org/16686
78 y = strsplit(ascii(x), "$€£");
79 y($) = [] // removes the ending ascii(65)
80 y = matrix(y, [dims(1) 1 dims(3:$)]); // dims#2 not squeezed (Matlab, Octave)
81 y = stripblanks(y,%f,1) // Matlab & Octave trim trailing ascii(32)(not \t)
77 end 82 end
78endfunction 83endfunction
diff --git a/scilab/modules/string/tests/nonreg_tests/bug_14976.tst b/scilab/modules/string/tests/nonreg_tests/bug_14976.tst
index b86fb63..f311d7f 100644
--- a/scilab/modules/string/tests/nonreg_tests/bug_14976.tst
+++ b/scilab/modules/string/tests/nonreg_tests/bug_14976.tst
@@ -1,6 +1,6 @@
1// ============================================================================= 1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2017 - Samuel GOUGEON 3// Copyright (C) 2017-2021 - Samuel GOUGEON
4// 4//
5// This file is distributed under the same license as the Scilab package. 5// This file is distributed under the same license as the Scilab package.
6// ============================================================================= 6// =============================================================================
@@ -18,10 +18,10 @@
18 18
19assert_checkequal(asciimat(97:122), "abcdefghijklmnopqrstuvwxyz"); 19assert_checkequal(asciimat(97:122), "abcdefghijklmnopqrstuvwxyz");
20c = (97:122)'; 20c = (97:122)';
21r = strsplit("a":"z",1:25); 21C = strsplit("a":"z",1:25);
22assert_checkequal(asciimat(c), r); 22assert_checkequal(asciimat(c), C);
23assert_checkequal(asciimat(cat(3,c,c)), [r r]); 23assert_checkequal(asciimat(cat(3,c,c)), cat(3,C,C));
24assert_checkequal(asciimat(cat(7,c,c)), cat(6, r, r)); 24assert_checkequal(asciimat(cat(7,c,c)), cat(7,C,C));
25 25
26// With UTF8 (limited application) 26// With UTF8 (limited application)
27t = "àâãäéèêëìîïòôöùûü"; 27t = "àâãäéèêëìîïòôöùûü";
diff --git a/scilab/modules/string/tests/unit_tests/asciimat.tst b/scilab/modules/string/tests/unit_tests/asciimat.tst
index 47c2058..5b1f2ad 100644
--- a/scilab/modules/string/tests/unit_tests/asciimat.tst
+++ b/scilab/modules/string/tests/unit_tests/asciimat.tst
@@ -1,7 +1,7 @@
1// ============================================================================= 1// =============================================================================
2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre 3// Copyright (C) 2012 - Scilab Enterprises - Cedric Delamarre
4// Copyright (C) 2017 - Samuel GOUGEON 4// Copyright (C) 2020-2021 - Samuel GOUGEON
5// 5//
6// This file is distributed under the same license as the Scilab package. 6// This file is distributed under the same license as the Scilab package.
7// ============================================================================= 7// =============================================================================
@@ -9,55 +9,108 @@
9// <-- CLI SHELL MODE --> 9// <-- CLI SHELL MODE -->
10// <-- NO CHECK REF --> 10// <-- NO CHECK REF -->
11 11
12// ascii to string 12// Empty
13// --------------- 13assert_checkequal(asciimat([]), []);
14ref = [97 98 99 ;100 101 102]; 14assert_checkequal(asciimat(["" ""]), []);
15code = asciimat(["a" "b" "c";"d" "e" "f"]); 15assert_checkequal(asciimat(["";""]), []);
16assert_checkequal(ref, code); 16assert_checkequal(asciimat(["" "";"" ""]), []);
17 17
18ref = [97 122 98 99 ;100 101 121 102]; 18// US-ASCII
19code = asciimat(["az" "b" "c";"d" "ey" "f"]); 19// ========
20assert_checkequal(ref, code); 20// Scalar
21assert_checkequal(asciimat(""), []);
22assert_checkequal(asciimat("a"), 97);
23assert_checkequal(asciimat("abc"), 97:99);
24assert_checkequal(asciimat(0), "");
25assert_checkequal(asciimat(97), "a");
26assert_checkequal(asciimat(97:99), "abc");
21 27
22// 3D hypermat 28// Mat with all lengths equal
23m = matrix(97:120,4,3,2); 29t = ["ab" ; " c" ; "d "];
24t = asciimat(m); 30ref = [ 97 98 ; 32 99 ; 100 32];
25ref = ["aei" "mqu" 31assert_checkequal(asciimat(t), ref);
26 "bfj" "nrv" 32assert_checkequal(asciimat(ref), ["ab" ; " c" ; "d"]);
27 "cgk" "osw"
28 "dhl" "ptx"
29 ];
30assert_checkequal(t, ref);
31 33
32// 12D hypermat 34t = ["a" "b" "c" ; "d" "e" "f"];
33h = cat(12,m,m); 35ref = [ 97 98 99 ;
34t = asciimat(h); 36 100 101 102];
35assert_checkequal(t, cat(11,ref,ref)); 37assert_checkequal(asciimat(t), ref);
36 38assert_checkequal(asciimat(ref), ["abc" ; "def"]);
37// string to ascii 39
38// --------------- 40// Matrix with various lengths, including "" :
39// not managed in scilab 5 41// * Matlab & Octave DELETE ""
40scilabversion = getversion("scilab"); 42// * Octave PADDS with ascii(32)
41if scilabversion(1) >= 6 43t = ["a" ; "ab" ; ""; " " ; "ab d"];
42 ref = matrix(97:120,2,3,4); 44ref = [ 97 32 32 32
43 a = matrix(strsplit(ascii(97:120),1:23),2,3,4); 45 97 98 32 32
44 code = asciimat(a); 46 32 32 32 32
45 assert_checkequal(ref, code); 47 32 32 32 32
46end 48 97 98 32 100 ];
47// 49assert_checkequal(asciimat(t), ref);
48ref = ["azerty";"ytreza"]; 50 // Matlab and Octave trim trailing spaces ascii(32)
49str = asciimat([97 122 101 114 116 121; 121 116 114 101 122 97]); 51assert_checkequal(asciimat(ref), ["a"; "ab"; "" ; "" ; "ab d"]);
50assert_checkequal(ref, str); 52
53// Hypermat
54t = [t, flipdim(t,1)];
55t = cat(3, t,t);
56ref = [97,97,98,32,100;97,98,32,32,32;32,32,32,32,32;32,32,97,98,32;97,98,32,100,97];
57ref = cat(3, ref, ref);
58assert_checkequal(asciimat(t), ref);
59tmp = ["aab d" ; "ab" ; "" ; " ab" ; "ab da"];
60assert_checkequal(asciimat(ref), cat(3, tmp,tmp));
51 61
52ref = ["bdf" "hjl" "npr" "tvx";"ceg" "ikm" "oqs" "uwy"]; 62// UTF-8
53a = matrix(97+(1:2*3*4),2,3,4); 63// =====
54str = asciimat(a); 64// ascimmat() uses Octave's encoding = UTF-8 + trims trailing spaces
55assert_checkequal(ref, str); 65t1 = "àâãäéèêë";
66t2 = "ìîïòôöùûü";
67assert_checkequal(asciimat(asciimat(t2)), t2);
68assert_checkequal(asciimat(asciimat([t1 t2])), t1+t2);
69assert_checkequal(asciimat(asciimat([t1 ; t2])), [t1 ; t2]);
70assert_checkequal(asciimat(asciimat([t1 t2 ; t2 t1])), [t1+t2 ; t2+t1]);
56 71
57// With UTF8 (limited application) 72// Scalar
58t = "àâãäéèêëìîïòôöùûü"; 73assert_checkequal(asciimat("α"), [206 177]);
59assert_checkequal(asciimat(asciimat(t)), t); 74assert_checkequal(asciimat("βcδ"), [206 178 99 206 180]);
60assert_checkequal(asciimat(asciimat([t t])), t+t); 75assert_checkequal(asciimat("abc"), 97:99);
61assert_checkequal(asciimat(asciimat([t;t])), [t;t]);
62 76
77x = ["a €" "bδ " ; " " "45ε"]
78// for x(:)
79ref = [97 32 226 130 172
80 32 32 32 32 32
81 98 206 180 32 32
82 52 53 206 181 32 ];
83assert_checkequal(asciimat(x(:)), ref);
84assert_checkequal(asciimat(ref), ["a €" "" "bδ" "45ε"]');
63 85
86// for x matrix
87ref = [97 32 226 130 172 98 206 180 32
88 32 32 32 52 53 206 181 32 32 ];
89assert_checkequal(asciimat(x), ref);
90assert_checkequal(asciimat(ref), ["a €bδ" ; " 45ε"]);
91
92// 3D hypermat
93x2 = ["αab" "βδc" ; "ε4" ""];
94h = cat(3, x, x2)
95/* h =
96(:,:,1)
97 "a €" "bδ "
98 " " "45ε"
99(:,:,2)
100 "αab" "βδc"
101 "ε4" ""
102*/
103ref = cat(3, [97 32 226 130 172 98 206 180 32.
104 32 32 32 52 53 206 181 32 32 ],..
105 [206 177 97 98 206 178 206 180 99
106 206 181 52 32 32 32 32 32 32 ]);
107assert_checkequal(asciimat(h), ref);
108refS = cat(3,["a €bδ";" 45ε"],["αabβδc";"ε4"]);
109assert_checkequal(asciimat(ref), refS);
110
111// 12D hypermat
112h = cat(12, ["€" "bδ"], ["" "45ε"]);
113ref = cat(12, [226 130 172 98 206 180 ],..
114 [ 52 53 206 181 32 32 ]);
115assert_checkequal(asciimat(h), ref);
116assert_checkequal(asciimat(ref), cat(12,"€bδ","45ε"));