2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2017 - Scilab Enterprises - Antoine ELIAS
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
15 /*--------------------------------------------------------------------------*/
17 #include "string_gw.hxx"
18 #include "function.hxx"
22 #include "overload.hxx"
23 /*--------------------------------------------------------------------------*/
26 #include "localization.h"
30 static const std::string fname("emptystr");
31 /*--------------------------------------------------------------------------*/
32 types::Function::ReturnValue sci_emptystr(types::typed_list &in, int _iRetCount, types::typed_list &out)
34 types::String* ret = nullptr;
35 int iRhs = static_cast<int>(in.size());
37 // check output parameters
38 if (_iRetCount != 1 && _iRetCount != -1)
40 Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), fname.data(), 1);
41 return types::Function::Error;
48 if (in[0]->isGenericType())
50 types::GenericType* pGT = in[0]->getAs<types::GenericType>();
51 if (pGT->getSize() == 0)
53 out.push_back(types::Double::Empty());
54 return types::Function::OK;
57 ret = new types::String(pGT->getDims(), pGT->getDimsArray());
59 else if (in[0]->isList())
61 types::List* pL = in[0]->getAs<types::List>();
62 ret = new types::String(pL->getSize(), 1);
66 return Overload::generateNameAndCall(L"emptystr", in, _iRetCount, out);
73 if (in[0]->isDouble() == false || in[0]->getAs<types::Double>()->isScalar() == false)
75 Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of integers expected.\n"), fname.data(), 1);
76 return types::Function::Error;
79 if (in[1]->isDouble() == false || in[1]->getAs<types::Double>()->isScalar() == false)
81 Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of integers expected.\n"), fname.data(), 2);
82 return types::Function::Error;
85 int row = static_cast<int>(in[0]->getAs<types::Double>()->get()[0]);
86 int col = static_cast<int>(in[1]->getAs<types::Double>()->get()[0]);
88 if (row == 0 || col == 0)
90 out.push_back(types::Double::Empty());
91 return types::Function::OK;
94 ret = new types::String(row, col);
99 ret = new types::String(1, 1);
103 int size = ret->getSize();
104 wchar_t** strs = ret->get();
105 for (int i = 0; i < size; ++i)
107 strs[i] = os_wcsdup(L"");
111 return types::Function::OK;