fork download
#include <iostream>
#include <string>
#include <cctype>
#include <vector>

typedef std::vector<std::string> DType;

DType MakeVector() {
	return { "snake_case","ODAI00_99_TEST","x_0_x","UpperCamelCase" };
}
int SelectChar(int Ch) {
	if (std::isdigit(Ch)) {
		return 1;//number
	}
	if (std::isalpha(Ch)) {//alphabet
		return 2;//upper
	}

	return 0;//graph
}
DType Split(const std::string& D){
	std::string S;
	DType R;
	int St = SelectChar(D.front());
	bool F = true;
	for(std::size_t i=0;i<D.size();i++){
		int V = SelectChar(D[i]);
		if (St == V) {
			if (F) {
				S += std::toupper(D[i]);
				F = false;
			}
			else {
				S += std::tolower(D[i]);	

			}
		}
		else {
			St = V;
			R.push_back(S);
			S.clear();
			i--;
			F = true;
		}
	}
	if (S.size()) R.push_back(S);
	return R;
}

std::string MakeHoge(const std::string& S) {
	DType D = Split(S);
	std::string R;

	for (std::size_t i = 0; i < D.size(); i++) {
		if (D[i][0] == '_') {
			if (static_cast<long long int>(i) - 1 >= 0) {
				if (!std::isdigit(D[i - 1].back())) { continue; }
				if (static_cast<long long int>(i) + 1 < D.size() && std::isdigit(D[i + 1].front())) { R += '_'; }	
			}
			continue;
		}	
		R += D[i];
	}
	return R;
}
int main() {
	DType D = MakeVector();
	
	for (auto& o : D) {
		auto R = MakeHoge(o);
		std::cout << o << " => " << R << std::endl;
	}

	return 0;
}
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
snake_case => SnakeCase
ODAI00_99_TEST => Odai00_99Test
x_0_x => X0X
UpperCamelCase => Uppercamelcase