Exemplo n.º 1
0
		//it returns true if 'str' starts with a count followed by ':'
		//3:{....}
		bool IsArrayString(const behaviac::string& str, int posStart, behaviac::string::size_type& posEnd)
		{
			//begin of the count of an array?
			//int posStartOld = posStart;

			bool bIsDigit = false;

			int strLen = (int)str.size();
			while (posStart < strLen)
			{
				char c = str[posStart++];

				if (isdigit(c))
				{
					bIsDigit = true;
				}
				else if (c == ':' && bIsDigit)
				{
					//transit_points = 3:{coordX = 0; coordY = 0; } | {coordX = 0; coordY = 0; } | {coordX = 0; coordY = 0; };
					//skip array item which is possible a struct
					int depth = 0;
					for (int posStart2 = posStart; posStart2 < strLen; posStart2++)
					{
						char c1 = str[posStart2];

						if (c1 == ';' && depth == 0)
						{
							//the last ';'
							posEnd = posStart2;
							break;
						}
						else if (c1 == '{')
						{
							BEHAVIAC_ASSERT(depth < 10);
							depth++;
						}
						else if (c1 == '}')
						{
							BEHAVIAC_ASSERT(depth > 0);
							depth--;
						}
					}
					
					return true;
				}
				else
				{
					break;
				}
			}

			return false;
		}
Exemplo n.º 2
0
        /// convert multibyte string to wide char string
        bool MBSToWCS(behaviac::wstring& resultString, const behaviac::string& str, const char* locale)
        {
            BEHAVIAC_UNUSED_VAR(resultString);
            BEHAVIAC_UNUSED_VAR(str);
            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 = MultiByteToWideChar(cp, 0, str.c_str(), -1, 0, 0);
            wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum * 2 + 2, "MBSToWCS");

            if (buffer)
            {
                MultiByteToWideChar(cp, 0, str.c_str(), -1, buffer, dwNum);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);

                ret = true;
            }

#else
            uint32_t dwNum = (str.size() + 1) * 4;
            wchar_t* buffer = (wchar_t*)BEHAVIAC_MALLOC_WITHTAG(dwNum, "MBSToWCS");

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

                char* loc = setlocale(LC_ALL, locale);

                if (loc)
                {
                    mbstowcs(buffer, str.c_str(), dwNum);
                    ret = true;
                }

                //restore
                setlocale(LC_ALL, currrentLocale);

                resultString = buffer;
                BEHAVIAC_FREE(buffer);
            }

#endif//#if BEHAVIAC_COMPILER_MSVC

            return ret;
        }
Exemplo n.º 3
0
    //suppose params are seprated by ','
    static void ParseForParams(const behaviac::string& tsrc, behaviac::vector<behaviac::string>& params)
    {
        int tsrcLen = (int)tsrc.size();
        int startIndex = 0;
        int index = 0;
        int quoteDepth = 0;

        for (; index < tsrcLen; ++index)
        {
            if (tsrc[index] == '"')
            {
                quoteDepth++;

                //if (quoteDepth == 1)
                //{
                //	startIndex = index;
                //}

                if ((quoteDepth & 0x1) == 0)
                {
                    //closing quote
                    quoteDepth -= 2;
                    BEHAVIAC_ASSERT(quoteDepth >= 0);
                }
            }
            else if (quoteDepth == 0 && tsrc[index] == ',')
            {
                //skip ',' inside quotes, like "count, count"
                int lengthTemp = index - startIndex;
                behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
                params.push_back(strTemp);
                startIndex = index + 1;
            }
        }//end for

        // the last param
        int lengthTemp = index - startIndex;

        if (lengthTemp > 0)
        {
            behaviac::string strTemp = tsrc.substr(startIndex, lengthTemp);
            params.push_back(strTemp);

            //params.push_back(strTemp);
        }
    }