2 * This file includes function definitions for several useful string
5 * Copyright (C) 2008 David Kolossa
7 * This file is part of OpenStranded.
9 * OpenStranded is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * OpenStranded is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with OpenStranded. If not, see <http://www.gnu.org/licenses/>.
23 #ifndef STRANDED_S2STRING_HH
24 #define STRANDED_S2STRING_HH
31 * Some constants passed in warnFlag
34 #define EXPLODE_LOWER 1
35 #define EXPLODE_GREATER 2
36 #define EXPLODE_NO_TOKEN 4
38 #define inFlag(flag, value) (((flag) & (value)) == (value))
41 * This namespace holds functions for easy manipulation of
48 * This function divides a string into substrings by a token.
49 * Inspired by the PHP function with the same name.
50 * @param str The string which sohuld be divided
51 * @param buf The buffer in which the substrings should be saved
52 * @param token The token which should split the string
53 * @param count The maximum number of strings to be written into buf
54 * @return 0 on success, larger than 0 on error
57 explode (std::string
&str
, std::string
*buf
, const char *token
, size_t count
);
60 * Converts a string into a float.
61 * This functions does some checks on the string so use string
62 * streams if you think you already have a valid float string.
63 * @param str The string to be conversed
64 * @param buf the float in which the result is stored
65 * @return true if string is valid, if not, it sets the float to 0.0 and returns false
68 stof (std::string
&str
, float &buf
);
71 * Converts a string into an int.
72 * This function checks the number whether it is a valid integer to allow
73 * user-friendly error-reporting for typos.
74 * If you don't need those checks use a string stream instead.
75 * @param str The string to be conversed
76 * @param buf The integer in which the result is stored
77 * @return true if str was valid and conversed, if not, buf is set to 0 and false is returned
80 stoi (std::string
&str
, int &buf
);
83 #endif /* STRANDED_S2STRING_HH */