Example #1
0
    bool String::endsWith(const String& search, bool caseSensitive) const
    {
        if(caseSensitive)
        {
            return subString(getSize() - search.getSize()) == search;

        }

        return subString(getSize() - search.getSize()).toUppercase() == search.toUppercase();
    }
Example #2
0
void ClipboardImpl::setString(const String& text)
{
    if (!OpenClipboard(NULL))
    {
        std::cerr << "Failed to open the Win32 clipboard." << std::endl;
        return;
    }

    if (!EmptyClipboard())
    {
        std::cerr << "Failed to empty the Win32 clipboard." << std::endl;
        return;
    }

    // Create a Win32-compatible string
    size_t string_size = (text.getSize() + 1) * sizeof(WCHAR);
    HANDLE string_handle = GlobalAlloc(GMEM_MOVEABLE, string_size);

    if (string_handle)
    {
        memcpy(GlobalLock(string_handle), text.toWideString().data(), string_size);
        GlobalUnlock(string_handle);
        SetClipboardData(CF_UNICODETEXT, string_handle);
    }

    CloseClipboard();
}
Example #3
0
    bool String::startsWith(const String& search, bool caseSensitive) const
    {
        if(caseSensitive)
        {
            return find(search) == 0;
        }

        return subString(0, search.getSize()).toUppercase() == search.toUppercase();
    }
Example #4
0
    void print (const String& str) {
        Vector2i offset;
        offset.x = mCursor.x + str.getSize();

        if (offset.x == 0)
            return;

        //if the string is not over the width
        if (offset.x < getSize().x) {
            mPrintN (str, str.getSize());
        // else we must go to next line
        } else {
            int pos = str.getSize() - (offset.x - getSize().x);
            mPrintN (str, pos);
            mCursor.y++;
            mCursor.x = 0;
            return print (str.toAnsiString().substr(pos).c_str());
        }
    }
Example #5
0
    std::size_t String::replace(const String& search, const String& replace)
    {
        std::size_t count = 0;
        std::size_t nextReplace;

        while((nextReplace = find(search)) < InvalidPosition)
        {
            m_string.replace(nextReplace, search.getSize(), replace.m_string);
        }

        return count;
    }
Example #6
0
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_basename(typed_list &in, int _iRetCount, typed_list &out)
{
    int iExpand     = 1;
    int iConvert    = 1;

    if (in.size() < 1 || in.size() > 3)
    {
        Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "basename", 1, 3);
        return Function::Error;
    }

    if (_iRetCount != 1)
    {
        Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "basename", 1);
        return Function::Error;
    }

    if (in.size() > 2)
    {
        if (in[2]->isBool() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 3);
            return Function::Error;
        }

        if (in[2]->getAs<types::Bool>()->getSize() != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 3);
            return Function::Error;
        }

        iExpand = in[2]->getAs<types::Bool>()->get()[0];
    }

    if (in.size() > 1)
    {
        if (in[1]->isBool() == false)
        {
            Scierror(999, _("%s: Wrong type for input argument #%d: A boolean expected.\n"), "basename", 2);
            return Function::Error;
        }

        if (in[1]->getAs<types::Bool>()->getSize() != 1)
        {
            Scierror(999, _("%s: Wrong size for input argument #%d: A scalar boolean expected.\n"), "basename", 2);
            return Function::Error;
        }

        iConvert = in[1]->getAs<types::Bool>()->get()[0];
    }

    if (in[0]->isDouble() && in[0]->getAs<Double>()->isEmpty())
    {
        out.push_back(Double::Empty());
        return Function::OK;
    }
    if (in[0]->isString() == false)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string matrix expected.\n"), "basename", 1);
        return Function::Error;
    }

    String* pS      = in[0]->getAs<types::String>();
    String* pOut    = new String(pS->getRows(), pS->getCols());
    for (int i = 0 ; i < pS->getSize() ; i++)
    {
        wchar_t* base = basenameW(pS->get(i), (BOOL)iExpand);
        pOut->set(i, base);
        FREE(base);
    }


    out.push_back(pOut);
    return Function::OK;
    //SciErr sciErr;
    //BOOL flag = TRUE; /* default */
    //BOOL flagexpand = TRUE; /* default */

    //int *piAddressVarOne = NULL;
    //wchar_t **pStVarOne = NULL;
    //int *lenStVarOne = NULL;
    //int iType1					= 0;
    //int m1 = 0, n1 = 0;

    //wchar_t **pStResult = NULL;

    //int i = 0;

    ///* Check Input & Output parameters */
    //CheckRhs(1,3);
    //CheckLhs(1,1);

    //if (Rhs > 2)
    //{
    //	int *piAddressVarThree = NULL;
    //	int *piData = NULL;
    //	int iType3	= 0;
    //	int m3 = 0, n3 = 0;

    //	sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddressVarThree);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarType(pvApiCtx, piAddressVarThree, &iType3);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if (iType3 != sci_boolean)
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 3);
    //		return 0;
    //	}

    //	sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarThree, &m3, &n3,  &piData);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarThree, &m3, &n3);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if ( (m3 != n3) && (n3 != 1) )
    //	{
    //		Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 3);
    //		return 0;
    //	}

    //	flagexpand = piData[0];
    //}

    //if (Rhs > 1)
    //{
    //	int *piAddressVarTwo = NULL;
    //	int *piData = NULL;
    //	int iType2	= 0;
    //	int m2 = 0, n2 = 0;

    //	sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddressVarTwo);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	sciErr = getVarType(pvApiCtx, piAddressVarTwo, &iType2);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if (iType2 != sci_boolean)
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: A boolean expected.\n"), fname, 2);
    //		return 0;
    //	}

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarTwo, &m2, &n2);

    //	if ( (m2 != n2) && (n2 != 1) )
    //	{
    //		Scierror(999,_("%s: Wrong size for input argument #%d: A boolean expected.\n"), fname, 2);
    //		return 0;
    //	}

    //	sciErr = getMatrixOfBoolean(pvApiCtx, piAddressVarTwo, &m2, &n2,  &piData);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	flag = piData[0];
    //}

    //sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddressVarOne);
    //if(sciErr.iErr)
    //{
    //	printError(&sciErr, 0);
    //	return 0;
    //}

    //sciErr = getVarType(pvApiCtx, piAddressVarOne, &iType1);
    //if(sciErr.iErr)
    //{
    //	printError(&sciErr, 0);
    //	return 0;
    //}

    //if (iType1 == sci_matrix)
    //{
    //	sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	if ( (m1 == n1) && (m1 == 0) )
    //	{
    //		sciErr = createMatrixOfDouble(pvApiCtx, Rhs + 1, m1, n1, NULL);
    //		if(sciErr.iErr)
    //		{
    //			printError(&sciErr, 0);
    //			return 0;
    //		}

    //		LhsVar(1) = Rhs + 1;
    //		C2F(putlhsvar)();
    //	}
    //	else
    //	{
    //		Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
    //	}
    //}
    //else if (iType1 == sci_strings)
    //{
    //	int i = 0;

    //	sciErr = getVarDimension(pvApiCtx, piAddressVarOne, &m1, &n1);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	lenStVarOne = (int*)MALLOC(sizeof(int) * (m1 * n1));
    //	if (lenStVarOne == NULL)
    //	{
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	// get lenStVarOne value
    //	sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
    //	if(sciErr.iErr)
    //	{
    //		freeArrayOfWideString(pStVarOne, m1 * n1);
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	pStVarOne = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));
    //	if (pStVarOne == NULL)
    //	{
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	for (i = 0; i < (m1 * n1); i++)
    //	{
    //		pStVarOne[i] = (wchar_t*)MALLOC(sizeof(wchar_t) * (lenStVarOne[i] + 1));
    //		if (pStVarOne[i] == NULL)
    //		{
    //			freeArrayOfWideString(pStVarOne, m1 * n1);
    //			if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //			Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //			return 0;
    //		}
    //	}

    //	// get pStVarOne
    //	sciErr = getMatrixOfWideString(pvApiCtx, piAddressVarOne, &m1, &n1, lenStVarOne, pStVarOne);
    //	if(sciErr.iErr)
    //	{
    //		freeArrayOfWideString(pStVarOne, m1 * n1);
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	pStResult = (wchar_t**)MALLOC(sizeof(wchar_t*) * (m1 * n1));

    //	if (pStResult == NULL)
    //	{
    //		if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //		Scierror(999,_("%s: Memory allocation error.\n"),fname);
    //		return 0;
    //	}

    //	for (i=0;i< m1 * n1; i++)
    //	{
    //		pStResult[i] = basenameW(pStVarOne[i], flagexpand);
    //	}

    //	sciErr = createMatrixOfWideString(pvApiCtx, Rhs + 1, m1, n1, pStResult);
    //	if(sciErr.iErr)
    //	{
    //		printError(&sciErr, 0);
    //		return 0;
    //	}

    //	LhsVar(1) = Rhs + 1;
    //	C2F(putlhsvar)();

    //	if (lenStVarOne) {FREE(lenStVarOne); lenStVarOne = NULL;}
    //	freeArrayOfWideString(pStResult, m1 * n1);
    //	freeArrayOfWideString(pStVarOne, m1 * n1);
    //}
    //else
    //{
    //	Scierror(999,_("%s: Wrong type for input argument #%d: String array expected.\n"), fname, 1);
    //}
    //return 0;
}