Rcpp Version 1.1.2
Loading...
Searching...
No Matches
StringTransformer.h
Go to the documentation of this file.
1
2// clone.h: Rcpp R/C++ interface class library -- clone RObject's
3//
4// Copyright (C) 2010 - 2025 Dirk Eddelbuettel and Romain Francois
5//
6// This file is part of Rcpp.
7//
8// Rcpp is free software: you can redistribute it and/or modify it
9// under the terms of the GNU General Public License as published by
10// the Free Software Foundation, either version 2 of the License, or
11// (at your option) any later version.
12//
13// Rcpp is distributed in the hope that it will be useful, but
14// WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
20
21#ifndef Rcpp__StringTransformer_h
22#define Rcpp__StringTransformer_h
23
24#include <RcppCommon.h>
25
26namespace Rcpp{
27
28 template <typename UnaryOperator>
29 class StringTransformer : public std::function<const char*(const char*)> {
30 public:
31 StringTransformer( const UnaryOperator& op_ ): op(op_), buffer(){}
33
34 const char* operator()(const char* input ) {
35 buffer = input;
36 std::transform( buffer.begin(), buffer.end(), buffer.begin(), op );
37 return buffer.c_str();
38 }
39
40 private:
41 const UnaryOperator& op;
42 std::string buffer;
43 };
44
45 template <typename UnaryOperator>
49
50}
51
52#endif
StringTransformer(const UnaryOperator &op_)
const char * operator()(const char *input)
const UnaryOperator & op
Rcpp API.
Definition algo.h:28
StringTransformer< UnaryOperator > make_string_transformer(const UnaryOperator &fun)