2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Allan CORNET
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 * Copyright (C) 2017 Siddhartha Gairola
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.
16 /*--------------------------------------------------------------------------*/
17 #include "string_gw.hxx"
18 #include "function.hxx"
19 #include "context.hxx"
23 #include "stripblanks.hxx"
24 /*--------------------------------------------------------------------------*/
27 #include "localization.h"
30 /*--------------------------------------------------------------------------*/
31 types::Function::ReturnValue sci_stripblanks(types::typed_list &in, int _iRetCount, types::typed_list &out)
33 #define FUNCNAME "stripblanks"
34 bool bRemoveTab = false;
37 // check input parameters
38 if (in.size() < 1 || in.size() > 3)
40 Scierror(999, _("%s: Wrong number of input arguments: %d to %d expected.\n"), FUNCNAME, 1, 3);
41 return types::Function::Error;
44 // check output parameters
45 if (_iRetCount != 1 && _iRetCount != -1)
47 Scierror(999, _("%s: Wrong number of output arguments: %d expected.\n"), FUNCNAME, 1);
48 return types::Function::Error;
53 if (in[1]->isBool() == false || in[1]->getAs<types::Bool>()->isScalar() == false)
55 Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), FUNCNAME, 2);
56 return types::Function::Error;
59 if (in[1]->getAs<types::Bool>()->get()[0] == 1)
67 if (in[2]->isDouble() == false || in[2]->getAs<types::Double>()->isScalar() == false)
70 Scierror(999, _("%s: Wrong type for input argument #%d: A scalar expected.\n"), FUNCNAME, 2);
71 return types::Function::Error;
75 flag = in[2]->getAs<types::Double>()->get()[0];
77 if (floor(flag) != flag || (flag != 0.0 && flag != 1.0 && flag != -1.0))
80 Scierror(999, _("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), FUNCNAME, 3, "-1, 0, 1");
81 return types::Function::Error;
86 switch (in[0]->getType())
88 case types::InternalType::ScilabString:
90 types::String *pS = stripblanks(in[0]->getAs<types::String>(), bRemoveTab, static_cast<int>(flag));
93 Scierror(999, _("%s : No more memory.\n"), FUNCNAME);
94 return types::Function::Error;
100 case types::InternalType::ScilabDouble://manage []
102 if (in[0]->getAs<types::Double>()->getSize() != 0)
104 Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty matrix expected.\n"), FUNCNAME, 1);
105 return types::Function::Error;
108 out.push_back(types::Double::Empty());
113 Scierror(999, _("%s: Wrong type for input argument #%d: Matrix of strings or empty matrix expected.\n"), FUNCNAME, 1);
114 return types::Function::Error;
118 return types::Function::OK;
120 /*--------------------------------------------------------------------------*/