Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Java программирование > Общие вопросы по Java, Java SE, Kotlin
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 28.12.2018, 10:42   #1
Nastya2018
Форумчанин
 
Регистрация: 24.07.2018
Сообщений: 133
По умолчанию Проверка на кириллические символы

я написала конвертер который конвертирует кириллицу в латиницу. Помогите написать функцию Который пройдется по латинскому алфавиту в классе Dictionary и проверит есть ли там кириллические символы.

Код:
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.IntStream;
 
        public class Main {
        public static void main(String[] args) throws  IOException {
    	final String DEFAULT_ENCODING = "utf-8";
    	
    	if(args.length < 2 || args.length > 3) {
    		System.out.println("Неверное количество аргументов");
    		System.exit(1);
    	}
    	
    	String inputFilePath = args[0];
    	String outputFilePath = args[1];	
    	String fileEncoding = args.length == 2 ? DEFAULT_ENCODING : args[2];
        
        
        

        
        

        
        
        BufferedReader in = new BufferedReader( new InputStreamReader(new FileInputStream(inputFilePath), fileEncoding));
        File file = new File(outputFilePath);
        FileOutputStream fileOutputStream = new FileOutputStream(file, false);
        
        Writer writer = new OutputStreamWriter(fileOutputStream, StandardCharsets.UTF_8);
        
        String line;
        StringBuilder result = new StringBuilder();
        
        Map<String, String> dictionary = new Dictionary().getDictionary();
        
        while ((line = in.readLine()) != null) {
            String outLine = convertString(line, dictionary) + System.getProperty("line.separator");
            System.out.println(line);
            System.out.println(outLine);
            result.append(outLine) ;
        }
        
        writer.write(result.toString());
        
        in.close();
        writer.flush();
        writer.close();
                
        }
        
 
    public static String convertString(String str, Map<String, String> dictionary) {
        char[] chars = str.toCharArray();
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < chars.length; i++) {
            if (dictionary.containsKey(Character.toString(chars[i]))) {
                stringBuilder.append(dictionary.get(Character.toString(chars[i])));
                continue;
            }
            stringBuilder.append(chars[i]);
        }
        return stringBuilder.toString();
    }
}
 
class Dictionary {
    private Map<String, String> dictionary;
 
    public Dictionary() {
        dictionary = new HashMap<>();
        dictionary = new HashMap<>();
        dictionary.put("а", "a");
        dictionary.put("А", "A");
        dictionary.put("ә", "á");
        dictionary.put("Ә", "Á");
        dictionary.put("б", "b");
        dictionary.put("Б", "B");
        dictionary.put("д", "d");
        dictionary.put("Д", "D");
        dictionary.put("е", "e");
        dictionary.put("Е", "E");
        dictionary.put("ф", "f");
        dictionary.put("Ф", "F");
        dictionary.put("г", "g");
        dictionary.put("Г", "G");
        dictionary.put("ғ", "ǵ");
        dictionary.put("Ғ", "Ǵ");        
        dictionary.put("х", "h");
        dictionary.put("Х", "H");
        dictionary.put("һ", "һ");
        dictionary.put("Һ", "H");
        dictionary.put("і", "i");
        dictionary.put("І", "I");
        dictionary.put("и", "ı");
        dictionary.put("И", "I");
        dictionary.put("й", "ı");
        dictionary.put("Й", "I");
        dictionary.put("ж", "j");
        dictionary.put("Ж", "J");
        dictionary.put("к", "k");
        dictionary.put("К", "K");
        dictionary.put("л", "l");
        dictionary.put("Л", "L");
        dictionary.put("м", "m");
        dictionary.put("М", "M");
        dictionary.put("н", "n");
        dictionary.put("Н", "N");
        dictionary.put("ң", "ń");
        dictionary.put("Ң", "Ń");
        dictionary.put("о", "o");
        dictionary.put("О", "O");
        dictionary.put("ө", "ó");
        dictionary.put("Ө", "Ó");
        dictionary.put("п", "p");
        dictionary.put("П", "P");
        dictionary.put("қ", "q");
        dictionary.put("Қ", "Q");
        dictionary.put("р", "r");
        dictionary.put("Р", "R");
        dictionary.put("с", "s");
        dictionary.put("С", "S");
        dictionary.put("ш", "sh");
        dictionary.put("Ш", "Sh");
        dictionary.put("ч", "ch");
        dictionary.put("Ч", "Ch");
        dictionary.put("т", "t");
        dictionary.put("Т", "T");
        dictionary.put("ү", "ú");
        dictionary.put("Ү", "Ú");
        dictionary.put("ұ", "u");
        dictionary.put("Ұ", "U");
        dictionary.put("в", "v");
        dictionary.put("В", "V");
        dictionary.put("ы", "y");
        dictionary.put("Ы", "Y");
        dictionary.put("у", "ý");
        dictionary.put("У", "Ý");
        dictionary.put("з", "z");
        dictionary.put("З", "Z");
        dictionary.put("э", "e");
        dictionary.put("Э", "E");
        dictionary.put("ю", "ıý");
        dictionary.put("Ю", "Iý");
        dictionary.put("я", "ıa");
        dictionary.put("Я", "Ia");
        dictionary.put("ц", "ts");
        dictionary.put("Ц", "Ts");
        dictionary.put("ь", "");
        dictionary.put("Ь", "");
        dictionary.put("ъ", "");
        dictionary.put("Ъ", "");
        dictionary.put("ё", "ıo");
        dictionary.put("Ё", "Io");
        dictionary.put("щ", "sh");
        dictionary.put("Щ", "Sh");
    
        
        
    }
    
 
   
 
    public Map<String, String> getDictionary() {
        return dictionary;
        
    }
}
Nastya2018 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Кириллические URLы не редиректятся с www Артем55 PHP 8 29.01.2018 23:32
Кириллические символы в идентификаторах avd Общие вопросы Delphi 10 16.10.2013 19:31
Проблема с электронной книгой Archos. Не получается внедрить кириллические шрифты в EPUB anutkyns Помощь студентам 0 09.07.2011 18:52
проверка на символы PHP bpystep Помощь студентам 11 06.08.2010 08:22
проверка на символы... Nlegion Общие вопросы C/C++ 8 19.07.2010 16:28