Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Last active August 29, 2015 14:10
Show Gist options
  • Save yutannihilation/bfbc134dc0047062b3b2 to your computer and use it in GitHub Desktop.
Save yutannihilation/bfbc134dc0047062b3b2 to your computer and use it in GitHub Desktop.
Rcpp hexdump
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
std::vector<std::string> rcpp_hello_world(std::vector<std::string> strings) {
for(std::vector<std::string>::iterator s_it = strings.begin(); s_it != strings.end(); ++s_it) {
std::vector<unsigned char> c((*s_it).begin(), (*s_it).end());
int length = c.size();
for (int i = 0; i < length; i++){
// Japanese characters are 3 byte length;
if( (length - i > 2) &&
(c[i] == 0xEF) &&
(c[i+1] == 0xBC) &&
(c[i+2] >= 0x90) &&
(c[i+2] <= 0x99) ) {
c[i] = c[i+2] - 0x60;
c.erase( c.begin() + i + 1, c.begin() + i + 3 );
}
}
(*s_it) = std::string(c.begin(), c.end());
}
return strings;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment