/* 
mrDiff.h
~~~~~~~~

Overview
--------

mrDiff is a set of functions for extracting, applying and merging the differences between
 two strings. It is intended for use with text files, but the strings may contain
 arbitrary binary data.
Containers are returned by value, so there should be a speedup by enabling move semantics
 in a C++11 compiler such as VS12 or GCC 4.6.

Functions
---------

Diff:  Expresses the difference between two strings as a patch_t.
       Implemented using the Myers matrix algorithm in a pretty naive way.   
Patch: Applies a patch_t to a string, to reconstruct a diff.
Merge: Performs a best-effort attempt to reconcile two diffs against the same source.
       This produces a new patch_t that can be applied to the original string.
Pos:   Returns an adjusted cursor position after applying a patch_t.

License
-------

Copyright 2011 Mason Giles. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
  1. Redistributions of source code must retain the above copyright notice and this list
     of conditions.
  2. Redistributions in binary form must reproduce the above copyright notice and this
     list of conditions in the documentation and/or other materials provided with the
     distribution.
*/

#include <string>
#include <vector>

#define MRDIFF_VERSION    "1.0"
#define MRDIFF_perror(x)  fputs(x "\n", stderr)

// Types

struct diff_t {
	int type;
	std::string literal;
	int src_len;
};

typedef std::vector<diff_t> patch_t;

// Primary diff operations

patch_t     mrdiff  (std::string sl, std::string sr);
std::string mrpatch (std::string orig, patch_t& d);
patch_t     mrmerge (patch_t& dl, patch_t& dr);

// Helper functions

int         mrpos         (int pos, patch_t& patch);
std::string mrserialise   (patch_t& d);
patch_t     mrunserialise (std::string d);