<commit_before>/*
 * Copyright (c) 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <decof/cli/pubsub_context.h>

#include <chrono>
#include <iomanip>
#include <limits>
#include <string>
#include <sstream>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>

#include <decof/exceptions.h>
#include <decof/object_dictionary.h>

#include "encoder.h"

namespace {

struct iso8601_time
{
    std::chrono::time_point<std::chrono::system_clock> time_point;
};

std::ostream& operator<<(std::ostream& out, const iso8601_time& arg)
{
    std::time_t t = std::chrono::system_clock::to_time_t(arg.time_point);
    out << std::put_time(std::localtime(&t), "%FT%T.000Z");
    return out;
}

} // Anonymous namespace

namespace decof
{

namespace cli
{

pubsub_context::pubsub_context(boost::asio::ip::tcp::socket&& socket, object_dictionary& od, userlevel_t userlevel) :
    cli_context_base(od, userlevel),
    socket_(std::move(socket))
{
    boost::asio::socket_base::send_buffer_size option;
    socket_.get_option(option);<commit_msg>Fixed build on g++ < 5.<commit_after>/*
 * Copyright (c) 2014 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <decof/cli/pubsub_context.h>

#include <chrono>
#include <iomanip>
#include <limits>
#include <string>
#include <sstream>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/asio.hpp>
#include <boost/lexical_cast.hpp>

#include <decof/exceptions.h>
#include <decof/object_dictionary.h>

#include "encoder.h"

namespace {

struct iso8601_time
{
    std::chrono::time_point<std::chrono::system_clock> time_point;
};

std::ostream& operator<<(std::ostream& out, const iso8601_time& arg)
{
    std::time_t t = std::chrono::system_clock::to_time_t(arg.time_point);
#if defined(__GNUC__) && (__GNUC__ < 5)
    const size_t max_length = 25;
    char time_str[max_length];
    std::strftime(time_str, sizeof(time_str), "%FT%T.000Z", std::localtime(&now));
    out << time_str;
#else
    out << std::put_time(std::localtime(&t), "%FT%T.000Z");
#endif
    return out;
}

} // Anonymous namespace

namespace decof
{

namespace cli
{

pubsub_context::pubsub_context(boost::asio::ip::tcp::socket&& socket, object_dictionary& od, userlevel_t userlevel) :
    cli_context_base(od, userlevel),
    socket_(std::move(socket))
{
    boost::asio::socket_base::send_buffer_size option;
    socket_.get_option(option);
{'fraction_non_alphanumeric': 0.13160854893138357, 'fraction_numerical': 0.01265466816647919, 'mean_word_length': 5.008445945945946, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1522954', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1151, 'n_words': 313}