/*
string class
by Martin Robinson
this object make char string manipulation easier
__________________________________________________
preprocessor*/
#pragma once
#ifndef _STRINGMR
#define _STRINGMR
#include <iostream>
using namespace std;
#include <assert.h>
#include "fstring.hpp"

/*-----------------
class
-----------------*/

class stringMR{
    baseFstr * _str;
    void destroyFstr();

public:
    stringMR();			        // constructeur sans paramètre
    stringMR(const char *s); 	// construction avec des éléments 
				                // d’une chaîne de caractères ex : «allo»
    stringMR(int n, char c);	// constructeur qui répète c, n fois
    stringMR(const stringMR& ch);	// constructeur de copie
    ~stringMR();			    // destructeur
           
    int size()const;   	 	    // retourne le nombre de caractères         
    void resize(int n);   		// modif. du nb. de char : l’allongement 
    void resize(int n, char c); // se fait en copiant c, n fois
           				        // ( ou par défaut '\0' )
    // accès au ième caractère
    const char operator[](int pos)const; 
    char &operator[](int pos);	 
    const char at(int n)const;
    char &at(int n);
        
    // obtention du char * sous-jacent, un nul est présent à la fin
    const char *c_str()const;

    // affectateur avec: stringMR, char *, char
    stringMR &operator=(const stringMR &str);
    stringMR &operator=(const char *s);
    stringMR &operator=(char c); 

    // concaténation avec: stringMR, char *, char
    stringMR &operator+=(const stringMR &str);
    stringMR &operator+=(const char *s);
    stringMR &operator+=(char c);   

    // insertion parmi les caractères d’une chaîne
    stringMR &insert(int pos, const stringMR &str);
    stringMR &insert(int pos, const char *s);
    stringMR &insert(int pos, int n, const char *c);    

    void swap(stringMR& str);	    // copie la stringMR implicite dans 
				                // l’explicite et vice-versa

    // recherche de chaînes et de caractères dans une chaîne ;
    int find(const stringMR &, int)const;
    int find(const stringMR &)const;
    int find(const char *s, int pos, int n)const;
    int find(const char *s, int pos)const;
    int find(const char *s)const;

    // recherche d'un caractère
    int find(char c, int pos = 0)const;
    int find(char c)const;

    // comparaison de chaînes
    int compare(const stringMR &str)const;
    int compare(int pos1, int n1, const stringMR &str)const;
    int compare(int pos1, int n1, const stringMR &str, int pos2, int n2)const;
    int compare(const char *s)const;

    // comparaison avec operator==
    bool operator==(const stringMR &str)const;

    // extraction de sous-chaîne
    stringMR & substr(int pos0, int combien);

    // lecture et affichage externe à la classe. Lecture jusqu’au char c
    friend istream & getline(istream &, stringMR &, char);
    friend ostream & operator<<(ostream &, const stringMR &);
    
    //petit ajout spécial
    stringMR & undo();
};

#endif
