Мой велосипед или о том как я сэкономил свои нервные клетки
#include
using namespace std;
std::string Toreplace(std::string text, std::string s, std::string d){
for(int index=0; index=text.find(s, index), index!=std::string::npos;) {
text.replace(index, s.length(), d);
index+=d.length();
}
return text;
}
int GetCurentLang(std::string str){
int thislang = 0;
const char *cstr = str.c_str();
std::string russtr[66] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю","ё","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю","Ё"};
std::string engstr[56] = {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l","z","x","c","v","b","n","m","<",">","Q","W","E","R","T","Y","U","I","O","P","A","S","D","F","G","H","J","K","L","Z","X","C","V","B","N","M"};
for (int i = 0; i < str.length() && thislang == 0; i++){
for (int a = 0; a < 66; a++){
if (russtr[a].compare(new char (cstr[i])) == true) {
thislang = 1;
}
}
for (int a = 0; a < 56; a++){
if (engstr[a].compare(new char (cstr[i])) == true) {
thislang = 2;
}
}
}
return thislang;
}
std::string TranslateToRu(std::string str){
std::string translate = str;
std::string replacein[67] = {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",",".","/","Q","W","E","R","T","Y","U","I","O","P","[","]","A","S","D","F","G","H","J","K","L",";","'","Z","X","C","V","B","N","M",",",".","/","&"};
std::string replaceto[67] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю",".","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю",".","?"};
for (int i = 0; i < 67; i++){
translate = Toreplace(translate, replacein[i], replaceto[i]);
}
return translate;
}
std::string TranslateToEng(std::string str){
std::string translate = str;
std::string replacein[67] = {"й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю",".","Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю",".","?"};
std::string replaceto[67] = {"q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",",".","/","Q","W","E","R","T","Y","U","I","O","P","[","]","A","S","D","F","G","H","J","K","L",";","'","Z","X","C","V","B","N","M","<",">","/","&"};
for (int i = 0; i < 67; i++){
translate = Toreplace(translate, replacein[i], replaceto[i]);
}
return translate;
}
int main(int argc, char *argv[]) {
std::string translate;
int currentlang = GetCurentLang(argv[1]);
if (currentlang == 2){
translate = TranslateToRu(argv[1]);
}else if (currentlang == 1){
translate = TranslateToEng(argv[1]);
}else{
translate = "";
}
cout << translate << endl;
return 0;
}