M1102 – TP6 Corrigés (exo1 – 5)

#include <iostream>
#include <vector>
#include <cctype>
#include <utility>

#include "nsUtil.h"

using namespace std;
using namespace nsUtil;
string & ToUpper (string & Str)
{
    for (char & car : Str)
        car = toupper (car);
    return  Str;
}

vector <string> & ToUpper (vector <string> & VString)
{
    for (string & str : VString)
        str = ToUpper(str);
    return VString;
}

vector <string> & ToUpper (vector <string> & VString, const unsigned & LineNumber)
{
    ToUpper(VString [LineNumber]);
    return VString;
}

string & ToLower (string & Str)
{
    for (char & car : Str)
        car = tolower (car);
    return  Str;
}

vector <string> & ToLower (vector <string> & VString)
{
    for (string & str : VString)
        str = ToLower (str);
    return VString;
}

vector <string> & ToLower (vector <string> & VString, const unsigned & LineNumber)
{
    ToLower (VString [LineNumber]);
    return VString;
}



vector <string> & Swap (vector <string> & VString, const unsigned & PosBeg, const unsigned & PosEnd)
{
    swap (VString[PosBeg], VString[PosEnd]);
    return VString;
}


int main(int argc, char *argv[])
{
    if (2 != argc)
    {
        cerr << "gros boulet" << endl;
        exit (0);
    }

    string InputFile (argv[1]);
    //unsigned long Width (stoul(argv[2]));
    vector <string> VFile (FileToVectString (InputFile));
    EditVStringV3 (VFile);
    string Instruction, Complement;
    while (true)
    {
        cin >> Instruction;
        Instruction = ToLower (Instruction);
        if ("fin" == Instruction)
        {
            break;
        }
        //sauvergarde
        else if ("sav" == Instruction)
        {
            string FileOut;
            cin >> FileOut;
            VectStringToFile (VFile, FileOut);

        }
        //majuscule
        else if ( "maj" ==  Instruction)
        {
            cin >> Complement;
            if (ToLower(Complement) == "tout")
                ToUpper (VFile);
            else
                ToUpper (VFile, stoul(Complement));
        }
        //minuscule
        else if ( "min" ==  Instruction)
        {
            cin >> Complement;
            if (ToLower (Complement) == "tout")
                ToLower (VFile);
            else
                ToLower (VFile, stoul(Complement));
        }

        EditVStringV2 (VFile);
    }//while

    return 0;
}