karma::lit and karma::string failure

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

karma::lit and karma::string failure

Mike Gresens
Hi,

see attached simple tests.

Best regards,
Mike...

/*
 * test.cpp
 *
 *  Created on: 30.07.2014
 *      Author: mgresens
 */

#include <boost/spirit/include/karma.hpp>

template <typename G>
void test_generator(const std::string& expected, G const& g)
{
    std::string s;
    std::back_insert_iterator<std::string> out(s);
    if (boost::spirit::karma::generate(out, g) && s == expected)
        std::cout << "ok" << std::endl;
    else
        std::cout << "fail" << std::endl;
}

int
main()
{
        const std::string string("H\x02\x00", 3);

        test_generator
        (
                string,
                boost::spirit::karma::lit(string)
        );

        test_generator
        (
                string,
                boost::spirit::karma::string(string)
        );

        return 0;
}
Reply | Threaded
Open this post in threaded view
|

Re: karma::lit and karma::string failure

Lee Clagett-2
On Fri, Aug 8, 2014 at 11:56 AM, Mike Gresens <[hidden email]> wrote:
Hi,

see attached simple tests.

Best regards,
Mike...

/*
 * test.cpp
 *
 *  Created on: 30.07.2014
 *      Author: mgresens
 */

#include <boost/spirit/include/karma.hpp>

template <typename G>
void test_generator(const std::string& expected, G const& g)
{
    std::string s;
    std::back_insert_iterator<std::string> out(s);
    if (boost::spirit::karma::generate(out, g) && s == expected)
        std::cout << "ok" << std::endl;
    else
        std::cout << "fail" << std::endl;
}

int
main()
{
        const std::string string("H\x02\x00", 3);

        test_generator
        (
                string,
                boost::spirit::karma::lit(string)
        );

        test_generator
        (
                string,
                boost::spirit::karma::string(string)
        );

        return 0;
}


Karma is currently using .c_str() for std::string, so it stops on first NULL character. This appears unnecessary because the code can already handler containers. I have a fix, but I will have to write three tests to verify each case. Then Joel/Harmut will have to review the pull request.

Lee

------------------------------------------------------------------------------

_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|

Re: karma::lit and karma::string failure

Lee Clagett-2
On Sat, Aug 9, 2014 at 7:06 PM, Lee Clagett <[hidden email]> wrote:
On Fri, Aug 8, 2014 at 11:56 AM, Mike Gresens <[hidden email]> wrote:
Hi,

see attached simple tests.

Best regards,
Mike...

/*
 * test.cpp
 *
 *  Created on: 30.07.2014
 *      Author: mgresens
 */

#include <boost/spirit/include/karma.hpp>

template <typename G>
void test_generator(const std::string& expected, G const& g)
{
    std::string s;
    std::back_insert_iterator<std::string> out(s);
    if (boost::spirit::karma::generate(out, g) && s == expected)
        std::cout << "ok" << std::endl;
    else
        std::cout << "fail" << std::endl;
}

int
main()
{
        const std::string string("H\x02\x00", 3);

        test_generator
        (
                string,
                boost::spirit::karma::lit(string)
        );

        test_generator
        (
                string,
                boost::spirit::karma::string(string)
        );

        return 0;
}


Karma is currently using .c_str() for std::string, so it stops on first NULL character. This appears unnecessary because the code can already handler containers. I have a fix, but I will have to write three tests to verify each case. Then Joel/Harmut will have to review the pull request.

Lee

A fix for this was merged to the develop branch [ https://github.com/boostorg/spirit/pull/62 ]. Not sure if it will make it into the master branch for boost 1.57, it doesn't appear so.

Lee


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general