Пример #1
0
        /// convert wide char string to multibyte string
        bool WCSToMBS(behaviac::string& resultString, const behaviac::wstring& wstr, const char* locale)
        {
            BEHAVIAC_UNUSED_VAR(resultString);
            BEHAVIAC_UNUSED_VAR(wstr);
            BEHAVIAC_UNUSED_VAR(locale);

            bool ret = false;

#if BEHAVIAC_COMPILER_MSVC
            const int cp = (strcmp(locale, LOCALE_CN_UTF8) == 0) ? CP_UTF8 : CP_ACP;
            const int dwNum = WideCharToMultiByte(cp, 0, wstr.c_str(), -1, NULL, 0, NULL, NULL);
            char* buffer = (char*)BEHAVIAC_MALLOC_WITHTAG(dwNum * 2 + 2, "WCSToMBS");

            if (buffer)
            {
                WideCharToMultiByte(cp, 0, wstr.c_str(), -1, buffer, dwNum, NULL, NULL);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);

                ret = true;
            }

#else
            uint32_t dwNum = (wstr.size() + 1) * 4;
            char* buffer = (char*)BEHAVIAC_MALLOC_WITHTAG(dwNum, "WCSToMBS");

            if (buffer)
            {
                //remember it to restore it later
                char* currrentLocale = setlocale(LC_ALL, 0);

                char* loc = setlocale(LC_ALL, locale);

                if (loc)
                {
                    wcstombs(buffer, wstr.c_str(), dwNum);
                    ret = true;
                }

                //restore
                setlocale(LC_ALL, currrentLocale);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);
            }

#endif//#if BEHAVIAC_COMPILER_MSVC

            return ret;
        }
Пример #2
0
//! Parse xml from null terminated buffer.
XmlNodeRef XmlParser::parseBuffer(const char* buffer, const char* rootNodeName)
{
    size_t bufLen = strlen(buffer);
    char* temp = (char*)BEHAVIAC_MALLOC_WITHTAG(bufLen + 1, "XmlParserImp::parse");
    memcpy(temp, buffer, bufLen);
    BEHAVIAC_ASSERT(temp[bufLen] == '\0');
    XmlNodeRef result = this->parseBuffer(temp, (int)bufLen, rootNodeName);
    BEHAVIAC_FREE(temp);
    return result;
}
Пример #3
0
void* CScriptSystem::LuaAlloc(void* ud, void* ptr, size_t osize, size_t nsize)
{
    if (nsize == 0)
    {
        BEHAVIAC_FREE(ptr);
        return NULL;
    }
    else
    {
        return BEHAVIAC_REALLOC_WITHTAG(ptr, nsize, "LuaMem");
    }
}
Пример #4
0
	void Workspace::FreeFileBuffer()
	{
		if (ms_fileBuffer)
		{
			BEHAVIAC_FREE(ms_fileBuffer);
			ms_fileBuffer = 0;
			ms_fileBufferLength = 0;
		}

		for (int i = 0; i < kFileBufferDepth; ++i)
		{
			ms_fileBufferOffset[i] = 0;
		}
		ms_fileBufferTop = 0;
	}
Пример #5
0
    void Workspace::FreeFileBuffer()
    {
		for (int i = 0; i < kFileBuffers; ++i) {
			FileBuffer_t& fileBuffer = this->m_fileBuffers[i];

			if (fileBuffer.start) {
				BEHAVIAC_FREE(fileBuffer.start);

				// clear it as it might be freed twice
				fileBuffer.start = 0;
				fileBuffer.offset = 0;
				fileBuffer.length = 0;
			}
		}
    }
Пример #6
0
XmlNodeRef XmlParser::parse(behaviac::IFile* file, const char* rootNodeName, const char* suffix, bool handleError)
{
    BEHAVIAC_UNUSED_VAR(suffix);
    BEHAVIAC_UNUSED_VAR(handleError);

    m_errorString.clear();
    XmlParserImp xml;

    if (file)
    {
        int iSize = (int)file->GetSize() - (int)file->Seek(0, behaviac::CFileSystem::ESeekMoveMode_Cur);

        if (iSize != 0)
        {
            static const int32_t ReadBlockSize = 64 * 1024;
            char* buf = (char*)BEHAVIAC_MALLOC_WITHTAG(ReadBlockSize, "XML");
            XmlNodeRef ref;

            for (int32_t i = 0; i <= iSize / (ReadBlockSize); ++i)
            {
                int32_t bufSize = file->Read(buf, ReadBlockSize);
                {
                    buf[bufSize] = '\0';
                    ref = xml.parse(buf, bufSize, rootNodeName, m_errorString, i == iSize / (ReadBlockSize));
                }
            }

            BEHAVIAC_FREE(buf);

            if (handleError && !m_errorString.empty())
            {
                BEHAVIAC_LOGWARNING("Error while parsing file\n\n%s", m_errorString.c_str());
            }

            return ref;

        }
        else
        {
            return XmlNodeRef();
        }
    }
    else
    {
        BEHAVIAC_ASSERT(0, "XmlParse(behaviac::IFile*) - Invalid file\n");
        return XmlNodeRef();
    }
}
Пример #7
0
	bool LoadTextFileAsStringArray(const char* fileName, behaviac::vector<behaviac::string>& stringArray)
	{
		char* buffer = LoadTextFileAsBuffer(fileName);

		if (buffer)
		{
			ConvertTextBufferAsStringArray(buffer, stringArray);
			BEHAVIAC_FREE(buffer);
			return true;

		}
		else
		{
			return false;
		}
	}
Пример #8
0
	void CStringID::Cleanup()
	{
#if BEHAVIAC_STRINGID_USESTRINGCONTENT

		if (ms_dictionary)
		{
			StringIdDictionary* dictionary = ms_dictionary;

			for (StringIdDictionary::iterator it = dictionary->begin(); it != dictionary->end(); ++it)
			{
				const char* p = it->second;

				BEHAVIAC_FREE(p);
			}

			dictionary->clear();
			BEHAVIAC_DELETE(ms_dictionary);
			ms_dictionary = 0;
		}

#endif//#if BEHAVIAC_STRINGID_USESTRINGCONTENT

		CPathID::ClearDictionary();
	}
Пример #9
0
XmlParserImp::~XmlParserImp()
{
    BEHAVIAC_FREE(m_buffer);
}