Skip to content

Instantly share code, notes, and snippets.

@shnya
shnya / Surrogate Pair Test
Created December 24, 2010 12:54
Surrogate Pair Test (For Linx)
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <wchar.h>
#include <string>
#include <iconv.h>
@shnya
shnya / C++ split: boost version
Created December 9, 2010 18:05
C++ split: boost version
boost_split, vector<string> v;
boost::algorithm::split(v, str, bind2nd(equal_to<char>(), ' ')
@shnya
shnya / C++ split: copy, istream_iteartor, back_inserter version
Created December 9, 2010 18:04
C++ split: copy, istream_iteartor, back_inserter version
vector<string> split(const string &str){
istringstream iss(str); vector<string> res;
copy(istream_iterator<string>(iss), istream_iterator<string>(), back_inserter(res));
return res;
}
@shnya
shnya / C++ split: stringstream version
Created December 9, 2010 18:04
C++ split: stringstream version
vector<string> split(const string &str, char delim){
istringstream iss(str); string tmp; vector<string> res;
while(getline(iss, tmp, delim)) res.push_back(tmp);
return res;
}
@shnya
shnya / C++ split: find version
Created December 9, 2010 18:01
C++ split: find version
vector<string> split(const string &str, const string &delim){
vector<string> res;
size_t current = 0, found, delimlen = delim.size();
while((found = str.find(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + delimlen;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
@shnya
shnya / C++ split(find_first_of version)
Created December 9, 2010 16:56
C++ split : find_first_of version
vector<string> split(const string &str, char delim){
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
string decode(string cipherText, int shift)
{
size_t len = cipherText.size();
string res(cipherText);
for(size_t i = 0; i < len; i++){
int c = res[i] - 'A';
if(c - shift < 0)
c = 26 + (c - shift);
else
c = c - shift;