pampa_rider

prompt separator

Mar 11th, 2021 (edited)
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. /*TELCOSHELL.H*/
  2.  
  3. #ifndef MAINSHELL_H_INCLUDED
  4. #define MAINSHELL_H_INCLUDED
  5.  
  6. //convertir char a string
  7. string convert_to_string(char *valor)
  8. {
  9. int i;
  10. string kms="";
  11. int size = strlen(valor);
  12.  
  13. for(i=0;i<size;i++)
  14. {
  15. kms+=valor[i];
  16. }
  17. return kms;
  18. }
  19.  
  20.  
  21.  
  22.  
  23. string get_command(string cmd,string delimit,int limit,int init)
  24. {
  25.  
  26. int i=0;
  27. int tam = cmd.length();
  28. int count=0;
  29.  
  30.     for(i=0;i<tam;i++)
  31.     {
  32.     if(cmd.substr(i,1)==delimit)
  33.     {
  34.     count++;   
  35.     if(count>=limit){return cmd.substr(init,i);}
  36.  
  37.     }
  38.     }  
  39.    
  40. }
  41.  
  42.  
  43. //obtener las variables separadas por delimitadores
  44. string get_word(string key,int lim)
  45. {
  46. int i;
  47. int tam = key.length();
  48. int count_limit=0;
  49. string word;
  50.  
  51.     for(i=0;i<tam;i++)
  52.     {
  53.        
  54.     if(key.substr(i,1)!=",")
  55.     {
  56.         if(count_limit==lim)
  57.         {
  58.         word+=key.substr(i,1); 
  59.         }
  60.    
  61.     }
  62.  
  63.    
  64.     if(count_limit>lim){return word;}
  65.     if(key.substr(i,1)==",")
  66.     {
  67.     count_limit++;
  68.     }
  69.            
  70.     }  
  71.  
  72. }
  73.  
  74. //obtener el valor cerrado entre limitadores
  75. string get_key(string ksm,string delimit)
  76. {
  77.  
  78. string values;
  79.  
  80. int i = 0;
  81. int limit, tam=0;
  82. bool key_in=false;
  83.    
  84. while(ksm.substr(i,1)!=delimit.substr(1,1))
  85. {
  86. i++;
  87.    
  88.     if(ksm.substr(i,1)==delimit.substr(0,1))
  89.     {
  90.     limit=i+1;
  91.     key_in=true;
  92.     }
  93.    
  94.     else
  95.     {
  96.     if(key_in == true){tam++;}
  97.     }
  98.  
  99.    
  100. }
  101. return ksm.substr(limit,tam-1);
  102. }
  103.  
  104. /* main.h
  105. int main()
  106. {
  107. contact c;
  108. string primary_cmd,secondary_cmd,thrd_cmd;
  109.  
  110.  
  111. //string ksm="customer -add (emmanuel,breyaue,eva peron 874,1,1,1122982222,0)";
  112. //string ksm="customer -edit 1 (jose,breyaue,eva peron,222,1,2,111111111,0)";
  113. string ksm="customer -delete 1";
  114. //string ksm="customer -search %jose%breyaue%";
  115.  
  116. primary_cmd = get_command(ksm," ",2,0);
  117. secondary_cmd = get_command(primary_cmd," ",1,0);
  118. //thrd_cmd=get_command(secondary_cmd," ",1,0);
  119.  
  120.  
  121. cout<<secondary_cmd<<endl;
  122. cout<<get_command(primary_cmd," ",1,secondary_cmd.length()+1)<<endl;
  123.  
  124. //obtener el tercer elemento
  125. //cout<<get_command(secondary_cmd," ",1,thrd_cmd.length())<<endl;
  126.  
  127. //cout<<get_word(get_key(ksm,"()"),3)<<endl;
  128. //cout<<get_word(get_key(ksm,"()"),4);
  129. return 0;
  130. }
  131. */
  132.  
  133.  
  134. #endif //MAINSHELL_H_INCLUDED
Add Comment
Please, Sign In to add comment