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

namespace coreutils {

   IMFHeader::IMFHeader(ZString &in) : ZString(in) {
      key = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_0123456789");
      if(key.getLength() != 0) {
	      if(!in.ifNext(":")) 
	        throw coreutils::Exception("Invalid character in expected header token.");	      
	      in.skipWhitespace();
         value = in.goeol();
      }
      else if(in.skipWhitespace() > 0) {}
      else if(in.str() == "") {}
   }

   IMFHeader::IMFHeader(ZString key, ZString value) : ZString(), key(key), value(value) {}

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

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

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

}