⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formdata.cpp

📁 Think in C++ 第二版源码
💻 CPP
字号:
//: C26:FormData.cpp {O}

// From Thinking in C++, 2nd Edition

// Available at http://www.BruceEckel.com

// (c) Bruce Eckel 1999

// Copyright notice in Copyright.txt

#include "FormData.h"

#include "../require.h"



DataPair& DataPair::get(istream& in) {

  first.erase(); second.erase();

  string ln;

  getline(in,ln);

  while(ln.find("[{[") == string::npos)

    if(!getline(in, ln)) return *this; // End

  first = ln.substr(3, ln.find("]}]") - 3);

  getline(in, ln); // Throw away [([

  while(getline(in, ln))

    if(ln.find("])]") == string::npos)

      second += ln + string(" ");

    else

      return *this;

}



FormData::FormData(char* fileName) {

  ifstream in(fileName);

  assure(in, fileName);

  require(getline(in, filePath) != 0);

  // Should be start of first line:

  require(filePath.find("///{") == 0); 

  filePath = filePath.substr(strlen("///{"));

  require(getline(in, email) != 0);

   // Should be start of 2nd line:

  require(email.find("From[") == 0);

  int begin = strlen("From[");

  int end = email.find("]");

  int length = end - begin;

  email = email.substr(begin, length);

  // Get the rest of the data:

  DataPair dp(in);

  while(dp) {

    push_back(dp);

    dp.get(in);

  }

} 



string FormData::operator[](const string& key) {

  iterator i = begin();

  while(i != end()) {

    if((*i).first == key)

      return (*i).second;

    i++;

  }

  return string(); // Empty string == not found

}



void FormData::dump(ostream& os) {

  os << "filePath = " << filePath << endl;

  os << "email = " << email << endl;

  for(iterator i = begin(); i != end(); i++)

    os << (*i).first << " = " 

       << (*i).second << endl;

} ///:~

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -