1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2011 New Dream Network
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_COMMON_STRTOL_H
16 #define CEPH_COMMON_STRTOL_H
23 long long strict_strtoll(const char *str, int base, std::string *err);
25 int strict_strtol(const char *str, int base, std::string *err);
27 double strict_strtod(const char *str, std::string *err);
29 float strict_strtof(const char *str, std::string *err);
31 uint64_t strict_sistrtoll(const char *str, std::string *err);
34 T strict_si_cast(const char *str, std::string *err);
36 /* On enter buf points to the end of the buffer, e.g. where the least
37 * significant digit of the input number will be printed. Returns pointer to
38 * where the most significant digit were printed, including zero padding.
39 * Does NOT add zero at the end of buffer, this is responsibility of the caller.
41 template<typename T, const unsigned base = 10, const unsigned width = 1>
43 char* ritoa(T u, char *buf)
45 static_assert(std::is_unsigned<T>::value, "signed types are not supported");
46 static_assert(base <= 16, "extend character map below to support higher bases");
49 *--buf = "0123456789abcdef"[u % base];
53 while (digits++ < width)