
#include "hash-t.hh"
#include "hash_repl.hh"
#include "clone_ptr-t.hh"

namespace afilter {

  using namespace autil;

  template <typename T>
  bool HashRepl<T>::fill(InValue c, Itr * i, Buffer * buffer) {
    if (c != begin_char) {
      return false;
      //*buffer += c;
    } else {
      inbuf.resize(0);
      char d;
      k.assign(i);
      for(;;) {
	d = i->next();
	if (d == end_char || d == '\0') break;
	else inbuf.push_back(d);
      }
      typename Lookup::iterator r = lookup->find(inbuf);
      if (r != lookup->end()) { 
	add_to_buffer(*buffer, r->second, SingleMulti());
	return true;
      } else {
	i = k;
	return false;
	//*buffer += c;
      }
    }
  }

  template <typename T>
  void HashRepl<T>::add (const InValue * k, const Value * v) {
    pair<const InString,String> temp;
    for (++k; *k != end_char; ++k) 
      const_cast<InString &>(temp.first) .push_back(*k);
    for (; *v != '\0'; ++v)        temp.second.push_back(*v);
    lookup->insert(temp);
  }

}
