File: string.f

package info (click to toggle)
bobcat 6.11.00-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,292 kB
  • sloc: cpp: 21,370; fortran: 6,507; makefile: 2,787; sh: 724; perl: 401; ansic: 26
file content (34 lines) | stat: -rw-r--r-- 754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
inline int String::casecmp(std::string const &lhs, std::string const &rhs)
{
    return strcasecmp(lhs.c_str(), rhs.c_str());
}

//static
template <std::unsigned_integral ValueType>
std::string String::to_string(ValueType value, unsigned base)
{
    std::string ret;
    if (not (2 <= base and base <= 36))         // 2 <= base <= 36
        return ret;

    if (value == 0)
        return ret = "0";

    std::string reversed;
    char const a10 = 'a' - 10;
    while (value != 0)
    {
        unsigned modVal = value % base;
        reversed.push_back( (modVal < 10 ? '0' : a10) + modVal);
        value /= base;
    }

    ret.reserve(reversed.length());
    reverse_copy(reversed.begin(), reversed.end(), back_inserter(ret));

    return ret;
}