Converting a Greek string of letters to all lower case
Jan 28, 2018 at 12:55pm UTC
So, I am trying to code a console program in Greek, and since I want to make the input non case sensitive, I wanted to create a function that converts all Greek letters of a string (Upper letters, Lower toned[accentuated] letters and Upper toned letters) into lower letters. I tried using maps to cross reference between strings, as well as check if it is toned/untoned lower/upper case letter (since they are not in order within UTF) Here's what I've attempted thus far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#include<iostream>
#include<windows.h>
#include<map>
using namespace std;
string sLower = " αβγδεζηθικλμνξοπρστυφχψω" ;
string sUpper = " ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ" ;
string sTLower = " άέήίόύώ" ;
string sTUpper = " ΆΈΉΊΌΎΏ" ;
string matchCase (string a){
map<char , bool > greekLower, uCheck, UTcheck, ltcheck;
map<char , char > greekUpper, greekTLower, greekTUpper;
string answer;
for (int i=1; i<=24; i++){
greekLower[sLower[i]] = true ;
greekUpper[sUpper[i]] = greekLower[i];
uCheck[sUpper[i]] = true ;
}
greekTLower['ά' ] = greekTUpper['Ά' ] = sLower[1];
greekTLower['έ' ] = greekTUpper['Έ' ] = sLower[5];
greekTLower['ή' ] = greekTUpper['Ή' ] = sLower[7];
greekTLower['ί' ] = greekTUpper['Ί' ] = sLower[10];
greekTLower['ό' ] = greekTUpper['Ό' ] = sLower[16];
greekTLower['ύ' ] = greekTUpper['Ύ' ] = sLower[21];
greekTLower['ώ' ] = greekTUpper['Ώ' ] = sLower[24];
LTcheck['ά' ] = UTcheck['Ά' ] = true ;
LTcheck['έ' ] = UTcheck['Έ' ] = true ;
LTcheck['ή' ] = UTcheck['Ή' ] = true ;
LTcheck['ί' ] = UTcheck['Ί' ] = true ;
LTcheck['ό' ] = UTcheck['Ό' ] = true ;
LTcheck['ύ' ] = UTcheck['Ύ' ] = true ;
LTcheck['ώ' ] = UTcheck['Ώ' ] = true ;
for (int i=0; i<a.size(); i++){
if (greekLower[a[i]]==true ){
answer.push_back(a[i]);
}
if (greekUpper[a[i]]==true ){
answer.push_back(greekUpper[a[i]]);
}
if (TLcheck[a[i]]==true ){
answer.push_back(greekTLower[a[i]]);
}
if (UTcheck[a[i]]==true ){
answer.push_back(greekTUpper[a[i]]);
}
}
return answer;
}
int main(){
system ("chcp 65001" );
string test;
cin>>test;
cout<<matchCase(test);
}
However it seems that it does not recognize the Greek letters as valid indexes? perhaps. Any suggestions?
Topic archived. No new replies allowed.