/***********************************************************************
*
*               Module   : Buffer
*               Fichier  : BufferTail.c
*               Auteur   : Ducloy
*               Date     : Avril 95
*  $Id: BufferTail.c,v 1.2 2005/06/22 14:53:33 parmentf Exp $
*
************************************************************************
*
* Copyright (c) 1995 CNRS/CRIN & INRIA Lorraine
* 
************************************************************************/

#include "Buffer.h"
#include <string.h>
#include <stdio.h>

int BufferTailCmp(Buffer *b1, char *s1)
{
  int l1;
  int l2;
  l1=strlen(s1);
  l2=BufferLen(b1);
  if (l1>l2)return -1;
  return strcmp(BufferString(b1)+l2-l1, s1);
}

char *BufferTailCut(Buffer *b1, int n1)
{
  int l1;
  l1=BufferLen(b1);
  if (n1>l1)return NULL;
  BufferString(b1)[l1-n1]='\0';
  BufferLen(b1)=l1-n1;
  return BufferString(b1);
}

char *BufferTailCutFromStr(Buffer *b1, char *s1)
{
  char *s2;
  s2=strstr(BufferString(b1),s1);
  if (!s2) return NULL;
  *s2='\0';
  BufferLen(b1)=strlen(BufferString(b1));
  return BufferString(b1);
}

char *BufferTailReplace(Buffer *b1, char *s1)
{
  int l1;
  int l2;
  l1=strlen(s1);
  l2=BufferLen(b1);
  if (l1>l2)return NULL;
  strcpy(BufferString(b1)+l2-l1,s1);
  return BufferString(b1);
}
