Example #1
0
	/*=============================================================================
    -- Returns true if the open element (thing in tags "<>" but with a "/") is
	   equivalent to the token.
    =============================================================================*/
	bool HMLFile::AtElementOpen(String element)
	{
		//add the "<>" tags if they aren't already there
        if (element[0] != "<")
            element.Insert("<", 0);
        if (element[element.Size()-1] != ">")
            element.Insert(">", element.Size());

        if (GetToken() == element)
            return true;

		if (mFile.eof())
			return true;

        return false;
	}
Example #2
0
String String::Erase(const int pos, int len)
{
    int str_len = Size();
    int len_a = pos;

    // If erase after the length of the string, return.
    if (len_a >= str_len)
        return *this;

    // Prevent erasing after the end of the string.
    if ((len_a + len) > str_len) {
        // Resize the erase length.
        len = str_len - len_a;
    }

    String s;
    int len_b = str_len - len_a - len;
    s.Allocate(len_a + len_b + 1);

    Copy(&s.v[0], &v[0], len_a);
    if (len_b > 0) {
        int offset_b = len_a + len;
        Concatenate(&s.v[0], &v[0 + offset_b]);
    }
    s.v[s.Size()] = 0;
    v = s.v;
    return *this;
}
void ColladaLoader::LoadDAEModel(
	const char*						ModelName,
	const uint						ProgramID)
{
	ColladaDoc colladadoc;
	VModelData mesh;

	String ModelPath = FindDAEModelPath(ModelName);

	if (ModelPath.Size() > 1)
	{
		colladadoc.Read((ModelPath + ModelName + ".dae").Val());
		mesh.SetModelPath(ModelPath.Val());
		mesh.SetName(ModelName);
		mesh.LoadColladaDoc(colladadoc);

		LoadModel(mesh);

		LogMessage("Model '%s' loaded", ModelName);

	} else
	{
		LogError("File '%s.dae' not found", ModelName);
	}
}
Example #4
0
const String& GetLocaleUnix()
{
    static String globalLocale;
    if (globalLocale.Size() == 0)
        globalLocale = String::UnsafeStringCreation(
            setlocale(LC_ALL, 0), RF_Core::DataManagment::TransfereOwnership);
    return globalLocale;
}
Example #5
0
String String::Erase(const int pos)
{
    String s;
    s.Allocate(pos + 1);
    Copy(&s.v[0], &v[0], pos);
    s.v[s.Size()] = 0;
    v = s.v;
    return *this;
}
Example #6
0
    /*=============================================================================
    -- Seeks through the file until it reaches the opening element (thing in tags
       "<>") or the end.
    =============================================================================*/
    bool HMLFile::SeekElementOpen(String element)
    {
        //add the "<>" tags if they aren't already there
        if (element[0] != "<")
            element.Insert("<", 0);
        if (element[element.Size()-1] != ">")
            element.Insert(">", element.Size());

        if (!mFile.is_open())
            return false;

        //seek to the element tag
        while (GetToken() != element.GetStd())
        {
			//return false because the file couldn't seek any further (at end of file)
            if (!Seek())
                return false;
        }


        return true;
    }
Example #7
0
/*!
 * Finds the last occurrence of a string
 *
 * \throws	ExceptionDomain	index out of bounds
 *
 * \param[in]	s	the string to search
 * \param[in]	last_pos	the position of the beginning, NPos for the end.
 * \return	the index of the first occurrence, or NPos if not found.
 */
size_t String::BackwardFind(const String &s, size_t last_pos) const
{
	if (s.Size() > Size())
		return NPos();
	if (last_pos == NPos())
		return data.rfind(s.data);
	if (last_pos >= Size())
	{
		throw ExceptionDomain(StringUTF8("int String::BackwardFind(const String &s, int last_pos = -1) const: ") +
				_("index out of bounds."));
	}
	return data.rfind(s.data, last_pos);
}
Example #8
0
/*!
 * Edit distance
 *
 * \author Wikibooks
 * \param[in]	s	the string to compare
 * \return	the amount of suppression, addition and change to morph from one string to the other
 */
int String::EditDistance(const String &s) const
{
	unsigned int s1 = (unsigned int)Size();
	unsigned int s2 = (unsigned int)s.Size();
	std::vector<std::vector<unsigned int> > d(s1 + 1, std::vector<unsigned int>(s2 + 1));

	for (unsigned int i = 1; i <= s1; ++i) d[i][0] = i;
	for (unsigned int i = 1; i <= s2; ++i) d[0][i] = i;

	for (unsigned int i = 1; i <= s1; ++i)
		for (unsigned int j = 1; j <= s2; ++j)
			d[i][j] = std::min(std::min(d[i - 1][j] + 1, d[i][j - 1] + 1),
					d[i - 1][j - 1] + (data[i - 1] == s[j - 1] ? 0 : 1));
	return d[s1][s2];
}
Example #9
0
/*!
 * Finds the first occurrence of a string
 *
 * \throws	ExceptionDomain	index out of bounds
 *
 * \param[in]	s	the string to search
 * \param[in]	from_pos	the position of the beginning
 * \return	the index of the first occurrence, or NPos if not found.
 */
size_t String::Find(const String &s, size_t from_pos) const
{
	if (IsEmpty())
		return NPos();
	if (s.Size() > Size())
	{
		return NPos();
	}
	if (from_pos >= Size())
	{
		throw ExceptionDomain(StringUTF8("int String::Find(const String &s, int from_pos = 0) const: ") +
				_("index out of bounds."));
	}
	return data.find(s.data, from_pos);
}
Example #10
0
 void String::Insert( int idx, String const& s )
 {
     Insert( idx, s.C_str(), s.Size() );
 }
Example #11
0
void String::Copy(String &d, const char *s, const int len)
{
    for (int i = 0; i < len; ++i)
        d.v << s[i];
    d.v[d.Size()] = 0;
}