#include <cstddef>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <string>

void sanitize(std::string &stringValue)
{
    // Add backslashes.
    for (auto i = stringValue.begin();;) {
        auto const pos = std::find_if(
            i, stringValue.end(),
            [](char const c) { return '\\' == c || '\'' == c || '"' == c; }
        );
        if (pos == stringValue.end()) {
            break;
        }
        i = std::next(stringValue.insert(pos, '\\'), 2);
    }

    // Removes others.
    stringValue.erase(
        std::remove_if(
            stringValue.begin(), stringValue.end(), [](char const c) {
                return '\n' == c || '\r' == c || '\0' == c || '\x1A' == c;
            }
        ),
        stringValue.end()
    );
}

int main()
{
	std::string s = "hello\" \"wo'rld\\ this is\na test";
	std::cout << s << "\n---\n";
	sanitize(s);
	std::cout << s << "\n---\n";
}
