Changeset 558

Show
Ignore:
Timestamp:
08/24/07 01:33:45 (16 years ago)
Author:
wagi
Message:

tokinize input (WIP)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/genericavc/avc_vendormodel.cpp

    r557 r558  
    2727#include <istream> 
    2828#include <iostream> 
     29#include <iterator> 
     30 
     31using namespace std; 
     32 
     33static void 
     34tokenize(const string& str, 
     35         vector<string>& tokens, 
     36         const string& delimiters = " ") 
     37{ 
     38    // Skip delimiters at beginning. 
     39    string::size_type lastPos = str.find_first_not_of(delimiters, 0); 
     40    // Find first "non-delimiter". 
     41    string::size_type pos     = str.find_first_of(delimiters, lastPos); 
     42 
     43    while (string::npos != pos || string::npos != lastPos) 
     44    { 
     45        // Found a token, add it to the vector. 
     46        tokens.push_back(str.substr(lastPos, pos - lastPos)); 
     47        // Skip delimiters.  Note the "not_of" 
     48        lastPos = str.find_first_not_of(delimiters, pos); 
     49        // Find next "non-delimiter" 
     50        pos = str.find_first_of(delimiters, lastPos); 
     51    } 
     52} 
    2953 
    3054GenericAVC::VendorModel::VendorModel( const char* filename ) 
    3155{ 
    32     using namespace std; 
    33  
    34     cout << "XXX GenericAVC::VendorModel::VendorModel" << endl; 
    35  
    3656    ifstream in ( filename ); 
    3757 
     
    4161    } 
    4262 
     63    cout << "vendorId\t\tmodelId\t\tvendorName\t\tmodelName" << endl; 
    4364    string line; 
    4465    while ( !getline( in,  line ).eof() ) { 
     66        string::size_type i = line.find_first_not_of( " \t\n\v" ); 
     67        if ( i != string::npos && line[i] == '#' ) 
     68            continue; 
    4569 
     70        vector<string> tokens; 
     71        tokenize( line, tokens, "," ); 
    4672 
     73        for ( vector<string>::iterator it = tokens.begin(); 
     74              it != tokens.end(); 
     75              ++it ) 
     76        { 
     77            string vendorId = *it++; 
     78            string modelId = *it++; 
     79            string vendorName = *it++; 
     80            string modelName= *it; 
     81            cout << vendorId << "\t" << modelId << "\t" <<vendorName << "\t" << modelName << endl; 
     82        } 
     83    } 
     84 
     85    if ( !in.eof() ) { 
     86        cout << "GenericAVC::VendorModel::VendorModel: error in parsing" << endl; 
    4787    } 
    4888}