Revision d0f00273a3e38274e7ea6f2c3f65cfc2235c2f90 authored by Steven Johnson on 13 December 2022, 20:52:30 UTC, committed by GitHub on 13 December 2022, 20:52:30 UTC
* [xtensa] Add xtensa_io.cpp

This is a better option than posix_io.cpp on Xtensa

* Update xtensa_io.cpp
1 parent 128be06
Raw File
regexp_replace.cpp
#include <cassert>
#include <cstring>
#include <iostream>
#include <regex>

// A utility that does a single regexp-based replace on stdin and dumps it to stdout.
// Exists solely because we can't rely on (e.g.) `sed` being available in Windows
// build environments. Usage is basically equivalent to `sed -e 's/regex/replacement/g'`
// Note that if regex is an empty string, this becomes a simple line-by-line file copy.

int main(int argc, const char **argv) {
    if (argc != 3) {
        fprintf(stderr, "Usage: %s regex replacement\n", argv[0]);
        return -1;
    }
    std::regex re(argv[1]);

    std::string line;
    while (std::getline(std::cin, line)) {
        std::regex_replace(std::ostreambuf_iterator<char>(std::cout),
                           line.begin(), line.end(), re, argv[2]);
        std::cout << std::endl;
    }
    return 0;
}
back to top