예제 #1
0
파일: zipchar.cpp 프로젝트: bblu/algocpp
char* zipChar(const char* str){

	int len = strlen(str);
	printf("strlen = %d\n",len);

	char* buf= new char[len];
	strcpy(buf,str);
	printf("init buf is %s\n",buf);
	char cur=str[0];
	int num=1;
	int itr=0;
	for(int i = 1; i < len; i++){
		char nex = str[i];
		if(cur==nex)
			num++;
		else
		{
			buf[itr++]=cur;
			appendNum(buf,itr,num);
			//printf("num=%d, buf=%s cur=%s\n",num,buf,&cur);
			if(itr>=len)
				return strcpy(buf,str);
			cur = nex;
			num = 1;
		}
	}
	if(cur){
		buf[itr++]=cur;
		appendNum(buf,itr,num);
		//printf("num=%d, buf=%s,cur=%s\n",num,buf,&cur);
	}
	buf[itr]=0;
	return buf;
}
예제 #2
0
QString JsonPin::toString(){
    QString str;
    str="{\n";
    str+=appendString("Id")+":"+appendNum(Id)+",\n";
    str+=appendString("Name")+":"+appendString(Name)+",\n";
    str+=appendString("Desc")+":"+appendString(Desc)+",\n";
    str+=appendString("DataType")+":"+appendString(DataType)+",\n";
    str+=appendString("InputPin")+":"+appendBool(InputPin);
    str+="\n}";
    return str;
}
예제 #3
0
QString JsonModule::toString(){
    QString str;
    str="{\n";
    str+=appendString("Id")+":"+appendNum(Id)+",\n";
    str+=appendString("Name")+":"+appendString(Name)+",\n";
    str+=appendString("InPins")+":"+appendStringList(InPins)+",\n";
    str+=appendString("OutPins")+":"+appendStringList(OutPins)+",\n";
    str+=appendString("Function")+":"+appendString(Function);
    str+="\n}";
    return str;
}
예제 #4
0
bool Numkey::checkTouch(Point* p){
	int boundX1, boundX2, boundY1, boundY2;
	int btnWidth = w/3;
	int btnHeight = h/5;
	bool pressed = false;
	if(lastMillis + debounceTime < millis()){ 
		if((p->x > x+borderWidth) && (p->x < x+w-borderWidth) && (p->y > y+borderWidth) && (p->y < y+h-borderWidth)){
			//backspace coordinates
			boundX1 = x+btnWidth*2;
			boundX2 = x+w;
			boundY1 = y+borderWidth;
			boundY2 = y+btnHeight;
			if((p->x > boundX1) && (p->x < boundX2) && (p->y > boundY1) && (p->y < boundY2)){
				deleteChar();
				pressed = true;
			}
			//num coordinates
			for(int r = 1;(r <= 4)&&(!pressed); r++)
			{
				boundY1 = y+(btnHeight)*r+borderWidth;
				boundY2 = y+(btnHeight)*(r+1)-borderWidth;
				for(int c = 1;(c <= 3)&&(!pressed);c++)
				{
					boundX1 = x + (btnWidth)*(c-1) + borderWidth;
					boundX2 = x + (btnWidth)*c - borderWidth;
					int num = 3*(r - 1) + c;
					if((p->x > boundX1) && (p->x < boundX2) && (p->y > boundY1) && (p->y < boundY2)){
						if(num==11){
							num = 0;
						}
						if(num==10){
							append(".");
						}else if(num==12){
							eventHandler(this);		// <<<------ Event handler called when = signed is pressed
							if(autoremove){
								if(myCanvas->widgets.peek() == this){ // check if top widget is this numkey
									myCanvas->pop();						// Remove this numkey from the canvas...
								}
							}
						}else{
							appendNum(char(num));//setNum(num);
						}
						pressed = true;
					}
				}// -- columns for loop
			}// --rows for loop
		}// -- if touch within widget area
		touched = !touched;
		lastMillis = millis();		
	}// -- debounce
	return false;
}
예제 #5
0
/*复制瓶罐<重载函数,在读取地图配置文件里面用>*/
Bottle* Bottle::copyBottle(Point _pt)
{
	char _id[MONSTER_MID_LENGTH + 1] = {'\0'};	
	Bottle* newBottle;	
	newBottle = new Bottle(typeId,lifeVal,hurt,brushStyle,bloodPre,magicPre,name,dropNum,dropStage,photoId);
	
	strncpy(_id,typeId,strlen(typeId));
	strncat(_id,"_",strlen("_"));	
	
	count++;
	appendNum(_id,count,4);		
	
	newBottle->setPiexPt(_pt);
	newBottle->setInstId(_id);
	
	return newBottle;
}
예제 #6
0
//-------------------------------------------------------------------------
DcMidiData::DcMidiData(const qint32 data)
    : _ts(0), _srcDevice(0)
{
    appendNum(data);
}
예제 #7
0
//-------------------------------------------------------------------------
void DcMidiData::setText( const char* data )
{
    clear();

    QString str = QString(QByteArray(data));

    str = str.trimmed();
    int len = str.length();

    if(len < 2)
        return;

    QStringList strList;

    if( str.count(" ") || str.count(","))
    {
        strList = str.split(QRegExp("[ ,]+"));
    }
    else
    {
        // At this point, 'str' holds a string like this: 0x1234 or F06677AA
        // Check for the '0x' string, then the non-delim/non-0x string.
        // Assume all strings passed in as char* must be hex

        if(is0xHexStr(str))
        {
            strList.append(str);
        }
        else
        {
            // For a legal hex midi string without spaces, it must be
            // divisible by 2
            if((str.length()%2) != 0)
            {
                qDebug() << "DcMidiData::DcMidiData(const char*,int) - invalid hex string format: " << str;
            }
            else
            {
                for (int idx = 0; idx < str.length() ; idx++)
                {
                    QString tstr;
                    tstr.append(str[idx++]);
                    tstr.append(str[idx]);
                    strList.append(tstr);
                }
            }
        }
    }
    // Convert the string to hex
    foreach(QString s, strList)
    {
        if(s.isEmpty())
            continue;

        bool ok = true;
        int x = s.toInt(&ok,16);
        if(!ok)
        {
            qDebug() << "DcMidiData::DcMidiData(const char*,int) - error converting hex string: " << str;
        }
        else
        {
            if(!appendNum(x))
                break;
        }
    }
}