|
| 1 | +//============================================================================= |
| 2 | +// Copyright (c) 2016-present Allan CORNET (Nelson) |
| 3 | +//============================================================================= |
| 4 | +// This file is part of the Nelson. |
| 5 | +//============================================================================= |
| 6 | +// LICENCE_BLOCK_BEGIN |
| 7 | +// SPDX-License-Identifier: LGPL-3.0-or-later |
| 8 | +// LICENCE_BLOCK_END |
| 9 | +//============================================================================= |
| 10 | +#include "joinBuiltin.hpp" |
| 11 | +#include "StringJoin.hpp" |
| 12 | +#include "Error.hpp" |
| 13 | +#include "i18n.hpp" |
| 14 | +#include "InputOutputArgumentsCheckers.hpp" |
| 15 | +#include "OverloadRequired.hpp" |
| 16 | +//============================================================================= |
| 17 | +using namespace Nelson; |
| 18 | +//============================================================================= |
| 19 | +ArrayOfVector |
| 20 | +Nelson::StringGateway::joinBuiltin(int nLhs, const ArrayOfVector& argIn) |
| 21 | +{ |
| 22 | + ArrayOfVector retval; |
| 23 | + nargoutcheck(nLhs, 0, 1); |
| 24 | + nargincheck(argIn, 1, 3); |
| 25 | + ArrayOf delimiters; |
| 26 | + ArrayOf A = argIn[0]; |
| 27 | + std::vector<indexType> vec = A.getDimensions().getAsVector(); |
| 28 | + indexType dim = 0; |
| 29 | + if (!A.isEmpty()) { |
| 30 | + for (int k = static_cast<int>(vec.size()) - 1; k >= 0; --k) { |
| 31 | + if (vec[k] != 0 && vec[k] != 1) { |
| 32 | + dim = k; |
| 33 | + break; |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + dim += 1; |
| 38 | + switch (argIn.size()) { |
| 39 | + case 1: { |
| 40 | + delimiters = ArrayOf::stringArrayConstructor(L" "); |
| 41 | + } break; |
| 42 | + case 2: { |
| 43 | + if (argIn[1].isRowVectorCharacterArray()) { |
| 44 | + delimiters = ArrayOf::stringArrayConstructor(argIn[1].getContentAsWideString()); |
| 45 | + } else if (argIn[1].isStringArray()) { |
| 46 | + delimiters = argIn[1]; |
| 47 | + } else if (argIn[1].isCellArrayOfCharacterVectors()) { |
| 48 | + delimiters = ArrayOf::stringArrayConstructor( |
| 49 | + argIn[1].getContentAsWideStringVector(false), argIn[1].getDimensions()); |
| 50 | + } else { |
| 51 | + dim = argIn[1].getContentAsScalarIndex(false, true); |
| 52 | + delimiters = ArrayOf::stringArrayConstructor(" "); |
| 53 | + } |
| 54 | + } break; |
| 55 | + case 3: { |
| 56 | + if (argIn[1].isRowVectorCharacterArray()) { |
| 57 | + delimiters = ArrayOf::stringArrayConstructor(argIn[1].getContentAsWideString()); |
| 58 | + } else if (argIn[1].isStringArray()) { |
| 59 | + delimiters = argIn[1]; |
| 60 | + } else if (argIn[1].isCellArrayOfCharacterVectors()) { |
| 61 | + delimiters = ArrayOf::stringArrayConstructor( |
| 62 | + argIn[1].getContentAsWideStringVector(false), argIn[1].getDimensions()); |
| 63 | + } else { |
| 64 | + Error(_W( |
| 65 | + "Wrong type for argument #3: string, characters or cell of characters expected.")); |
| 66 | + } |
| 67 | + dim = argIn[2].getContentAsScalarIndex(false, true); |
| 68 | + } break; |
| 69 | + default: { |
| 70 | + Error(ERROR_WRONG_NUMBERS_INPUT_ARGS); |
| 71 | + } break; |
| 72 | + } |
| 73 | + retval << StringJoin(A, delimiters, dim); |
| 74 | + return retval; |
| 75 | +} |
| 76 | +//============================================================================= |
0 commit comments