예제 #1
0
/**********************************
*func name:
*function:
*parameters:
*call:
*called:
*return:
*/
void trim(char *src)
{
    char *s = src;
    
    left_trim(s);
    right_trim(s);
}
예제 #2
0
static char*
get_http_header_alloc(const char* ptr, const char* key) {
  if (!ptr || !key) return NULL;

  const size_t key_length = strlen(key);
  const char* term;
  for (; *ptr && (term = strpbrk(ptr, "\r\n")); ptr = term + 1) {
    if (ptr[key_length] == ':' && !strncasecmp(ptr, key, key_length))
      break;
  }
  const char* const top = left_trim(ptr + key_length + 1);
  return top ? strndup(top, (size_t) (term - top)) : NULL;
}
예제 #3
0
/*
 * func:clear left and right space.
 */
char * both_trim(char * szOutput, const char * szInput)
{
    char *p = NULL;

    if (szInput == NULL || szOutput == NULL) {
        return NULL;
    }

    if (left_trim(szOutput, szInput) == NULL) {
        return NULL;
    }

    for (p = szOutput + strlen(szOutput) - 1;p >= szOutput && isspace(*p); --p){
     ;
    }
    *(++p) = '\0';

    return szOutput;
}
예제 #4
0
std::string trim(std::string s) {
  left_trim(s);
  right_trim(s);
  return s;
}
예제 #5
0
std::string left_trim(const char * src) {
  std::string tmp(src);
  return left_trim(tmp);
}
예제 #6
0
void SmDataDBFFormat::print_field_information(int record_num)
{
    if (record_num>num_of_records_)
    {
        QMessageBox::information(this,"Error","This is not a valid record Number....Try again");
//      std::cout<<"This is not a valid record Number....Try again"<<std::endl;
        return;
    }
    if (record_num==0)
    {


        for (int i=0;i<num_of_field_;i++)
        {
//            std::cout<<"************************"<<std::endl;
//            std::cout<<"Field Name is : "<<field_descriptor_[i].field_name_<<std::endl;
            QTableWidgetItem* tab_item=new QTableWidgetItem();
            tab_item->setText(QString(field_descriptor_[i].field_name_.c_str()));
            identify_table_->setItem(i,0,tab_item);
//            std::cout<<"field Type is : "<<get_data_field_type(field_descriptor_[i].field_type_)<<std::endl;
//            std::cout<<"Field Length is : "<<field_descriptor_[i].field_length_<<std::endl;
//            std::cout<<"***********************"<<std::endl;
        }
    }
    else
    {
        //record number is not 0
        in_file_->seekg(num_of_byte_header_+((record_num-1)*record_length_in_byte_)
                        ,std::ios::beg);
        unsigned char * record_buffer=new unsigned char[record_length_in_byte_];
        in_file_->read((char *)record_buffer,record_length_in_byte_);
        if(record_buffer[0]==RECORD_IS_DELETED)
        {
            std::cout<<"This Record is Deleted"<<std::endl;
            return;
        }
        else
        {
            int temp=0;
            int buffer_offset=0;
            buffer_offset++;
            std::string temp_buffer="";

            while(temp<num_of_field_)
            {
                for(int i=0;i<field_descriptor_[temp].field_length_;i++)
                {
                    temp_buffer+=record_buffer[buffer_offset];
                    buffer_offset++;
                }
//                std::cout<<left_trim(temp_buffer);
                QTableWidgetItem* tab_item=new QTableWidgetItem();
                tab_item->setText(QString(left_trim(temp_buffer).c_str()));
                identify_table_->setItem(temp,1,tab_item);
//                std::cout<<"  ";
                temp_buffer="";
                temp++;
            }
        }

    }
}
예제 #7
0
/*
 * func:读取配置文件中的键值,没有section字段分布
 * argu:
 *      value   store result 
 */
int get_value_by_key(FILE *fp, char *key, char *value)
{
    char        keyname[32];
    char        *buf = NULL, *pos = NULL;
    char        *temp = NULL, *tempValue = NULL;
    char        buf_i[KEYVALLEN], buf_o[KEYVALLEN];

    if (fp == NULL || key == NULL || value == NULL) {
        return -1;
    }
    
    /* init */
    fseek(fp, 0, SEEK_SET);
    buf_i[0] = '\0';
    buf_o[0] = '\0';
    temp = value;

    /* main loop */
    while (!feof(fp) && fgets(buf_i, KEYVALLEN, fp) != NULL) {
        if (left_trim(buf_o, buf_i) == NULL) {
            printf("ReadConfig:Call left_trim return illegal value.\n");
            return -1;
        }
        // space line
        if (strlen(buf_o) <= 0) {
            continue;
        }

        buf = NULL;
        buf = buf_o;

        if (buf[0] == '#') {            //comments line
            continue;
        } else if (buf[0] == '[') {   // illegal keyname
            printf("ReadConfig:Illegal format line.\n");
            break;
        } else {
            // get left value of '='
            if ((pos = (char*)strchr(buf, '=')) == NULL) {
                continue;               // value are too long
            }

            // handle left value of '='
            if (get_specified_sring(buf, keyname, "\t =") < 0) {
                printf("ReadConfig:call get_specified_sring failed.\n");
                break;
            }

            // handle right value of '=' when find correct keyname
            if (strcmp(keyname, key) == 0) {
                if (get_specified_sring(++pos, temp, "\n") < 0) {
                    printf("ReadConfig:call get_specified_sring failed.\n");
                    break;
                }
                tempValue = (char *)malloc(strlen(temp) + 1);
                if (tempValue == NULL) {
                    printf("ReadConfig:lack of memory.\n");
                    break;
                }
                memset(tempValue, 0, sizeof(tempValue));

                // delete space 
                if (both_trim(tempValue, temp) == NULL) {
                    printf("ReadConfig:Call both_trim return illegal value.\n");
                    return -1;
                }
                if (strlen(tempValue) > 0) {
                    strcpy(value, tempValue);
                }
                free(tempValue);
                tempValue = NULL;
                return 0;
            }
        }
    }//while

    return -1;
}
예제 #8
0
/*                                                                          
 * func:get value by key and section                                        
 * argu:                                                                    
 *      value   store result                                                
 */                                                                         
int section_get_value_by_key(FILE *fp, char *section, char *key, char *value )    
{                                                                           
    char appname[32],keyname[32];                                           
    char *buf,*c;                                                           
    char buf_i[KEYVALLEN], buf_o[KEYVALLEN];                                
    int found=0; /* 1 section 2 key */                                      
                                                                            
    if ( fp == NULL || section == NULL || key == NULL || value == NULL ) {  
        return -1;                                                          
    }                                                                       
                                                                            
    fseek( fp, 0, SEEK_SET );                                               
    memset( appname, 0, sizeof(appname) );                                  
    sprintf( appname,"[%s]", section );                                     
                                                                            
    while( !feof(fp) && fgets(buf_i, KEYVALLEN, fp )!=NULL ){               
        if (left_trim(buf_o, buf_i) == NULL) {                              
            return -1;                                                      
        }                                                                   
        if (strlen(buf_o) <= 0) {                                           
            continue;                                                       
        }                                                                   
                                                                            
        buf = buf_o;                                                        
                                                                            
        if( found == 0 ){                                                   
            if( buf[0] != '[' ) {                                           
                continue;                                                   
            } else if ( strncmp(buf,appname,strlen(appname))==0 ){                     
                found = 1;                                                             
                continue;                                                              
            }                                                                          
                                                                                       
        } else if( found == 1 ) {                                                      
            if( buf[0] == '#' ){                                                       
                continue;                                                              
            } else if ( buf[0] == '[' ) {                                              
                break;                                                                 
            } else {                                                                   
                if( (c = (char*)strchr(buf, '=')) == NULL )                            
                    continue;                                                          
                                                                                       
                memset( keyname, 0, sizeof(keyname) );                                 
                get_specified_sring(buf, keyname, "\t =");                             
                if (strcmp(keyname, key) == 0) {                                       
                    get_specified_sring(++c, value, "\n");                             
                    //sscanf( ++c, "%[^\n]", value );                                  
                    char *value_o = (char *)malloc(strlen(value) + 1);                 
                    if(value_o != NULL){                                               
                        memset(value_o, 0, strlen(value) + 1);                         
                        // delete space                                                
                        if (both_trim(value_o, value) == NULL) {                       
                            return -1;                                                 
                        }                                                              
                        if(value_o && strlen(value_o) > 0)                             
                            strcpy(value, value_o);                                    
                        free(value_o);                                                 
                        value_o = NULL;                                                
                    }                                                                  
                    found = 2;                                                         
                    break;                                                             
                } else {                                                               
                    continue;                       
                }                                   
            }                                       
        }//if-else if- else                         
    }//while                                        
                                                    
    if( found == 2 ) {                              
        return 0;                                   
    }                                               
    return -1;                                      
}