Beispiel #1
0
void mult(strArray &a, strArray &b)
{
	strArray c(a); a.clear();
	for (int i = 0; i < c.size(); i ++)
		for (int j = 0; j < b.size(); j ++)
			a.push_back(c[i] + b[j]);
};
// string toolkit
static inline void split(std::string src, const char* token, strArray& vect)
{
    int nend=0;
    int nbegin=0;
    while(nend != -1)
    {
        nend = src.find(token, nbegin);
        if(nend == -1)
            vect.push_back(src.substr(nbegin, src.length()-nbegin));
        else
            vect.push_back(src.substr(nbegin, nend-nbegin));
        nbegin = nend + strlen(token);
    }
}
Beispiel #3
0
// string toolkit
static inline void split(const std::string& src, const std::string& token, strArray& vect)
{
    size_t nend = 0;
    size_t nbegin = 0;
    size_t tokenSize = token.size();
    while(nend != std::string::npos)
    {
        nend = src.find(token, nbegin);
        if(nend == std::string::npos)
            vect.push_back(src.substr(nbegin, src.length()-nbegin));
        else
            vect.push_back(src.substr(nbegin, nend-nbegin));
        nbegin = nend + tokenSize;
    }
}
Beispiel #4
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
// 首先,判断表格的字符串是否为{x,y}
// 是,则使用分裂字符串到参数strs
// 否则参数strs为空;
// 表格是对的,则返回true
static bool splitWithForm(const char* pStr, strArray& strs)
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(!pStr);

        // string is empty
        // 字符串为空
        std::string content = pStr;
        CC_BREAK_IF(content.length() == 0);

        int nPosLeft  = content.find('{');
        int nPosRight = content.find('}');

        // don't have '{' and '}'
        // 不含有{}
        CC_BREAK_IF(nPosLeft == (int)std::string::npos || nPosRight == (int)std::string::npos);
        // '}' is before '{'
        // }在{前
        CC_BREAK_IF(nPosLeft > nPosRight);

        std::string pointStr = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1);
        // nothing between '{' and '}'
        // 在{}之前没有任何参数
        CC_BREAK_IF(pointStr.length() == 0);

        int nPos1 = pointStr.find('{');
        int nPos2 = pointStr.find('}');
        // contain '{' or '}' 
        // 包含{}
        CC_BREAK_IF(nPos1 != (int)std::string::npos || nPos2 != (int)std::string::npos);

        split(pointStr, ",", strs);
        if (strs.size() != 2 || strs[0].length() == 0 || strs[1].length() == 0)
        {
            strs.clear();
            break;
        }

        bRet = true;
    } while (0);

    return bRet;
}
Beispiel #5
0
bool trans(int l, int r, strArray &a)
{
	int i = l, ope = 1, j;
	strArray b, c, d;
	string s;
	a.clear();	
	if (l > r) {
		a.push_back("");
		return 1;
	};
	while (i <= r)
	{
		if (st[i] == '+')
		{
			if (ope) return 0;
			ope = 1; ++i;
		} 
		else {
			if (!ope || (st[i] < 'a' || st[i] > 'z') && st[i] != '(') return 0;
			b.clear(); b.push_back("");
			while (i <= r && (st[i] >= 'a' && st[i] <= 'z' || st[i] == '(')) 
			{
				if (st[i] == '(')
				{
					if (!findEnd(i, j, r)) return 0;
					if (!trans(i + 1, j - 1, c)) return 0;
					i = j + 1;
				}
				else {
					s = "";
					while (i <= r && st[i] >= 'a' && st[i] <= 'z') s += st[i ++];
					c.clear(); c.push_back(s);
				};
				if (c.empty()) return 0;
				mult(b, c);
			};
			if (b.size() == 1 && b[0] == "") continue;
			add(a, b); ope = 0;
		};
	};
	if (ope && !a.empty()) return 0;
	return 1;
};
Beispiel #6
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
static KDbool splitWithForm ( const KDchar* szString, strArray& vStrings )
{
	KDbool  bRet = KD_FALSE;

    do 
    {
        CC_BREAK_IF ( !szString );

        // string is empty
        std::string   sContent = szString;
        CC_BREAK_IF ( sContent.length ( ) == 0 );

        KDuint  nPosLeft  = sContent.find ( '{' );
        KDuint  nPosRight = sContent.find ( '}' );

        // don't have '{' and '}'
        CC_BREAK_IF ( nPosLeft == std::string::npos || nPosRight == std::string::npos );
        // '}' is before '{'
        CC_BREAK_IF ( nPosLeft > nPosRight );

        std::string   sPointStr = sContent.substr ( nPosLeft + 1, nPosRight - nPosLeft - 1 );
        // nothing between '{' and '}'
        CC_BREAK_IF ( sPointStr.length ( ) == 0 );

        KDuint  nPos1 = sPointStr.find ( '{' );
        KDuint  nPos2 = sPointStr.find ( '}' );
        // contain '{' or '}' 
        CC_BREAK_IF ( nPos1 != std::string::npos || nPos2 != std::string::npos );

        split ( sPointStr, ",", vStrings );
        if ( vStrings.size ( ) != 2 || vStrings [ 0 ].length ( ) == 0 || vStrings [ 1 ].length ( ) == 0 )
        {
            vStrings.clear ( );
            break;
        }

        bRet = KD_TRUE;

    } while ( 0 );

    return bRet;
}
Beispiel #7
0
// string toolkit
static KDvoid split ( std::string sString, const KDchar* szToken, strArray& vStrings )
{
	KDint  nEnd   = 0;
	KDint  nBegin = 0;

	while ( nEnd != -1 )
	{
		nEnd = sString.find ( szToken, nBegin );

		if ( nEnd == -1 )
		{
			vStrings.push_back ( sString.substr ( nBegin, sString.length ( ) - nBegin ) );
		}
		else
		{
			vStrings.push_back ( sString.substr ( nBegin, nEnd - nBegin ) );
		}

		nBegin = nEnd + kdStrlen ( szToken );
	}
}
Beispiel #8
0
// first, judge whether the form of the string like this: {x,y}
// if the form is right,the string will be split into the parameter strs;
// or the parameter strs will be empty.
// if the form is right return true,else return false.
static bool splitWithForm(const std::string& content, strArray& strs)
{
    bool bRet = false;

    do 
    {
        CC_BREAK_IF(content.empty());

        size_t nPosLeft  = content.find('{');
        size_t nPosRight = content.find('}');

        // don't have '{' and '}'
        CC_BREAK_IF(nPosLeft == std::string::npos || nPosRight == std::string::npos);
        // '}' is before '{'
        CC_BREAK_IF(nPosLeft > nPosRight);

        const std::string pointStr = content.substr(nPosLeft + 1, nPosRight - nPosLeft - 1);
        // nothing between '{' and '}'
        CC_BREAK_IF(pointStr.length() == 0);

        size_t nPos1 = pointStr.find('{');
        size_t nPos2 = pointStr.find('}');
        // contain '{' or '}' 
        CC_BREAK_IF(nPos1 != std::string::npos || nPos2 != std::string::npos);

        split(pointStr, ",", strs);
        if (strs.size() != 2 || strs[0].length() == 0 || strs[1].length() == 0)
        {
            strs.clear();
            break;
        }

        bRet = true;
    } while (0);

    return bRet;
}
Beispiel #9
0
void add(strArray &a, const strArray &b)
{
	for (int i = 0; i < b.size(); i ++)
		a.push_back(b[i]);
};
Beispiel #10
0
void print(strArray &answer)
{
	if (answer.size()) printf("%s", answer[0].c_str());
	for (int i = 1; i < answer.size(); i++) printf("+%s", answer[i].c_str());
	printf("\n");
};