Created
October 9, 2014 13:04
-
-
Save c4tachan/78e591cd12d229c5080b to your computer and use it in GitHub Desktop.
Get a string from the console, convert the characters to "funny" characters, and return the "translated" string. This will help test the language translation system I use at work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TestLanguageGenerator.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
#include <string> | |
#include <cwctype> | |
#include <clocale> | |
std::wstring translatedString; | |
const wchar_t charConvert(wchar_t inC) | |
{ | |
wchar_t output; | |
// Statics I use to itterate through each collection of "funny characters" | |
static int iaa = 0; | |
static int ibb = 0; | |
static int icc = 0; | |
static int idd = 0; | |
static int iee = 0; | |
static int iff = 0; | |
static int igg = 0; | |
static int ihh = 0; | |
static int ijj = 0; | |
static int ikk = 0; | |
static int ill = 0; | |
static int imm = 0; | |
static int inn = 0; | |
static int ioo = 0; | |
static int ipp = 0; | |
static int iqq = 0; | |
static int irr = 0; | |
static int iss = 0; | |
static int itt = 0; | |
static int iuu = 0; | |
static int ivv = 0; | |
static int iww = 0; | |
static int ixx = 0; | |
static int iyy = 0; | |
static int izz = 0; | |
// Strings of "Funny characters" to replace "normal characters" with | |
const wchar_t* A = L"AÀÁÂÃÄÅĀĂǞǠǍǺȀȂḀẠẢẤẦẨẪẬẮẰẲẴẶ"; | |
const wchar_t* b = L"BßƁḂḄḆ"; | |
const wchar_t* c = L"CÇĆĈĊČƇḈ"; | |
const wchar_t* d = L"DÐĎĐƉƊḊḌḎḐḒ"; | |
const wchar_t* e = L"EÈÉÊËĒĔĖĘĚƎƐȄȆḔḖḘḚḜẸẺẼẾỀỂỄỆ"; | |
const wchar_t* f = L""; | |
const wchar_t* g = L""; | |
const wchar_t* h = L""; | |
const wchar_t* i = L""; | |
const wchar_t* j = L""; | |
const wchar_t* k = L""; | |
const wchar_t* l = L""; | |
const wchar_t* m = L""; | |
const wchar_t* n = L""; | |
const wchar_t* o = L""; | |
const wchar_t* p = L""; | |
const wchar_t* q = L""; | |
const wchar_t* r = L""; | |
const wchar_t* s = L""; | |
const wchar_t* t = L""; | |
const wchar_t* u = L""; | |
const wchar_t* v = L""; | |
const wchar_t* w = L""; | |
const wchar_t* x = L""; | |
const wchar_t* y = L""; | |
const wchar_t* z = L""; | |
switch (inC) | |
{ | |
case L'A': | |
case L'a': | |
output = wchar_t(A[iaa++ % wcslen(A)]); | |
break; | |
case L'B': | |
case L'b': | |
output = wchar_t(b[ibb++ % wcslen(b)]); | |
break; | |
//Thes aren't finished yet, but they will work like the ones above | |
case L'C': | |
output = L'Ĉ'; | |
break; | |
case L'c': | |
output = L'ċ'; | |
break; | |
case L'D': | |
output = L'Đ'; | |
break; | |
case L'd': | |
output = L'ď'; | |
break; | |
case L'E': | |
output = L'Ɛ'; | |
break; | |
case L'e': | |
output = L'Ə'; | |
break; | |
case L'F': | |
output = L'F'; | |
break; | |
case L'G': | |
output = L'G'; | |
break; | |
case L'H': | |
output = L'H'; | |
break; | |
case L'I': | |
output = L'I'; | |
break; | |
case L'J': | |
output = L'J'; | |
break; | |
case L'K': | |
output = L'K'; | |
break; | |
case L'L': | |
output = L'L'; | |
break; | |
case L'M': | |
output = L'M'; | |
break; | |
case L'N': | |
output = L'N'; | |
break; | |
case L'O': | |
output = L'O'; | |
break; | |
case L'P': | |
output = L'P'; | |
break; | |
case L'Q': | |
output = L'Q'; | |
break; | |
case L'R': | |
output = L'R'; | |
break; | |
case L'S': | |
output = L'S'; | |
break; | |
case L'T': | |
output = L'T'; | |
break; | |
case L'U': | |
output = L'U'; | |
break; | |
case L'V': | |
output = L'V'; | |
break; | |
case L'W': | |
output = L'W'; | |
break; | |
case L'X': | |
output = L'X'; | |
break; | |
case L'Y': | |
output = L'Y'; | |
break; | |
case L'Z': | |
output = L'Z'; | |
break; | |
default: | |
return inC; | |
break; | |
} | |
if(iswlower(inC)) | |
{ | |
output = towlower(output); | |
} | |
return output; | |
} | |
const wchar_t* translate(std::wstring const in) | |
{ | |
translatedString = L""; | |
for(unsigned int i = 0; i < in.length(); i++) | |
{ | |
translatedString += charConvert(wchar_t(in[i])); | |
} | |
return translatedString.c_str(); | |
} | |
// The entry point for the console application | |
int _tmain(int argc, char* argv[]) | |
{ | |
std::wstring input; | |
//std::wcerr << | |
_wsetlocale(LC_ALL, L""); // << std::endl; | |
do | |
{ | |
std::wcerr << L"Enter text to be translated" << std::endl; | |
std::wcin >> input; | |
std::wcout << translate(input); | |
std::wcout << std::endl; | |
} while (1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's the biggest issue I have seen so far:
Note that the "translated" output string is cut off, and the std::endl is not printed to the terminal.