623e7ab4 |
1 | /* |
2 | suPHP - (c)2002-2005 Sebastian Marsching <sebastian@marsching.com> |
3 | |
4 | This file is part of suPHP. |
5 | |
6 | suPHP is free software; you can redistribute it and/or modify |
7 | it under the terms of the GNU General Public License as published by |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. |
10 | |
11 | suPHP is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | GNU General Public License for more details. |
15 | |
16 | You should have received a copy of the GNU General Public License |
17 | along with suPHP; if not, write to the Free Software |
18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | */ |
20 | |
21 | #include <sstream> |
22 | |
23 | #include "Util.hpp" |
24 | |
25 | using namespace suPHP; |
26 | |
27 | std::string suPHP::Util::intToStr(const int i) { |
28 | std::ostringstream ostr; |
29 | ostr << i; |
30 | return ostr.str(); |
31 | } |
32 | |
33 | int suPHP::Util::strToInt(const std::string str) { |
34 | int i = 0; |
35 | std::istringstream istr; |
36 | istr.str(str); |
37 | istr >> i; |
38 | return i; |
39 | } |
40 | |
41 | int suPHP::Util::octalStrToInt(const std::string str) { |
42 | int result = 0; |
43 | for (int i=0; i<str.length(); i++) { |
44 | int d; |
45 | result *= 8; |
46 | switch (str[i]) { |
47 | case '0': |
48 | d = 0; |
49 | break; |
50 | case '1': |
51 | d = 1; |
52 | break; |
53 | case '2': |
54 | d = 2; |
55 | break; |
56 | case '3': |
57 | d = 3; |
58 | break; |
59 | case '4': |
60 | d = 4; |
61 | break; |
62 | case '5': |
63 | d = 5; |
64 | break; |
65 | case '6': |
66 | d = 6; |
67 | break; |
68 | case '7': |
69 | d = 7; |
70 | break; |
71 | default: |
72 | // Should not happen |
73 | continue; |
74 | } |
75 | result += d; |
76 | } |
77 | return result; |
78 | } |