/* This file is part of cpp-ethereum. cpp-ethereum is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. cpp-ethereum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with cpp-ethereum. If not, see . */ /** @file CommonData.cpp * @author Gav Wood * @date 2014 */ #include "CommonData.h" #include "Exceptions.h" using namespace std; using namespace dev; std::string dev::escaped(std::string const& _s, bool _all) { static const map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; std::string ret; ret.reserve(_s.size() + 2); ret.push_back('"'); for (auto i: _s) if (i == '"' && !_all) ret += "\\\""; else if (i == '\\' && !_all) ret += "\\\\"; else if (prettyEscapes.count(i) && !_all) { ret += '\\'; ret += prettyEscapes.find(i)->second; } else if (i < ' ' || _all) { ret += "\\x"; ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); } else ret.push_back(i); ret.push_back('"'); return ret; } int dev::fromHex(char _i, WhenError _throw) { if (_i >= '0' && _i <= '9') return _i - '0'; if (_i >= 'a' && _i <= 'f') return _i - 'a' + 10; if (_i >= 'A' && _i <= 'F') return _i - 'A' + 10; if (_throw == WhenError::Throw) BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i)); else return -1; } bytes dev::fromHex(std::string const& _s, WhenError _throw) { unsigned s = (_s.size() >= 2 && _s[0] == '0' && _s[1] == 'x') ? 2 : 0; std::vector ret; ret.reserve((_s.size() - s + 1) / 2); if (_s.size() % 2) { int h = fromHex(_s[s++], WhenError::DontThrow); if (h != -1) ret.push_back(h); else if (_throw == WhenError::Throw) BOOST_THROW_EXCEPTION(BadHexCharacter()); else return bytes(); } for (unsigned i = s; i < _s.size(); i += 2) { int h = fromHex(_s[i], WhenError::DontThrow); int l = fromHex(_s[i + 1], WhenError::DontThrow); if (h != -1 && l != -1) ret.push_back((byte)(h * 16 + l)); else if (_throw == WhenError::Throw) BOOST_THROW_EXCEPTION(BadHexCharacter()); else return bytes(); } return ret; } 22Q2 FreeBSD Ports (https://github.com/freebsd/freebsd-ports)
aboutsummaryrefslogtreecommitdiffstats
Commit message (Expand)AuthorAgeFilesLines
* */libreoffice: update LibreOffice suite to 7.4.3 release (+)Dima Panov2022-11-281-3/+3
* editors/libreoffice: update to 7.4.2 release (+)Dima Panov2022-10-141-3/+3
* editors/libreoffice: update to 7.4.1 release (+)Dima Panov2022-09-181-3/+3
* editors/libreoffice: update to 7.4.0 release (+)Dima Panov2022-08-181-3/+3
* editors/libreoffice: update to 7.3.5 release (+)Dima Panov2022-07-241-3/+3
* */libreoffice*: update to 7.3.4 release (+)Dima Panov2022-06-101-3/+3
* editors/libreoffice: update to 7.3.3 release (+)Dima Panov2022-05-071-3/+3
* */libreoffice*: update to 7.3.2 release (+)Dima Panov2022-04-011-3/+3
* LibreOffice 7.3.1 Community, the first minor release of the LibreOffice 7.3 f...Dima Panov2022-03-051-3/+3
* Please welcome new generation release of LibreOffice suite - 7.3.0! (+)Dima Panov2022-02-171-3/+3
* Please welcome LibreOffice suite 7.2.5 release! (+)Dima Panov2022-01-061-3/+3
* LibreOffice 7.2.4 Community release available ahead of schedule to provide an...Dima Panov2021-12-101-3/+3
* LibreOffice 7.2.3 is now available, with over 100 bugfixes and compatibility ...Dima Panov2021-11-261-3/+3
* editors/libreoffice: update to 7.2.2 release (+)Dima Panov2021-10-141-3/+3
* editors/libreoffice: update to 7.2.1 release (+)Dima Panov2021-09-171-3/+3
* editors/libreoffice: Please welcome LibreOffice suite 7.2.0 release!Dima Panov2021-08-201-3/+3
* editors/libreoffice: Update to 7.1.5Li-Wen Hsu2021-07-231-3/+3
* editors/libreoffice: Update to 7.1.4Li-Wen Hsu2021-06-201-3/+3
* editors/libreoffice: Update to 7.1.3 releaseDima Panov2021-05-091-3/+3
* One more small cleanup, forgotten yesterday.Mathieu Arnold2021-04-071-1/+0
* Remove # $FreeBSD$ from Makefiles.Mathieu Arnold2021-04-061-1/+0
* editors/libreoffice: update to 7.1.2 releaseDima Panov2021-04-061-3/+3
* LibreOffice 7.1.1 is now available, with over 90 bugfixes and compatibility i...Dima Panov2021-03-081-3/+3
* Please welcome LibreOffice suite 7.1.0 release!Dima Panov2021-02-041-3/+3
* LibreOffice 7.0.4 is here, with over 110 bugfixes and compatibility improveme...Dima Panov2020-12-181-3/+3
* editors/libreoffice-*: use release-rolled i18n tarballsDima Panov2020-10-291-3/+3
* Update LibreOffice suite to 7.0.3 releaseDima Panov2020-10-291-3/+3
* LibreOffice 7.0.2 is now available, with over 130 bugfixes and compatibility ...Dima Panov2020-10-091-3/+3
* - Update LibreOffice suite to 7.0.1 releaseDima Panov2020-09-041-3/+3
* LibreOffice suite: update to 7.0.0 releaseDima Panov2020-08-161-3/+3
* Update LibreOffice suite to 6.4.6 maintenance releaseDima Panov2020-08-141-3/+3
* Update LibreOffice suite to 6.4.5 releaseDima Panov2020-07-071-3/+3
* FreeBSD Office team is proud to announce LibreOffice 6.4.4, latest stable rel...Dima Panov2020-06-131-3/+3
* Update LibreOffice to 6.3.6 stable releaseDima Panov2020-05-161-3/+3
* - Update to 6.3.4Li-Wen Hsu2019-12-131-3/+3
* - Update to 6.3.3Li-Wen Hsu2019-11-011-3/+3
* - Update to 6.3.2Li-Wen Hsu2019-09-281-3/+3
* - Update to 6.3.1Li-Wen Hsu2019-09-061-3/+3
* - Update to 6.3.0Li-Wen Hsu2019-08-201-3/+3
* - Update to 6.2.5Li-Wen Hsu2019-07-081-3/+3
* - Update to 6.2.4Li-Wen Hsu2019-05-241-3/+3
* - Update to 6.2.3Li-Wen Hsu2019-04-21