Herezh_dev/herezh_pp/Util/CharUtil.h

134 lines
5.3 KiB
C++
Executable file

/*! \file CharUtil.h
\brief Utilitaires divers concernant les caracteres.
*/
// This file is part of the Herezh++ application.
//
// The finite element software Herezh++ is dedicated to the field
// of mechanics for large transformations of solid structures.
// It is developed by Gérard Rio (APP: IDDN.FR.010.0106078.000.R.P.2006.035.20600)
// INSTITUT DE RECHERCHE DUPUY DE LÔME (IRDL) <https://www.irdl.fr/>.
//
// Herezh++ is distributed under GPL 3 license ou ultérieure.
//
// Copyright (C) 1997-2021 Université Bretagne Sud (France)
// AUTHOR : Gérard Rio
// E-MAIL : gerardrio56@free.fr
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License,
// or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// For more information, please consult: <https://herezh.irdl.fr/>.
/************************************************************************
* DATE: 23/01/97 *
* $ *
* AUTEUR: G RIO (mailto:gerardrio56@free.fr) *
* $ *
* PROJET: Herezh++ *
* $ *
************************************************************************
* BUT: Utilitaires divers concernant les caracteres. *
* $ *
* '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' *
* $ *
************************************************************************/
#ifndef CHARUTIL_H
#define CHARUTIL_H
#include <iostream>
#include <fstream>
//#include "Debug.h"
#ifndef ENLINUX_STREAM
#include <sstream> // pour le flot en memoire centrale
#else
#include <strstream> // pour le flot en memoire centrale
#endif
//#ifdef SYSTEM_MAC_OS_X
// #include <stringfwd.h> // a priori ce n'est pas portable
//#el
#if defined SYSTEM_MAC_OS_CARBON
#include <stringfwd.h> // a priori ce n'est pas portable
#else
#include <string.h> // pour le flot en memoire centrale
#endif
#include <string>
//#include <bool.h>
#include "Tableau_T.h"
/// sortie de n blancs
inline void SortBlanc(int n)
{ if (n>0) for (int i=1;i<= n; i++) cout << " ";
};
/// sortie de n fois le meme caratere
inline void Sortcar(int n,char c)
{ if (n>0) for (int i=1;i<= n; i++) cout << c;
};
/// transformation d'un string ou d'une chaine de character en entier
int ChangeEntier(string st);
int ChangeEntier(char * st);
/// transformation d'un string ou d'une chaine de character en relle
double ChangeReel(string st);
double ChangeReel(char * st);
/// transformation d'un entier en chaine de caractere correspondant
string ChangeEntierSTring(int );
/// transformation d'un réel en chaine de caractère correspondant
string ChangeReelSTring(double a );
/// transformation d'un entier de 0 a 10 en 1 caractere correspondant
char* ChangeEntierChar(int );
/// transformation d'un string en minuscules
string Minuscules(const string& st);
/// test si un string est numérique ou pas
bool isNumeric( const char* pszInput, int nNumberBase );
/// -------- utilitaire pour lire une chaine de caractères:
/// cas avec une valeur par défaut accepter
/// si retour chariot, retourne la valeur par défaut passée en paramètre
/// sinon retourne le string lue au clavier
/// si avec_ecriture = true: on écrit "--> valeur par defaut : " val_defaut
/// gestion d'erreur si lecture non correcte
string lect_return_defaut(bool avec_ecriture,string val_defaut);
/// lecture d'une chaine de caractère via getline: pas de validation
/// tant qu'il n'y a rien de lue
/// gestion d'erreur si lecture non correcte
string lect_chaine();
/// cas d'une valeur o/n , sinon pas acceptable
/// si avec_ecriture = true: on écrit "--> valeur lue : " valeur lue
string lect_o_n(bool avec_ecriture);
/// cas d'une valeur 1/0 , sinon pas acceptable
/// si avec_ecriture = true: on écrit "--> valeur lue : " valeur lue
string lect_1_0(bool avec_ecriture);
/// lecture d'un scalaire réel avec getline
/// gestion d'erreur si lecture non correcte
double lect_double();
/// lecture du prochain caractère non espace et non vide dans le flot sans modifier le flot
/// en remplacement de la méthode peek qui ne marche pas avec code warrior
/// si pb ou aucun caractère, retour du caractère "espacement"
char Picococar(ifstream& entr);
#ifndef ENLINUX_STREAM
char Picococar(istringstream& entr);
#else
char Picococar(istrstream& entr);
#endif
/// recherche "nom" dans le tableau "tabMot", si nom existe ramene true, sinon false
bool ExisteString (Tableau<string>& tabMot,string nom);
#endif