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]);
};
Beispiel #2
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 #3
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 #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.
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 #5
0
void add(strArray &a, const strArray &b)
{
	for (int i = 0; i < b.size(); i ++)
		a.push_back(b[i]);
};
Beispiel #6
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");
};