Rev 990 | Rev 1008 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 990 | Rev 997 | ||
|---|---|---|---|
| Line 94... | Line 94... | ||
| 94 | { |
94 | { |
| 95 | string hex; |
95 | string hex; |
| 96 | 96 | ||
| 97 | while (bin.size() > 0) |
97 | while (bin.size() > 0) |
| 98 | { |
98 | { |
| - | 99 | string part; |
|
| - | 100 | ||
| - | 101 | try |
|
| - | 102 | { |
|
| 99 |
|
103 | part = bin.substr(0, 4); |
| - | 104 | } |
|
| - | 105 | catch (std::out_of_range& e) |
|
| - | 106 | { |
|
| - | 107 | cout << "DEBUG: bin2hex exception: " << e.what() << "\n"; |
|
| - | 108 | cout << "DEBUG: A bin=" << bin << endl; |
|
| - | 109 | continue; |
|
| - | 110 | } |
|
| - | 111 | ||
| 100 | bin.erase(0, part.size()); |
112 | bin.erase(0, part.size()); |
| 101 | 113 | ||
| 102 | while (part.size() < 4) |
114 | while (part.size() < 4) |
| 103 | part = "0" + part; |
115 | part = "0" + part; |
| 104 | 116 | ||
| Line 138... | Line 150... | ||
| 138 | 150 | ||
| 139 | return hex; |
151 | return hex; |
| 140 | } |
152 | } |
| 141 | 153 | ||
| 142 | string float2bin(float num, int length) |
154 | string float2bin(float num, int length) |
| 143 | { |
155 | { |
| 144 | string bin; |
156 | string bin; |
| 145 | 157 | ||
| 146 | ///FIXME |
158 | ///FIXME |
| 147 | 159 | ||
| 148 | while (bin.size() < length) |
160 | while (bin.size() < length) |
| 149 | bin = "0" + bin; |
161 | bin = "0" + bin; |
| 150 | 162 | ||
| Line 186... | Line 198... | ||
| 186 | string uint2bin(unsigned int num, int length) |
198 | string uint2bin(unsigned int num, int length) |
| 187 | { |
199 | { |
| 188 | string bin; |
200 | string bin; |
| 189 | 201 | ||
| 190 | while (num) |
202 | while (num) |
| 191 | { |
203 | { |
| 192 | bin = char((num&1)+'0') + bin; |
204 | bin = char((num&1)+'0') + bin; |
| 193 | num >>= 1; |
205 | num >>= 1; |
| 194 | } |
206 | } |
| 195 | 207 | ||
| 196 | while (bin.size() < length) |
208 | while (bin.size() < length) |
| 197 | bin = "0" + bin; |
209 | bin = "0" + bin; |
| 198 | 210 | ||
| 199 | return bin; |
211 | return bin; |
| 200 | } |
212 | } |
| 201 | 213 | ||
| 202 | string uint2hex(unsigned int num, int length) |
214 | string uint2hex(unsigned int num, int length) |
| 203 | { |
215 | { |
| 204 | return bin2hex(uint2bin(num, length)); |
216 | return bin2hex(uint2bin(num, length)); |
| 205 | } |
217 | } |
| 206 | 218 | ||
| 207 | vector<string> explode(string delimiter, string str) |
219 | vector<string> explode(string delimiter, string str) |
| 208 | { |
220 | { |
| 209 | vector<string> parts; |
221 | vector<string> parts; |
| 210 | string::size_type startPos = 0; |
222 | string::size_type startPos = 0; |
| 211 | string::size_type endPos = 0; |
223 | string::size_type endPos = 0; |
| 212 | 224 | ||
| 213 | while ((endPos = str.find(delimiter, startPos)) != string::npos) |
225 | while ((endPos = str.find(delimiter, startPos)) != string::npos) |
| 214 | { |
226 | { |
| - | 227 | try |
|
| - | 228 | { |
|
| 215 | parts.push_back(str.substr(startPos, endPos-startPos)); |
229 | parts.push_back(str.substr(startPos, endPos-startPos)); |
| - | 230 | } |
|
| - | 231 | catch (std::out_of_range& e) |
|
| - | 232 | { |
|
| - | 233 | cout << "DEBUG: explode exception: " << e.what() << "\n"; |
|
| - | 234 | cout << "DEBUG: A str=" << str << " :: startPos=" << startPos << " :: endPos=" << endPos << endl; |
|
| - | 235 | continue; |
|
| - | 236 | } |
|
| - | 237 | ||
| 216 | startPos = endPos+delimiter.length(); |
238 | startPos = endPos+delimiter.length(); |
| 217 | } |
239 | } |
| 218 | 240 | ||
| 219 | if (startPos < str.length()) |
241 | if (startPos < str.length()) |
| 220 | { |
242 | { |
| - | 243 | try |
|
| - | 244 | { |
|
| 221 | parts.push_back(str.substr(startPos, str.length()-startPos)); |
245 | parts.push_back(str.substr(startPos, str.length()-startPos)); |
| - | 246 | } |
|
| - | 247 | catch (std::out_of_range& e) |
|
| - | 248 | { |
|
| - | 249 | cout << "DEBUG: explode exception: " << e.what() << "\n"; |
|
| - | 250 | cout << "DEBUG: B str=" << str << " :: startPos=" << startPos << " :: endPos=" << endPos << endl; |
|
| - | 251 | } |
|
| 222 | } |
252 | } |
| 223 | 253 | ||
| 224 | return parts; |
254 | return parts; |
| 225 | } |
255 | } |
| 226 | 256 | ||