#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   string document = "HEADER::BEGIN[data to find]END::FOOTER";

   // 1. Isolate the content block we want to search in.
   // Assume the block we care about is between BEGIN and END.
   auto startIndex = document.find("BEGIN[") + 6;
   auto endIndex = document.find("]END");
   auto contentLength = endIndex - startIndex;
   auto contentBlock = document.substr(startIndex, contentLength);
   cout << "Searching within substring: '" << contentBlock << "'" << endl;

   // 2. Perform a find operation on just that substring.
   auto t = uc.NewTransformer().SetText(contentBlock);
   t.Pattern("find");
   t.Find();
   auto matches = t.Matches();

   cout << "Local match StartPosition: " << matches[0].StartPosition() << endl; // Relative to 'contentBlock'

   // 3. Apply the offset to remap to the global 'document' coordinate space.
   matches.ApplyOffset(startIndex);

   cout << "Global match StartPosition: " << matches[0].StartPosition() << endl;
}