Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*TELCOSHELL.H*/
- #ifndef MAINSHELL_H_INCLUDED
- #define MAINSHELL_H_INCLUDED
- //convertir char a string
- string convert_to_string(char *valor)
- {
- int i;
- string kms="";
- int size = strlen(valor);
- for(i=0;i<size;i++)
- {
- kms+=valor[i];
- }
- return kms;
- }
- string get_command(string cmd,string delimit,int limit,int init)
- {
- int i=0;
- int tam = cmd.length();
- int count=0;
- for(i=0;i<tam;i++)
- {
- if(cmd.substr(i,1)==delimit)
- {
- count++;
- if(count>=limit){return cmd.substr(init,i);}
- }
- }
- }
- //obtener las variables separadas por delimitadores
- string get_word(string key,int lim)
- {
- int i;
- int tam = key.length();
- int count_limit=0;
- string word;
- for(i=0;i<tam;i++)
- {
- if(key.substr(i,1)!=",")
- {
- if(count_limit==lim)
- {
- word+=key.substr(i,1);
- }
- }
- if(count_limit>lim){return word;}
- if(key.substr(i,1)==",")
- {
- count_limit++;
- }
- }
- }
- //obtener el valor cerrado entre limitadores
- string get_key(string ksm,string delimit)
- {
- string values;
- int i = 0;
- int limit, tam=0;
- bool key_in=false;
- while(ksm.substr(i,1)!=delimit.substr(1,1))
- {
- i++;
- if(ksm.substr(i,1)==delimit.substr(0,1))
- {
- limit=i+1;
- key_in=true;
- }
- else
- {
- if(key_in == true){tam++;}
- }
- }
- return ksm.substr(limit,tam-1);
- }
- /* main.h
- int main()
- {
- contact c;
- string primary_cmd,secondary_cmd,thrd_cmd;
- //string ksm="customer -add (emmanuel,breyaue,eva peron 874,1,1,1122982222,0)";
- //string ksm="customer -edit 1 (jose,breyaue,eva peron,222,1,2,111111111,0)";
- string ksm="customer -delete 1";
- //string ksm="customer -search %jose%breyaue%";
- primary_cmd = get_command(ksm," ",2,0);
- secondary_cmd = get_command(primary_cmd," ",1,0);
- //thrd_cmd=get_command(secondary_cmd," ",1,0);
- cout<<secondary_cmd<<endl;
- cout<<get_command(primary_cmd," ",1,secondary_cmd.length()+1)<<endl;
- //obtener el tercer elemento
- //cout<<get_command(secondary_cmd," ",1,thrd_cmd.length())<<endl;
- //cout<<get_word(get_key(ksm,"()"),3)<<endl;
- //cout<<get_word(get_key(ksm,"()"),4);
- return 0;
- }
- */
- #endif //MAINSHELL_H_INCLUDED
Add Comment
Please, Sign In to add comment