Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue #173 convertStringsToChars builtin
- Loading branch information
1 parent
d2e27f2
commit 8725ab7
Showing
17 changed files
with
324 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
modules/string/builtin/cpp/convertStringsToCharsBuiltin.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-2019 Allan CORNET (Nelson) | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#include "ConvertStringsToChars.hpp" | ||
#include "Error.hpp" | ||
#include "convertStringsToCharsBuiltin.hpp" | ||
//============================================================================= | ||
using namespace Nelson; | ||
//============================================================================= | ||
ArrayOfVector | ||
Nelson::StringGateway::convertStringsToCharsBuiltin( | ||
Evaluator* eval, int nLhs, const ArrayOfVector& argIn) | ||
{ | ||
if (nLhs > argIn.size()) { | ||
Error(_W("Number of Input arguments must the same as output.")); | ||
} | ||
return ConvertStringsToChars(argIn); | ||
} | ||
//============================================================================= |
32 changes: 32 additions & 0 deletions
32
modules/string/builtin/include/convertStringsToCharsBuiltin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-2019 Allan CORNET (Nelson) | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#pragma once | ||
//============================================================================= | ||
#include "ArrayOf.hpp" | ||
#include "Evaluator.hpp" | ||
//============================================================================= | ||
namespace Nelson { | ||
//============================================================================= | ||
namespace StringGateway { | ||
ArrayOfVector | ||
convertStringsToCharsBuiltin(Evaluator* eval, int nLhs, const ArrayOfVector& argIn); | ||
} | ||
//============================================================================= | ||
} // namespace Nelson | ||
//============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xmldoc> | ||
<copyright>SAME AS NELSON SOFTWARE</copyright> | ||
|
||
<language>en_US</language> | ||
<keyword>convertStringsToChars</keyword> | ||
<short_description>Convert string arrays to character arrays.</short_description> | ||
|
||
<syntax> | ||
<syntax_item>C = convertStringsToChars(S)</syntax_item> | ||
<syntax_item>[B1, B2, ..., BN] = convertStringsToChars(A1, A2, ..., AN)</syntax_item> | ||
</syntax> | ||
|
||
<param_input> | ||
<param_input_item> | ||
<param_name>S</param_name> | ||
<param_description>if S is a string array, output C will be converted to an cell of strings or an character vector (if S is scalar).</param_description> | ||
</param_input_item> | ||
<param_input_item> | ||
<param_name>A1, A2, ..., AN</param_name> | ||
<param_description>variables to convert to char array if it is a string array.</param_description> | ||
</param_input_item> | ||
</param_input> | ||
|
||
<param_output> | ||
|
||
<param_output_item> | ||
<param_name>C</param_name> | ||
<param_description>a string array or unaltered variable</param_description> | ||
</param_output_item> | ||
<param_output_item> | ||
<param_name>B1, B2, ..., BN</param_name> | ||
<param_description>variables converted to char array if it is a string array.</param_description> | ||
</param_output_item> | ||
|
||
</param_output> | ||
|
||
<description> | ||
<p><b>convertStringsToChars</b> converts string arrays to character arrays.</p> | ||
</description> | ||
|
||
|
||
<used_function></used_function> | ||
<bibliography></bibliography> | ||
|
||
<examples> | ||
|
||
<example_item> | ||
<example_item_type>nelson</example_item_type> | ||
<example_item_description></example_item_description> | ||
<example_item_data><![CDATA[A = convertStringsToChars("Nelson") | ||
A = convertStringsToChars(["Nelson", string(NaN)])]]> | ||
</example_item_data> | ||
|
||
</example_item> | ||
|
||
</examples> | ||
|
||
<see_also> | ||
<see_also_item> | ||
<link linkend="${data_structures}cellstr">cellstr</link> | ||
</see_also_item> | ||
<see_also_item> | ||
<link linkend="${string}string">string</link> | ||
</see_also_item> | ||
<see_also_item> | ||
<link linkend="${string}char">char</link> | ||
</see_also_item> | ||
|
||
</see_also> | ||
|
||
<history> | ||
<history_item> | ||
<history_version>1.0.0</history_version> | ||
<history_description>initial version</history_description> | ||
</history_item> | ||
</history> | ||
|
||
<authors> | ||
<author_item>Allan CORNET</author_item> | ||
</authors> | ||
</xmldoc> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//============================================================================= | ||
// Copyright (c) 2016-2019 Allan CORNET (Nelson) | ||
//============================================================================= | ||
// LICENCE_BLOCK_BEGIN | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 2 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
// LICENCE_BLOCK_END | ||
//============================================================================= | ||
#include "ConvertStringsToChars.hpp" | ||
#include "Exception.hpp" | ||
//============================================================================= | ||
namespace Nelson { | ||
ArrayOfVector | ||
ConvertStringsToChars(const ArrayOfVector& A) | ||
{ | ||
ArrayOfVector res; | ||
for (auto value : A) { | ||
if (value.isStringArray()) { | ||
Dimensions dims = value.getDimensions(); | ||
if (dims.isEmpty(false)) { | ||
ArrayOf valueAsCell = ArrayOf(NLS_CELL_ARRAY, dims, nullptr); | ||
res.push_back(valueAsCell); | ||
} else if (dims.isScalar()) { | ||
auto* elementsStr = (ArrayOf*)value.getDataPointer(); | ||
ArrayOf element = elementsStr[0]; | ||
if (element.getDataClass() == NLS_CHAR) { | ||
res.push_back( | ||
ArrayOf::characterArrayConstructor(element.getContentAsWideString())); | ||
} else { | ||
res.push_back(ArrayOf::characterArrayConstructor("")); | ||
} | ||
} else { | ||
auto* elementsCell = new_with_exception<ArrayOf>(dims.getElementCount(), false); | ||
ArrayOf valueAsCell = ArrayOf(NLS_CELL_ARRAY, dims, elementsCell); | ||
auto* elementsStr = (ArrayOf*)value.getDataPointer(); | ||
for (indexType q = 0; q < dims.getElementCount(); q++) { | ||
if (elementsStr[q].getDataClass() == NLS_CHAR) { | ||
elementsCell[q] = elementsStr[q]; | ||
} else { | ||
elementsCell[q] = ArrayOf::characterArrayConstructor(""); | ||
} | ||
} | ||
res.push_back(valueAsCell); | ||
} | ||
} else { | ||
res.push_back(value); | ||
} | ||
} | ||
return res; | ||
} | ||
//============================================================================= | ||
} // namespace Nelson | ||
//============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.