int main()
{
	int menu_choice=0;
	AddressBook personal;
	
	while(menu_choice!=4)
	{
		cout << "What would you like to do?" << endl;
		cout << "1) Add a contact" << endl;
		cout << "2) Search for a contact" << endl;
		cout << "3) Display all contacts" << endl;
		cout << "4) Exit program" << endl;
		cout << "Please enter your choice: ";
		cin >> menu_choice;
		if(menu_choice<1 || menu_choice>4)
		{
			cout << "Error Invalid Input" << endl;
			menu_choice=0;
		}
		if(menu_choice==1)
		{
			AddToBook(personal);
		}
		if(menu_choice==2)
		{
			Search(personal);
		}
		if(menu_choice==3)
		{
			personal.displayContacts();
		}
	}

	return 0;
}
Example #2
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    AddressBook w;
    w.show();
    return a.exec();
}
int main6()
{
#if 0
  // read in the name from a user, which we want to search

  cout << " enter name";
  string name;
  cin>> name;

 
  // change 'findMatchingAddress' to 'find'
  // notice that the lambda function uses the the variable 'name'
  // global_address_book.findMatchingAddresses ( [&] (const string& addr) { return addr.find( name ) != string::npos; } );
  global_address_book.find ( [&] (const string& addr) { return addr.find( name ) != string::npos; } );
  //  error: ‘class AddressBook’ has no member named ‘find’
  //  global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
  //                      ^

  int min_len = 0;
  cout << " enter min_len";
  cin >> min_len;

  // change 'findMatchingAddress' to 'find'
  global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
  //  error: ‘class AddressBook’ has no member named ‘find’
  //  global_address_book.find( [&] (const string& addr) { return addr.length() >= min_len; } );
  //                      ^

  cout << "\n";
#endif
  return 0;
} // main6
Example #4
0
File: write.cpp Project: skhal/Cpp
void print(AddressBook &book)
{
    for(AddressBook::const_iterator person = book.begin();
            book.end() != person;
            ++person)
    {
        cout << "Person ID: " << person->id() << endl;
        cout << "     Name: " << person->name() << endl;
        cout << "    Email: " << person->email() << endl;

        for(uint32_t j = 0, size = person->phones_size(); size > j; ++j)
        {
            const Phone *phone = person->phone(j);

            switch (phone->type())
            {
                case Phone::MOBILE:
                    cout << "Mobile phone #: ";
                    break;

                case Phone::HOME:
                    cout << "  Home phone #: ";
                    break;

                case Phone::WORK:
                    cout << "  Work phone #: ";
                    break;
            }

            cout << phone->number() << endl;
        }
        cout << endl;
    }
}
Example #5
0
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    //QMainW
    AddressBook addressBook;
    addressBook.show();

    return a.exec();
}
Example #6
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    AddressBook *addressBook = new AddressBook;
    addressBook->show();

    return app.exec();
}
Example #7
0
int main( int argc, char **argv )
{
  KAboutData aboutData( "bigwrite", 0, ki18n( "BigWriteKabc" ), "0.1" );
  KCmdLineArgs::init( argc, argv, &aboutData );

  KApplication app( false );

  AddressBook ab;
  ResourceFile r( QLatin1String( "my.kabc" ), QLatin1String( "vcard" ) );
  ab.addResource( &r );

  for ( int i = 0; i < 5000; ++i ) {
    Addressee a;
    a.setGivenName( QLatin1String( "number" ) + QString::number( i ) );
    a.setFamilyName( QLatin1String( "Name" ) );
    a.insertEmail( QString::number( i ) + QLatin1String( "@domain" ) );

    ab.insertAddressee( a );
  }
  printf( "\n" );

  Ticket *t = ab.requestSaveTicket( &r );
  if ( t ) {
    struct tms start;

    times( &start );

#if 0
    kDebug() << "utime :" << int( start.tms_utime );
    kDebug() << "stime :" << int( start.tms_stime );
    kDebug() << "cutime:" << int( start.tms_cutime );
    kDebug() << "cstime:" << int( start.tms_cstime );
#endif

    if ( !ab.save( t ) ) {
      kDebug() << "Can't save.";
    }

    struct tms end;

    times( &end );

#if 0
    kDebug() << "utime :" << int( end.tms_utime );
    kDebug() << "stime :" << int( end.tms_stime );
    kDebug() << "cutime:" << int( end.tms_cutime );
    kDebug() << "cstime:" << int( end.tms_cstime );
#endif

    kDebug() << "UTime:" << int( end.tms_utime ) - int( start.tms_utime );
    kDebug() << "STime:" << int( end.tms_stime ) - int( start.tms_stime );

  } else {
    kDebug() << "No ticket for save.";
  }
}
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    if (!QAxFactory::isServer()) {
        AddressBook addressBook;
        addressBook.show();
        return app.exec();
    }
    return app.exec();
}
Example #9
0
File: main.cpp Project: CCJY/coliru
int main(){

AddressBook test;    

test.NoPeople = 2;

test.People[0].storeName("Ann", "Southall");
test.People[0].storeAddress("12 Park st");
test.People[0].storePhNo("0427854623");

test.People[1].storeName("Lawoko","Lars");
test.People[1].storeAddress("26 Wilpena Place, Vermont South, Melbourne");
test.People[1].storePhNo("0400510502");

test.printAddressBook();
}
vector<string> findAddressesFromOrgs ()
{
    // change 'findMatchingAddress' to 'find'
    // return global_address_book.findMatchingAddresses
    return global_address_book.find
    ( 
        // we're declaring a lambda here; the [] signals the start
        [] (const string& addr) { return addr.find( ".org" ) != string::npos; } 
    );
}
Example #11
0
int main(int argc,char **argv)
{
    KAboutData aboutData("testkabc",I18N_NOOP("TestKabc"),"0.1");
    KCmdLineArgs::init(argc, argv, &aboutData);

    KApplication app( false, false );
    AddressBook *ab = StdAddressBook::self();

#define READ

#ifdef READ
    AddressBook::Iterator it;
    for ( it = ab->begin(); it != ab->end(); ++it ) {
      QString vcard;
      VCardConverter converter;
      converter.addresseeToVCard( *it, vcard );
      kdDebug() << "card=" << vcard << endl;
    }
#else
    Addressee addr;

    addr.setGivenName("Tobias");
    addr.setFamilyName("Koenig");


    Picture pic;
    QImage img;
    img.load("/home/tobias/test.png");
/*
    pic.setData(img);
    pic.setType(QImage::imageFormat("/home/tobias/test.png"));
*/
    pic.setUrl("http://www.mypict.de");
    addr.setLogo( pic );

    ab->insertAddressee( addr );

    StdAddressBook::save();
#endif

    return 0;
}
Example #12
0
void read_write_read_with_mergefrom(const string &filename, AddressBook &book)
{
    {
        fstream read_f(filename.c_str(), ios::in | ios::binary);
        if (!read_f)
        {
            cerr << filename << ": file not found, exit..." << endl;
            return;
        }

        book.ParseFromIstream(&read_f);
        cout << "book: " << book.DebugString() << endl;
    }

    book.set_host_name("carl_update_mergefrom");
    int index = 0;
    for (; index < book.person_size(); ++index)
    {
        Person person;
        person.CopyFrom(book.person(index));
        person.set_age(100);

        book.mutable_person(index)->MergeFrom(person);
    }

    {
        fstream write_f(filename.c_str(), ios::out | ios::trunc | ios::binary);
        if (!book.SerializeToOstream(&write_f))
        {
            cerr << "failed to write addressbook" << endl;
            return;
        }
    }

    {
        fstream read_f(filename.c_str(), ios::in | ios::binary);
        if (!read_f)
        {
            cerr << filename << ": file not found, exit..." << endl;
            return;
        }

        book.ParseFromIstream(&read_f);
        cout << "book: " << book.DebugString() << endl;
    }

}
Example #13
0
int main(int argc,char **argv)
{
  KAboutData aboutData("testdb","TestKabcDB","0.1");
  KCmdLineArgs::init(argc,argv,&aboutData);

//  KApplication app( false, false );
  KApplication app;

  AddressBook ab;
  
  ResourceSql r( &ab, "root", "kde4ever", "localhost" );
  if ( ! r.open() ) {
    kdDebug() << "Failed to open resource." << endl;
  }
  
  r.load( &ab );
  
  r.close();
  
  ab.dump();
}
void Search(AddressBook tempbook)
{
	string tempfirst;
	string templast;
	Contact* tempcontact;
	cout << "Please enter the first name: ";
	cin >> tempfirst;
	cout << endl;
	cout << "Please enter the last name: ";
	cin >> templast;
	cout << endl;
	tempbook.findContact(tempfirst,templast);
	tempcontact=NULL;
}
//Iterates through all people in the AddressBook and prints info about them
void ListPeople(const AddressBook& address_book)
{
for(int i=0; i < address_book.person_size(); i++)
{
const Person& person = address_book.person(i);

cout << "Person ID: " << person.id() << endl;
cout << "  Name: " << person.name() << endl;
if(person.has_email())
{
cout << "  E-mail address: " << person.email() << endl;
}

for(int j=0; j < person.phone_size(); j++)
{
const Person::PhoneNumber& phone_number = person.phone(j);

switch(phone_number.type())
{
case Person::MOBILE:
cout << "  Mobile phone #: ";
break;

case Person::HOME:
cout << "  Home phone #: ";
break;

case Person::WORK:
cout << "  Work phone #: ";
break;
}

cout << phone_number.number() << endl;
}

}
}
int main () {

	AddressBook book;

	book.add(Contact("John", "Doe"));
	book.add(Contact("Gerald", "Weiss"));
	bool value = book.checker(Contact("Gerald", "Weiss"));
	bool value1 = book.checker(Contact("Jeffrey", "Dover"));
	book.print();
	cout << "If value is 1 then Gerald Weiss exists else it does not. Value is " << value << endl;
	cout << "If value is 1 then Jeffrey Dover exists else, it does not. Value is " << value1 << endl;
	return 0;
}
void AddToBook(AddressBook& tempbook)
{
	string firsttemp;
	string lasttemp;
	string emailtemp;

	cout << endl;
	cout << "Please enter contact's first name: ";
	cin >> firsttemp;
	cout << endl;
	cout << "Please enter contact's last name: ";
	cin >> lasttemp;
	cout << endl;
	cout << "Please enter contact's email address: ";
	cin >> emailtemp;
	cout << endl;

	Contact tempcontact(firsttemp,lasttemp,emailtemp);
	tempbook.addContact(tempcontact);

	cout << "Contact added" << endl;
}
Example #18
0
/****************************************************************
 *
 * Description: The main hander function for the phonebook. Notice
 *              the book is defined here (as a static value).
 *
 *
 * Pre:  none
 *
 * Post: Handles the input based on the value of c.
 *
 ***************************************************************/
bool handleInput( char c ) {
  static AddressBook book; // the phone book
  string nameBuffer;
  string phoneBuffer;
  bool retval = true;    // return value (false if quit)

  switch( c ) {

  // case A = Add entry to the phone book
  case 'A':
  case 'a':
    cout << "Name  : ";
    cin >> nameBuffer;
    cout << "\nNumber: ";
    cin >> phoneBuffer;
    book.addEntry(nameBuffer, phoneBuffer);
    cout << "\nNew entry: <" << nameBuffer << "," << phoneBuffer << ">" << endl;
    break;

  // case D = Delete item from the phone book
  case 'D':
  case 'd':
    cout << "Name to delete: ";
    cin >> nameBuffer;
    book.removeEntry( nameBuffer );
    cout << "\n";
    break;

  // case Q = Quit
  case 'Q':
  case 'q':
    cout << "Quit" << endl;
    retval = false;
    break;

  // case F = Find an entry
  case 'F':
  case 'f':
    {
      cout << "Find: ";
      cin >> searchString;
      cout << "\n";
      /**
       * TODO:
       *
       * We ant to search for all the elements that matches some criterial specified
       * by a lamda function that you pass in from here.
       *
       * As an example, you may return true from your lamnda function if you find parial match
       * on either the name or the phone number (although, you decide what the search criteria should be
       * 
       * Assuming you have already implemented the find function on the AddressBook, 
       * you should be able to write some code similar to this (IN PSEUDO CODE):
       *
       * list<pair<string,string> > result = book.find( YOUR_LAMBDA_FUNCTION);
       * if ( result.empty() ) {
       *    cout << nameBuffer << " not found" << endl;
       * } else {
       *   for( auto entry : result ) {
       *      cout << "Name / number : " << entry.first << " / " << entry.second << endl;
       *   }
       * }
    }
    break;
    
    // case L = List entries in the phone book
  case 'L':
  case 'l':
    book.listEntries(cout);
    break;
    
    // default prints help
  default:
    cout << "Commands are:" << endl <<
      "A -> Add entry" << endl <<
      "D -> Delete entry" << endl <<
      "F -> Find entry" << endl <<
      "L -> List" << endl <<
      "Q -> Quit" << endl;
    break;
  }
  return retval;
}

/****************************************************************
 *
 * Description: main for the address book example
 *
 * Pre:  none
 *
 * Post: Reads input and handles input until the handleInput
 *       function returns false.
 *
 ***************************************************************/
int main() {
  char c;
  do {
   c = readInput();
  } while ( handleInput( (char) c ) );

  return 0;
}
Example #19
0
/*
**NOTE**
For all class member functions, check their respective header files
for the DETAILED (Post/Pre condition) description of the function.
*/
int main(int argc,char* argv[])//argv[1] will be the csv inputfile name.
{
 
 //If statement to check if an inputfile command line arguement is passed.
 if(argc<2)
 {
   cout << "\nError usage, please run the program in the following manner:" << endl;
   cout << argv[0] << " CSV_INPUT_FILE_NAME\n" << endl;
   exit(1); //Display usage and exit program if no command line arguement.
 }

//////////////////////////
//TOKEN EXTRACTION BLOCK//
//////////////////////////
 AddressBook bookOne;
 //Create AddressBook object bookOne
 bookOne.pushTitle();
 //This function pushes the title line into the contact vector at position 0.(i.e "First Name", "Last Name" etc...)
 /*Could probably leave this out by reading the first line of the given input file which also contains
 the title line.*/

 vector<string> myString;
 //myString will store text lines from csv inputfile argv[1]
 string fileline, currentline, substring;
 //fileline=line of file from text to be push back into myString
 //currentline=current line that is being looked at by token extraction algorithm
 //substring=token extracted to be pushed into the actual Addressbook Contact


    	//File extration is done here
	ifstream myfile(argv[1]);
	
	//Start extraction line by line if able to open file.
	if(myfile.is_open())
	{
		while(myfile)
		{
			getline(myfile, fileline);
			if(fileline.length()!=0)
			{
				myString.push_back(fileline);
			}
		}
    		myfile.close();
	}

	//Else if the file does not exist, asks user to double check that the files is in the directory.
	else
	{
		cout << "\n*WARNING* CSV File not found in directory. Please check for file:\"" << argv[1] << "\"\n" << endl;
		exit(1);		
	}

    //Token extraction loop/algorithm starts here.
    //Took me a while but I figured it out =)!
    for(int i=1; i<myString.size(); i++) //this for loop will run for the length of myString
    {
        bookOne.iPush();
        //iPush will pushback the vector to make room for the new incomming line.

        currentline=myString.at(i);
        //currentline will get each line from myString from first to end

        //x is left "
        //y is right "
        //token will count token # 1-11 for each field.
        int x=0, y=0, token=0;
        while(token<11)//The algorithm should keep looking for tokens until counter hits 11 tokens
        {
            //x starts looking for the first " from y (0 initially at the start of the string/loop)
            x=currentline.find_first_of("\"", y);
            //y will start looking for the next " starting from x+1
            y=currentline.find_first_of("\"",x+1);

            //This if check is not really needed but to be save, x" will always be less than y"
            if(x<y)
            {
                token++;
            }
            substring=currentline.substr(x+1,(y-x)-1);
            //substring is the token which will always be found at x+1 to y-1
            //to get the length, starting from x+1, it is (y-x)-1...(there are also other ways to calculate)
            bookOne.buildData(i,substring,token);
            //After token is extracted to substring, it is pushed to the address book with it's respective
            //token index counter "token"

            //This was the tricky part...took me a while to figure it out =P
            //y needs to get +1 to prevent x from finding y's " in the next loop. DUHHH!!
            //Also this can be done with a third variable to look for commas but this is more efficient/easier.
            y++;

        }

    }//for loop ends here bringing the extraction process to an end.

    //This loop will validate the newly built vector of contacts. (Start at 1 as 0 is the title line)
    for(int i=1; i<bookOne.vectorSize()-1; i++) //vectorsize returns the size the vector Contact data.
    {
        if(bookOne.contactValidate(i)==0)//this boolean function validates and DELETES invalid contacts.
        {
            bookOne.contactValidate(i);//calling the actual function DELETES invalid contacts (more detail in header file)
            i=1; //Thus bringing i back to 1 is needed to check for all invalid contacts in the new vector size.
        }
    }



/////////////////////
//MAIN OPTION BLOCK//
/////////////////////
 string option;
 //option is the variable for the menu option input from the user
 do{ //this do loop will run wile the option is not Q or q for quit.
    do{ //this do loop will run until a valid option is received from the user.
        displayMenu();
        cout << "Select an option:";
        cin >> option;
        //if the option is longer than 1 character. (can probably leave out >1 as function checks for length also)
        if(checkOption(option)==false || option.length()>1)
        {
            cout << "Invalid choice please try again.." << endl; //output invalid choice statement.
        }
    }while(checkOption(option)==false);

    //Program will get here only if option is valid.
    //Options are listed in order shown on project 3 description

        //////////////////////////////
        //OPTION [A] - Add a contact//
        //////////////////////////////
    if(option=="A" || option=="a")
    {
        //Function A uses push_back to add the new contact
        //Check AddressBook header/source file for more detail.
        bookOne.functionA();

        //if the new added push_back vector is valid (NOTE* if valid this function will NOT delete)
        if(bookOne.contactValidate(bookOne.vectorSize()-1)==1)
        {
            //Thus print detail should print the last entry added which is vector size-1;
            bookOne.printDetail(bookOne.vectorSize()-1);
            cout << "\n**New contact added to the end of the list at position " << bookOne.vectorSize()-1 << endl;
        }

        else //no need to call function again as the first if statement already called it and will delete if it's invalid.
        {    //will enter this else if it's deleted, in that case output the error message below.
            cout <<"\nInvalid contact..."
                 <<"\nPlease input valid/non space leading values for the first four fields." << endl;
        }
    }

        //////////////////////////////////////////
        //OPTION [D] - Display by sorted contact//
        //////////////////////////////////////////
    else if(option=="D" || option=="d")
    {
        //sort is the token # which it needs to be sorted by. (1-4 only)
        int sort=0;

        //do-while loop will run until a valid token choice is given.
        do{
            cout << "\nWhich field would you like to sort by?"
                << "\n1)Last Name"
                << "\n2)First Name"
                << "\n3)Nickname"
                << "\n4)Email 1"
                << "\n--------------"
                << "\nEnter Choice:";
            cin  >> sort;

            //if statement to reprompt user for valid choice
            if(sort<=0 || sort > 4)
            {
                cout << "**Error choice input, please enter choice 1-4." << endl;
            }
        }while(sort<=0 || sort > 4);

        //functionD sorts the contacts accordint to token sort
        //I used the same sorting method as my project 2!! =)
        //More in detail in AddressBook header/source file
        bookOne.functionD(sort);

        //Print preview the newly sorted contacts
        bookOne.printPreview();
    }

        ///////////////////////////////////////////
        //OPTION [C] - Display details of contact//
        ///////////////////////////////////////////
    else if(option=="C" || option=="c")
    {
        //Simply print out the details of the desired contact entry.
        int entry=0;
        bookOne.printPreview();
        do{//do-while loop to keep the entry selection within bounds of the valid vector.
            cout << "Which entry # would you like to view in detail?:";
            cin >> entry;
            if(entry<0 || entry>bookOne.vectorSize()-1)
            {
                cout << "\n**Error entry #, please try again.." << endl;
            }
        }while(entry<0 || entry>bookOne.vectorSize()-1);
        //printDetail will print the details of the desired entry.
        bookOne.printDetail(entry);

    }
Example #20
0
void AddressBook::MergeFrom(const AddressBook& from) {
  GOOGLE_CHECK_NE(&from, this);
  person_.MergeFrom(from.person_);
  mutable_unknown_fields()->append(from.unknown_fields());
}
Example #21
0
File: write.cpp Project: skhal/Cpp
void promptForAddress(AddressBook &book)
{
    while(true)
    {
        cout << "Enter person ID number [0 to quit]: ";

        Person person;

        {
            int id;
            cin >> id;

            if (!id)
                break;

            person.setId(id);
            cin.ignore(256, '\n');
        }

        {
            cout << "Enter name: ";
            std::string name;
            getline(cin, name);

            person.setName(name);
        }

        {
            cout << "Enter email address (blank for none): ";

            string email;
            getline(cin, email);
            if (!email.empty())
                person.setEmail(email);
        }

        while(true)
        {
            cout << "Enter a phone number [Enter to finish]: ";
            string number;
            getline(cin, number);
            if (number.empty())
                break;

            Phone *phone = person.add_phone();
            phone->setNumber(number);

            cout << "Is this a mobile, home or work phone? ";
            string type;
            getline(cin, type);

            if ("mobile" == type)
                phone->setType(Phone::MOBILE);
            else if ("home" == type)
                phone->setType(Phone::HOME);
            else if ("work" == type)
                phone->setType(Phone::WORK);
            else
                cout << "Unknown phone type. Using default." << endl;
        }

        book.push_back(person);
    }
}
Example #22
0
int main()
{
	AddressBook book;
	book.run();
	return 0;
}
Example #23
0
TEST(all, all)
{
    srand(time(NULL));
    g_log = new Logger("a.log");
    if (! g_log->Load())
    {
        return ;
    }
    bool b;

    Fmt fmt;
    b = fmt.Load("fmt.xml");
    EXPECT_EQ(b, true);
    if (! b)
    {
        return ;
    }

    Dat dat;
    b = dat.Load("dat.xml", &fmt, "", "");
    EXPECT_EQ(b, true);
    if (! b)
    {
        return ;
    }
    {
        RRMessage r;
        r.m_body = "4abcd3abc";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ(true, res);
    }

    {
        RRMessage r;
        //匹配zhangsan|1
        r.m_body = "zhangsan|1|zs@126.com|zzz_HOME,yyy_MOBILE";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        int i = 123;
        char buf[16];
        memcpy(buf, &i, sizeof(int));
        string b(buf, sizeof(int));
        EXPECT_EQ(resp.m_body, b + ",k1=k2;aaa-1");
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //匹配reg:.*163.COM
        r.m_body = "zhangsan|3|zs@163.com|zzz_HOME,yyy_MOBILE";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        int i = 123;
        char buf[16];
        memcpy(buf, &i, sizeof(int));
        string b(buf, sizeof(int));
        EXPECT_EQ(resp.m_body, "k1=k2;aaa-3");
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //匹配<abd
        r.m_body = "zhangsan|3|zs@126.com|abc_HOME,yyy_MOBILE";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        string e1 = "file=aaa;email=zs@fuck.com;a=1;b=";
        string e2 = "a=a1;b=b2|c=c3";
        bool t = false;
        if (e1 == resp.m_body)
        {
            t = true;
        }
        else if (e2 == resp.m_body)
        {
            t = true;
        }
        EXPECT_EQ(t, true);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //匹配reg:HOM*
        r.m_body = "zhangsan|3|zs@126.com|zzz_HOME,yyy_MOBILE";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        string e1 = "file=aaa;email=zs@fuck.com;a=1;b=";
        string e2 = "a=a1;b=b2|c=c3";
        bool t = false;
        if (e1 == resp.m_body)
        {
            t = true;
        }
        else if (e2 == resp.m_body)
        {
            t = true;
        }
        EXPECT_EQ(t, true);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //匹配yyy
        r.m_body = "zhangsan|3|zs@126.com|zzz_HME,yyy_MOBILE";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        string e = "b==b2;email==@3-yyy-bxx";
        EXPECT_EQ(e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //0x03abc4,defgzzz
        string data = "abc";
        string d2 = "defg";
        string tail = "zzz";
        int length = data.size();
        char buf[128];
        char *p = buf;
        memcpy(p, &length, sizeof(int));
        p += sizeof(int);
        strcpy(p, data.c_str());
        p += data.size();
        p += sprintf(p, "%d,", (int)d2.size());
        strcpy(p, d2.c_str());
        p += d2.size();
        strcpy(p, tail.c_str());
        p += tail.size();

        r.m_body = string(buf, p - buf);
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        if (! res)
        {
            EXPECT_EQ(0, 1);
            return ;
        }

        AddressBook ab;
        {
            Person* p = ab.add_person();
            p->set_name("zhangsan");
            p->set_id(3);
            p->set_email("zs@163.com");
            Person::PhoneNumber* pp = p->add_phone();
            pp->set_number("010-11");
            pp->set_type(Person_PhoneType_WORK);
            pp = p->add_phone();
            pp->set_number("123");
            pp->set_type(Person_PhoneType_MOBILE);
        }
        {
            Person* p = ab.add_person();
            p->set_name("lisi");
            p->set_id(4);
        }
        string e;
        ab.SerializeToString(&e);

        EXPECT_EQ("abcd"+e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        //0x03abc4,defgzzz
        string data = "abc";
        string d2 = "defgg";
        string tail = "zzz";
        int length = data.size();
        char buf[128];
        char *p = buf;
        memcpy(p, &length, sizeof(int));
        p += sizeof(int);
        strcpy(p, data.c_str());
        p += data.size();
        p += sprintf(p, "%d,", (int)d2.size());
        strcpy(p, d2.c_str());
        p += d2.size();
        strcpy(p, tail.c_str());
        p += tail.size();

        r.m_body = string(buf, p - buf);
        QA* qa = dat.Match(&r, true, "");
        if (! qa)
        {
            EXPECT_EQ(0, 1);
            return ;
        }
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        if (! res)
        {
            EXPECT_EQ(0, 1);
            return ;
        }

        AddressBook ab;
        {
            Person* p = ab.add_person();
            p->set_name("zhangsan");
            p->set_id(3);
            p->set_email("zs@163.com");
            Person::PhoneNumber* pp = p->add_phone();
            pp->set_number("010-11");
            pp->set_type(Person_PhoneType_WORK);
            pp = p->add_phone();
            pp->set_number("123");
            pp->set_type(Person_PhoneType_MOBILE);
        }
        {
            Person* p = ab.add_person();
            p->set_name("lisi");
            p->set_id(4);
        }
        string e;
        ab.SerializeToString(&e);

        EXPECT_EQ(e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        r.m_body = "100,200;100,300;100,400";
        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("a==a1;b==b1-A-", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string b1 = "hello";
        char buf[128];
        char* p = buf;
        p += sprintf(p, "k=key;v=val;a=");
        int len = b1.size();
        memcpy(p, &len, sizeof(int));
        p += sizeof(int);
        p += sprintf(p, ";b=%sb2v;c=cv", b1.c_str());

        r.m_body = string(buf, p - buf);

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        AddressBook ab;
        {
            Person* p = ab.add_person();
            p->set_name("len");
            p->set_id(len);
        }
        string e;
        ab.SerializeToString(&e);

        EXPECT_EQ(e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s = "b=1;c=2;a=a1:1,a2:2;a=a2:3,a3:4|ddeee";
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        string e;
        string name = "";
        {
            AddressBook ab;
            {
                Person* p = ab.add_person();
                p->set_name("zhangsan");
                p->set_id(3333);
            }
            ab.SerializeToString(&name);
        }
        {
            AddressBook ab;
            {
                Person* p = ab.add_person();
                p->set_name(name);
                p->set_id(123);
            }
            ab.SerializeToString(&e);
        }

        EXPECT_EQ(e, resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s;
        Pair p;
        p.set_key("3;abc12");
        p.set_value(111);
        p.SerializeToString(&s);
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("a==aa;email==xx-132-100", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s;
        AddressBook ab;

        Person* p = ab.add_person();
        p->set_name("zhangsan");
        p->set_id(3);
        p->set_email("zs@fuck.com");
        Person::PhoneNumber* pn = p->add_phone();
        pn->set_number("010-111");
        pn->set_type(Person::MOBILE);

        ab.SerializeToString(&s);
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("mytypethis is pb", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s = "a=1;b=2;url=p.tanx.com%2Fex%3Fi%3D1%26b%3D2";
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("hello", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;

        string e;
        string name = "";
        {
            AddressBook ab;
            {
                Person* p = ab.add_person();
                p->set_name("zhangsan");
                p->set_id(3333);
                p->set_email("123@163.com");
                Person::PhoneNumber* pn = p->add_phone();
                pn->set_number("010");
                pn->set_type(Person::MOBILE);
                pn = p->add_phone();
                pn->set_number("012");
                pn->set_type(Person::HOME);
            }
            ab.SerializeToString(&name);
        }
        {
            AddressBook ab;
            {
                Person* p = ab.add_person();
                p->set_name(name);
                p->set_id(124);
                p->set_email("222@126.com");
                Person::PhoneNumber* pn = p->add_phone();
                pn->set_number("010");
                pn->set_type(Person::WORK);
            }
            ab.SerializeToString(&e);
        }
        char buf[16];
        int l = e.size();
        memcpy(buf, &l, sizeof(int));
        e = string(buf, sizeof(int)) + e;
        r.m_body = e + "1234,6,,78";

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("a==a1;b==b1-A-", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s = "a";
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("--", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s = "http%3A%2F%2F#http://www.baidu.com";
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("http%3A%2F%2F|http%3A%2F%2Fwww.baidu.com", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;
        string s = "http://xxx.com/ex?js-%7B%22a%22%20%3A%20%22av%22%2C%20%22b%22%20%3A%20%22bv_v1_v2%22%2C%20%22c%22%20%3A%20%5B%7B%22c1%22%20%3A%20%22c1v%22%7D%2C%20%7B%22c2%22%20%3A%20%22c2_v1_v2%22%7D%2C%20%7B%22c3%22%20%3A%20%5B%22c31_v1%22%2C%20%22c32_v2%22%2C%20%22c33_v3%22%5D%7D%5D%7D$k-123";
        r.m_body = s;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ("{\"a\":[{\"a1\":[11,111],\"a2\":22,\"b\":{\"b1\":[\"1b\",\"1.1b\"],\"b2\":\"b22\"}},{\"a1\":333,\"a2\":22,\"a3\":33,\"b\":{\"b1\":[\"b-1\",\"1.1-b\"],\"b2\":\"b22\"}}]}", resp.m_body);
        EXPECT_EQ(true, res);
    }
    {
        RRMessage r;

        string eq, ea;
        string name = "";
        {
            Person* p = new Person;
            p->set_name("xxnousex");
            p->set_id(1223456);
            p->set_goodman(true);
            p->SerializeToString(&eq);
        }
        {
            Person* p = new Person();
            p->set_name("xxx");
            p->set_id(9876103);
            p->set_goodman(false);
            p->SerializeToString(&ea);
        }
        r.m_body = eq;

        QA* qa = dat.Match(&r, true, "");
        RRMessage resp;
        bool res = qa->Answer(&resp, &r);
        EXPECT_EQ(ea, resp.m_body);
        EXPECT_EQ(true, res);
    }
}