Пример #1
0
template <typename Iter, typename Other> inline bool
operator == (range<Iter> const &value, range<Other> const &other) {
	if (value.size() == other.size()) {
		return value.empty() ? true : std::equal(value.begin(), value.end(), other.begin());
	}
	return false;
}
Пример #2
0
inline bool
operator == (range<char const*> const &value, range<char const*> const &other) {
	if (value.size() == other.size()) {
		return value.empty() ? true : strncmp(value.begin(), other.begin(), value.size()) == 0;
	}
	return false;
}
    void compare (Distances distances, Reference const & reference_)
{
    auto reference = range::view (reference_);

    while (!empty (reference)) {
        BOOST_CHECK (!empty (distances));
        if (empty (distances))
            return;

        auto d = chop_in_place (distances);
        auto r = chop_in_place (reference);
        BOOST_CHECK_EQUAL (first (d), first (r));
        BOOST_CHECK_EQUAL (second (d), second (r));
    }
    BOOST_CHECK (empty (distances));
}
Пример #4
0
template <class Parser> void check_repeat_a (Parser const & parser) {
    using range::empty; using range::first; using range::drop;
    {
        std::string r ("aa");
        auto result = parse (parser, r);
        BOOST_CHECK (success (result));
        auto o = output (result);
        BOOST_CHECK (!empty (o));
        BOOST_CHECK (!empty (drop (o)));
        BOOST_CHECK (empty (drop (drop (o))));
        BOOST_CHECK_EQUAL (first (o), 'a');
        BOOST_CHECK_EQUAL (first (drop (o)), 'a');
        BOOST_CHECK (empty (rest (result)));
    }
    {
        std::string r ("ab");
        auto result = parse (parser, r);
        BOOST_CHECK (success (result));
        auto o = output (result);
        BOOST_CHECK (!empty (o));
        BOOST_CHECK (empty (drop (o)));
        BOOST_CHECK_EQUAL (first (o), 'a');
        BOOST_CHECK_EQUAL (first (rest (result)), 'b');
    }
    {
        std::string r ("b");
        auto result = parse (parser, r);
        BOOST_CHECK (success (result));
        auto o = output (result);
        BOOST_CHECK (empty (o));
        BOOST_CHECK_EQUAL (first (rest (result)), 'b');
    }
}
Пример #5
0
    void write_code_file(range const& file, range const& file_type) {
        int output_pipe[2];
        if (-1 == pipe(output_pipe)) {
            std::cerr << "could not create pipe for source-highlight\n";
            return;
        }

        int cpid = fork();
        if (-1 == cpid) {
            std::cerr << "could not create fork for source-highlight\n";
            return;
        }

        if (! cpid) {
            // source-highlight process
            close(output_pipe[0]);
            dup2(output_pipe[1], STDOUT_FILENO);

            std::string fileStr = file; // to append null

            if (file_type.empty())
                execlp(
                    "source-highlight", "source-highlight",
                    "-i", fileStr.c_str(), 0);
            else {
                std::string typeStr = file_type;
                execlp(
                    "source-highlight", "source-highlight",
                    "-s", typeStr.c_str(), "-i", fileStr.c_str(), 0);
            }

            std::cerr << "could not execute source-highlight\n";
            close(output_pipe[1]);
            return;
        }
        else {
            close(output_pipe[1]);
            print_source_highlight(output_pipe[0]);
            close(output_pipe[0]);
        }
    }
Пример #6
0
inline bool
operator > (range<char const*> const &value, range<char const*> const &other) {
	return (!value.empty() && !other.empty()) ? (strncmp(value.begin(), other.begin(), std::max(value.size(), other.size())) > 0) : !value.empty();
}
Пример #7
0
template <typename Iter, typename Other> inline bool
operator > (range<Iter> const &value, range<Other> const &other) {
	std::greater<typename std::iterator_traits<Iter>::value_type> pred;
	return (!value.empty() && !other.empty()) ? std::lexicographical_compare(value.begin(), value.end(), other.begin(), other.end(), pred) : !value.empty();
}
Пример #8
0
template <typename Iter, typename Other> inline bool
operator < (range<Iter> const &value, range<Other> const &other) {
	return (!value.empty() && !other.empty()) ? std::lexicographical_compare(value.begin(), value.end(), other.begin(), other.end()) : !other.empty();
}