QuickRank  v2.0
QuickRank: A C++ suite of Learning to Rank algorithms
strutils.h
Go to the documentation of this file.
1 /*
2  * QuickRank - A C++ suite of Learning to Rank algorithms
3  * Webpage: http://quickrank.isti.cnr.it/
4  * Contact: quickrank@isti.cnr.it
5  *
6  * Unless explicitly acquired and licensed from Licensor under another
7  * license, the contents of this file are subject to the Reciprocal Public
8  * License ("RPL") Version 1.5, or subsequent versions as allowed by the RPL,
9  * and You may not copy or use this file in either source code or executable
10  * form, except in compliance with the terms and conditions of the RPL.
11  *
12  * All software distributed under the RPL is provided strictly on an "AS
13  * IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, AND
14  * LICENSOR HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
15  * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16  * PURPOSE, QUIET ENJOYMENT, OR NON-INFRINGEMENT. See the RPL for specific
17  * language governing rights and limitations under the RPL.
18  *
19  * Contributor:
20  * HPC. Laboratory - ISTI - CNR - http://hpc.isti.cnr.it/
21  */
22 #pragma once
23 
24 #include <cctype>
25 #include <string>
26 
27 /*! \file strutils.hpp
28  * \brief some useful functions for strings
29  */
30 
31 /*! \def ISSPC
32  * \brief return true if \a ch is a space-char
33  */
34 #define ISSPC(ch) (ch==' ' || ch=='\t' || ch=='\n' || ch=='\v' || ch=='\f' || ch=='\r')
35 
36 /*! \def ISEMPTY
37  * \brief return true if \a str is empty string
38  */
39 #define ISEMPTY(str) (*(str)=='\0')
40 
41 /*! \fn read_token(char *&str, const char exitch='\0')
42  * \brief skip a sequence of spaces (see ISSPC macro) and return the token which is considered closed at the next space encountered (if \a exitch is the FIRST not-space of str the function returns immediately).
43  */
44 char *read_token(char *&str, const char exitch = '\0');
45 
46 /*! \fn is_empty(const char *str)
47  * \brief return true if \a str pointer is NULL or is made of spaces (see ISSPC macro)
48  */
49 bool is_empty(const char *str);
50 
51 /*! \fn atou(char *str, const char *sep)
52  * \brief skip a sequence of spaces (see ISSPC macro) and return the unsigned int after \a sep
53  */
54 unsigned int atou(char *str, const char *sep);
55 
56 /*! \fn void trim(std::string& str)
57  * \brief delete spaces from start/end of a string (in place modification)
58  */
59 std::string &trim(std::string &str);
bool is_empty(const char *str)
return true if str pointer is NULL or is made of spaces (see ISSPC macro)
Definition: strutils.cc:50
unsigned int atou(char *str, const char *sep)
skip a sequence of spaces (see ISSPC macro) and return the unsigned int after sep ...
Definition: strutils.cc:61
char * read_token(char *&str, const char exitch= '\0')
skip a sequence of spaces (see ISSPC macro) and return the token which is considered closed at the ne...
Definition: strutils.cc:34
std::string & trim(std::string &str)
delete spaces from start/end of a string (in place modification)
Definition: strutils.cc:79