// // exception.cxx // dice // // Created by Sam Jaffe on 12/17/18. // Copyright © 2018 Sam Jaffe. All rights reserved. // #include "dice-roll/exception.h" #include #include static std::string carrot(long long pos) { if (pos == -1) return ""; // For safety std::string out; // resize(0) followed by back() will cause UB out.resize(std::max(pos, 1ll), '~'); out.back() = '^'; return out; } namespace dice { unexpected_token::unexpected_token(std::string const & reason, long long pos) : std::runtime_error(reason), position(pos) {} std::string unexpected_token::pointer(long long backup_length) const { return carrot(position == -1 ? backup_length : position); } }