#include "IMFHeader.h"
#include "Exception.h"
#include "Log.h"

namespace coreutils {

   IMFHeader::IMFHeader() : ZString() {

   }

   IMFHeader::IMFHeader(ZString &in) : ZString(in) {
      key = in.getTokenInclude((char *)"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-0123456789");
      if(key.getLength() != 0) {
	 if(!in.ifNext((char *)":")) {
	    printf("key=%s %02X\n", key.str().c_str(), in.str()[0]);
	    throw coreutils::Exception("Invalid character in expected header token.");
	 }
	 in.skipWhitespace();
         value = in.goeol();
      }
      else if(in.skipWhitespace() > 0) {}
      else if(in.str() == "") {}
      coreutils::Log(coreutils::LOG_DEBUG_2) << " " << key << "[" << value << "]";
   }
   
   IMFHeader::IMFHeader(ZString key, ZString value) : ZString() {
      this->key = key;
      this->value = value;
   }

   ZString IMFHeader::getKey() {
      return key;
   }

   ZString IMFHeader::getValue() {
      return value;
   }

   void IMFHeader::output(std::stringstream &out) {
      out << key << ": " << value << "\r\n";
   }

}