コード例 #1
0
ファイル: LexicalCast.cpp プロジェクト: 619213152/vpal20
    void testInteger (IntType in)
    {
        std::string s;
        IntType out (in+1);

        expect (lexicalCastChecked (s, in));
        expect (lexicalCastChecked (out, s));
        expect (out == in);
    }
コード例 #2
0
ファイル: LexicalCast.cpp プロジェクト: 619213152/vpal20
    bool tryEdgeCase (std::string const& s)
    {
        T ret;

        bool const result = lexicalCastChecked (ret, s);

        if (!result)
            return false;

        return s == std::to_string (ret);
    }
コード例 #3
0
ファイル: SemanticVersion.cpp プロジェクト: E-LLP/rippled
bool isNumeric (std::string const& s)
{
    int n;

    // Must be convertible to an integer
    if (!lexicalCastChecked (n, s))
        return false;

    // Must not have leading zeroes
    return std::to_string (n) == s;
}
コード例 #4
0
ファイル: SemanticVersion.cpp プロジェクト: E-LLP/rippled
bool chopUInt (int& value, int limit, std::string& input)
{
    // Must not be empty
    if (input.empty ())
        return false;

    auto left_iter = std::find_if_not (input.begin (), input.end (),
        [](std::string::value_type c)
        {
            return std::isdigit (c, std::locale::classic());
        });

    std::string item (input.begin (), left_iter);

    // Must not be empty
    if (item.empty ())
        return false;

    int n;

    // Must be convertible to an integer
    if (!lexicalCastChecked (n, item))
        return false;

    // Must not have leading zeroes
    if (std::to_string (n) != item)
        return false;

    // Must not be out of range
    if (n < 0 || n > limit)
        return false;

    input.erase (input.begin (), left_iter);
    value = n;

    return true;
}
コード例 #5
0
ファイル: LexicalCast.cpp プロジェクト: 619213152/vpal20
    void testZero ()
    {
        testcase ("zero conversion");

        {
            std::int32_t out;

            expect (lexicalCastChecked (out, "-0"), "0");
            expect (lexicalCastChecked (out, "0"), "0");
            expect (lexicalCastChecked (out, "+0"), "0");
        }

        {
            std::uint32_t out;

            expect (!lexicalCastChecked (out, "-0"), "0");
            expect (lexicalCastChecked (out, "0"), "0");
            expect (lexicalCastChecked (out, "+0"), "0");
        }
    }
コード例 #6
0
ファイル: LexicalCast.cpp プロジェクト: 619213152/vpal20
 void tryBadConvert (std::string const& s)
 {
     T out;
     expect (!lexicalCastChecked (out, s), s);
 }