Eliminated some problems resulting from last merge
[openstranded.git] / src / s2string.hh
blob26916e6dca21b7f302fac0c9c246c84faabaa590
1 /*
2 * This file includes function definitions for several useful string
3 * operations.
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
26 #include <vector>
27 #include <string>
28 #include <sstream>
31 * Some constants passed in warnFlag
33 #define EXPLODE_OK 0
34 #define EXPLODE_LOWER 1
35 #define EXPLODE_GREATER 2
36 #define EXPLODE_NO_TOKEN 4
38 #define inFlag(flag, value) (((flag) & (value)) == (value))
40 namespace s2str
44 * This function divides a string into substrings by a token.
45 * Returns 0 on success and larger 0 when anything went bad.
46 * Inspired by the PHP function with the same name.
48 int
49 explode (std::string &str, std::string *buf, const char *token, size_t count);
52 * Converts a string into a float.
53 * This functions does some checks on the string so use string
54 * streams if you think you already have a valid float string.
55 * Returns true if str was valid, if not, it sets the float to 0.0
56 * and returns false.
58 bool
59 stof (std::string &str, float &buf);
62 * Converts a string into an int.
63 * This function checks the number whether it is a valid integer to allow
64 * user-friendly error-reporting for typos.
65 * If you don't need them use a string stream instead.
66 * Returns true if str was valid, if not it sets buf to 0 and returns
67 * false.
69 bool
70 stoi (std::string &str, int &buf);
73 #endif /* STRANDED_S2STRING_HH */