Beispiel #1
0
String operator+ (const String & s1, const String & s2)
{
   char * chaine = new char[s1.getSize() + s2.getSize()]; //passage par declaration dynamique cause ISO C++
   strcat(strcpy(chaine,s1.getPData()),s2.getPData());
   String temp(chaine);
   delete[] chaine;
   return temp;
}
Beispiel #2
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();
    }
Beispiel #3
0
void String::replace(const String& searchFor, const String& replaceWith)
{
    std::size_t step = replaceWith.getSize();
    std::size_t len = searchFor.getSize();
    std::size_t pos = find(searchFor);

    // Replace each occurrence of search
    while (pos != InvalidPos)
    {
        replace(pos, len, replaceWith);
        pos = find(searchFor, pos + step);
    }
}
void TeleportPlayer(Player &player, vector<Portal*> &portals)
{
	player.isTeleporting = false;
	if (portals.size() >= 2)
	{
		String namePortal;
		for (auto *p : portals)
		{
			if (player.GetRect().intersects(p->GetRect()))
			{
				namePortal = (*p).name;
			}
		}
		if (namePortal.getSize() != 0)
		{
			for (auto *p : portals)
			{
				if (!((*p).name == namePortal))
				{
					player.SetPos((*p).GetCoordinates().x - ((*p).GetSize().x / 2), (*p).GetCoordinates().y - ((*p).GetSize().y / 2));
					player.teleportTimer = 0.1f;
				}
			}
		}
	}
}
Beispiel #5
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();
}
Beispiel #6
0
String* readLine() {
	String* line = new String(256);

	cin.getline(*line, line->getSize());

	return line;
}
Beispiel #7
0
    bool String::startsWith(const String& search, bool caseSensitive) const
    {
        if(caseSensitive)
        {
            return find(search) == 0;
        }

        return subString(0, search.getSize()).toUppercase() == search.toUppercase();
    }
Beispiel #8
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());
        }
    }
Beispiel #9
0
int strprintf(String &str, size_t size, const char *format, ...)
{
    va_list args;
    va_start(args, format);
    int rtn;

    if(!size)
        size = str.getSize();

    if(size > str.getSize())
        str.resize(size);

    char *ptr = str.getText();
    str.setLength(0);
    ptr[0] = 0;
    rtn = vsnprintf(ptr, size, format, args);
    str.setLength(strlen(ptr));
    va_end(args);
    return rtn;
}
Beispiel #10
0
 UString::UString(
     const String &  _STRING
 )
     : UStringBase(
         Converter(
             _STRING.getPtr()
             , _STRING.getSize()
         ).getString()
     )
 {
 }
Beispiel #11
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;
    }
Beispiel #12
0
std::list<String> getTaskList()
{
    std::list<String> taskList;

    // Получаем список файлов и записываем его в taskList
    {
        // В классе String я демонстрирую работу со строками в стиле Си
        String files;
        files.getString();

        // Разбиваем единую входную строку на список строк, разделитель','
        if ((files.getCStr() != 0) && (files.getSize() > 1))
        {
            // Копируем строку на разделение для strtok
            char *str_buf = new(std::nothrow) char[files.getSize()];

            if (str_buf == nullptr)
                return taskList;

            strcpy(str_buf, files.getCStr());

            // Разбиваем строку по токену ","
            char *pch = strtok(str_buf, ",");
            while (pch != nullptr)
            {
                // Сохраняем результат
                taskList.push_back(String(pch, strlen(pch) + 1));
                // Берем следущее значение
                pch = strtok (nullptr, " ,");
            }

            delete[] str_buf;
        }
    }

    return taskList;
}
Beispiel #13
0
mxArray *mxCreateCharArray(int ndim, const int *dims)
{
    if (ndim == 0 || ndim == 1)
    {
        ndim = 2;
    }
    String *ptr = new String(ndim, (int *)dims);

    int size = ptr->getSize();
    for (int i = 0; i < size; ++i)
    {
        ptr->set(i, L"");
    }
    return (mxArray *)ptr;
}
Beispiel #14
0
int mxGetFieldNumber(const mxArray *ptr, const char *string)
{
    if (!mxIsStruct(ptr))
    {
        return -1;
    }
    Struct *pa = (Struct *)ptr;
    String *names = pa->getFieldNames();
    wchar_t *field_name = to_wide_string(string);

    for (int i = 0; i < names->getSize(); i++)
    {
        if (wcscmp(names->get(i), field_name) == 0)
        {
            FREE(field_name);
            return i;
        }
    }
    FREE(field_name);
    return -1;
}
Beispiel #15
0
Tile Tile::fromString(const string& ch, ColorId colorId, bool symbol) {
  String tmp = Renderer::toUnicode(ch);
  CHECK(tmp.getSize() == 1) << "Symbol text too long: " << ch;
  return Tile::unicode(tmp[0], colorId, symbol);
}
Beispiel #16
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;
}