void write_key_val(std::ostream &out, const std::string &key, const t_string &value, unsigned int level, std::string& textdomain)
{
	bool first = true;
	if (value.empty()) {
		out << std::string(level, '\t') << key << AttributeEquals
			<< AttributePrefix << AttributePostfix
			<< AttributeEndPostfix;;
		return;
	}

	for(t_string::walker w(value); !w.eos(); w.next()) {
		std::string part(w.begin(), w.end());

		if(w.translatable()) {
			if(w.textdomain() != textdomain) {
				out << TextdomainPrefix
					<< w.textdomain()
					<< TextdomainPostfix;
				textdomain = w.textdomain();
			}

			if(first) {
				out << std::string(level, '\t')
					<< key
					<< AttributeEquals;
			}

			out << TranslatableAttributePrefix
				<< escaped_string(part)
				<< AttributePostfix;

		} else {
			if(first) {
				out << std::string(level, '\t')
					<< key
					<< AttributeEquals;
			}

			out << AttributePrefix
				<< escaped_string(part)
				<< AttributePostfix;
		}

		if(w.last()) {
			out << AttributeEndPostfix;
		} else {
			out << AttributeContPostfix;
			out << std::string(level+1, '\t');
		}

		first = false;
	}
}
/**
 * Writes all the parts of a translatable string.
 * @note If the first part is translatable and in the wrong textdomain,
 *       the textdomain change has to happen before the attribute name.
 *       That is the reason for not outputting the key beforehand and
 *       letting this function do it.
 */
void write_key_val_visitor::operator()(t_string const &value) const
{
	bool first = true;

	for (t_string::walker w(value); !w.eos(); w.next())
	{
		std::string part(w.begin(), w.end());

		if (!first)
			out_ << " +\n";

		if (w.translatable() && w.textdomain() != textdomain_) {
			textdomain_ = w.textdomain();
			out_ << "#textdomain " << textdomain_ << '\n';
		}

		for (unsigned i = 0; i < level_; ++i) out_ << '\t';

		if (first)
			out_ << key_ << '=';
		else
			out_ << '\t';

		if (w.translatable())
			out_ << '_';

		out_ << '"' << escaped_string(part) << '"';
		first = false;
	}
}
Example #3
0
std::string MySQLQuery::escape(const std::string& raw) {
    if (!conn_) {
        LOG_WARN("event=[mysqlquery] type=[execute] status=[invalid]");
        return "";
    }
    std::unique_ptr<char[]> escaped_string( new char[raw.size() << 1 + 1]);

    int size = mysql_real_escape_string(conn_->handler(), escaped_string.get(), raw.c_str(), raw.size());

    return std::string(escaped_string.get(), size);
}
Example #4
0
std::string CMySQLConnection::escape_string(const std::string& str) const
{
    MYSQL* mysql_handler = static_cast<MYSQL*>(_mysql_handler);
    int escaped_string_length = 0;
    std::string escaped_string(str.size()*2+1, '\0');

    if (NULL == _mysql_handler)
    {
        escaped_string_length = mysql_escape_string(
                                    const_cast<char*>(escaped_string.data()), str.c_str(), str.length());
    }
    else
    {
        escaped_string_length = mysql_real_escape_string(
                                    mysql_handler, const_cast<char*>(escaped_string.data()), str.c_str(), str.length());
    }

    escaped_string.resize(escaped_string_length);
    return escaped_string;
}
Example #5
0
/*
	SEARCH / COMPANY
*/
tmdb_company_t *tmdb_search_company(const char *name)
{
	int			result;
	char			*url_str;
	char			*esc_name;
	net_data_t		data;
	tmdb_request_ctx_t	ctx;
	tmdb_company_t		*companies = NULL;

	init_data_chunk(&data);

	esc_name = escaped_string(name);

	memset(&ctx, 0, sizeof(tmdb_request_ctx_t));
	tmdb_ctx_set(&ctx, API_URL_F, NULL);
	tmdb_ctx_set(&ctx, API_HEADER_F, NULL);
	tmdb_ctx_set(&ctx, API_KEY_F, NULL);
	ctx.request_type.type = SEARCH_COMPANY;
	tmdb_ctx_set(&ctx, QUERY, esc_name);

	url_str = tmdb_get_url_from_ctx(&ctx);

	result = nethelper_get(url_str, API_HEADER, &data);

	free(url_str);
	free_ctx(&ctx);
	free(esc_name);

	if (!result) {
		header_process(&data);
		body_process(&data, SEARCH_COMPANY_NUM_TOKENS,
			     company_search_parse, &companies);
	}
	free_data_chunk(&data);

	return companies;
}
	void operator()(std::string const &s) const
	{ out_ << '"' << escaped_string(s) << '"'; }