1%%%%%%%%%%%%%%%%%%% 2% XLiFE++ is an extended library of finite elements written in C++ 3% Copyright (C) 2014 Lunéville, Eric; Kielbasiewicz, Nicolas; Lafranche, Yvon; Nguyen, Manh-Ha; Chambeyron, Colin 4% 5% This program is free software: you can redistribute it and/or modify 6% it under the terms of the GNU General Public License as published by 7% the Free Software Foundation, either version 3 of the License, or 8% (at your option) any later version. 9% This program is distributed in the hope that it will be useful, 10% but WITHOUT ANY WARRANTY; without even the implied warranty of 11% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12% GNU General Public License for more details. 13% You should have received a copy of the GNU General Public License 14% along with this program. If not, see <http://www.gnu.org/licenses/>. 15%%%%%%%%%%%%%%%%%%% 16 17\section{The {\classtitle String} class} 18 19String is no more than an alias (typedef) to the String class of the STL. By using a macro 20variable it is possible to choose either standard string (utf8) or wide string (utf16): 21\begin{lstlisting}[deletekeywords={[3] string}] 22#ifdef WIDE_STRING 23 typedef std::wstring String; 24#else 25 typedef std::string String; 26#endif 27\end{lstlisting} 28\vspace{.2cm} 29The \emph{WIDE\_STRING} macro variable is currently set in the \emph{Config.hpp} header file. 30\\ 31 32As a the string or wstring class of STL, String proposes all the functionalities of std::string 33(see the STL documentation) and new additional ones: 34\begin{lstlisting} 35//conversion utilities 36template<typename T_> String tostring(const T_& t); //'anything' to String 37template<typename T_> T_ stringto(const String& s); //String to 'anything' 38 39//transformation utilities 40String lowercase(const String&); // String converted to lowercase 41String uppercase(const String&); // String converted to uppercase 42String capitalize(const String&); // String with initial converted to uppercase 43String trimLeading(const String& s, const char* delim = " \t\n\f\r"); // trims leading white spaces 44String trimTrailing(const String& s, const char* delim = " \t\n\f\r"); // trims trailing white spaces 45String trim(const String& s, const char* delim = " \t\n\f\r"); // trims leading and trailing white spaces 46String delSpace(const String& s); //delete all white space 47String& replaceString(String& s, const String& s1, const String& s2); // replace string s1 by string s2 in string s 48String& replaceChar(String& s, char c1, char c2); // replace char c1 by char c2 in string s 49String fileExtension(const String& f); // return file name extension using last point as delimiter 50std::pair<String, String> fileRootExtension(const String& f); // return rootname and extension of a file 51void blanks(String&,int n); // add or remove n blanks at end of string 52 53//search capabilities 54int findString(const String, const std::vector<String>&); //!<returns index 55 56\end{lstlisting} 57\vspace{.2cm} 58Be cautious with templated conversion functions. The function \emph{tostring} (resp. \emph{stringto}) 59works when the operator $<<$ (resp. $>>$) on stringstream is defined for the template type 60\emph{T\_}. The function \emph{tostring} is more flexible than \emph{stringto}. Note that the 61template \emph{T\_} type has to be clarified when invoking \emph{stringto}. 62\begin{lstlisting} 63//examples of conversion stringto 64 String s="1 2 3"; 65 int i=stringto<int>(s); //i=1 66 real_t r=stringto<real_t>(s); //r=1. 67 complex_t c=stringto<complex_t>(s);//c=(1.,0) 68 void * p=stringto<void*>(s); //p=0x1 69 String ss=stringto<String>(s); //ss="1" 70 s="(0,1)"; 71 c=stringto<complex_t>(s); //c=(0.,1.) 72\end{lstlisting} 73 74 75\displayInfos{library=utils, header=String.hpp, implementation=String.cpp, test=test\_String.cpp} 76