| 7 | #include <util/generic/yexception.h> |
| 8 | |
| 9 | static inline size_t ParseHex(const TString& s) { |
| 10 | if (s.empty()) { |
| 11 | ythrow yexception() << "can not parse chunk length(empty string)"; |
| 12 | } |
| 13 | |
| 14 | size_t ret = 0; |
| 15 | |
| 16 | for (TString::const_iterator c = s.begin(); c != s.end(); ++c) { |
| 17 | const char ch = *c; |
| 18 | |
| 19 | if (ch >= '0' && ch <= '9') { |
| 20 | ret *= 16; |
| 21 | ret += ch - '0'; |
| 22 | } else if (ch >= 'a' && ch <= 'f') { |
| 23 | ret *= 16; |
| 24 | ret += 10 + ch - 'a'; |
| 25 | } else if (ch >= 'A' && ch <= 'F') { |
| 26 | ret *= 16; |
| 27 | ret += 10 + ch - 'A'; |
| 28 | } else if (ch == ';') { |
| 29 | break; |
| 30 | } else if (isspace(ch)) { |
| 31 | continue; |
| 32 | } else { |
| 33 | ythrow yexception() << "can not parse chunk length(" << s.data() << ")"; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | static inline char* ToHex(size_t len, char* buf) { |
| 41 | do { |
no test coverage detected