// -*- Mode: C++; tab-width: 4  -*-

#ifdef _WIN32
#include <algo.h>
#include <bstring.h>
#else
#include <string>
#include <algorithm>
#endif

// return the size of the largest prefix of needle at the end
// of haystack

inline int
find_prefix_at_end (string haystack, string needle)
{
  int hl = haystack.length();
  int nl = needle.length();

  for (int i = max (nl-hl, 0); i < nl; i++) {
    if (haystack.compare (needle, hl-(nl-i), nl-i) == 0) {
	  return (nl-i);
	}
  }
  return 0;
}

#if 0
#include <iostream.h>
int
main (int argc, char * argv[])
{
  cout << find_prefix_at_end (string (argv[1]), string(argv[2])) << endl;
}
#endif
