@@ -74,40 +74,54 @@ object Russian extends Language {
7474 ): (Int , String ) = {
7575 val text = latin + append
7676 val ofs = text.length
77-
78- if (ofs >= 4 &&
79- fourGrams.contains(text.substring(ofs - 4 , ofs).toLowerCase)) {
80- val chars = text.substring(ofs - 4 , ofs)
81- val cyrillic = fourGrams(chars.toLowerCase)
82- (- 2 , restoreCaseFirst(chars, cyrillic).toString)
83- } else if (ofs >= 3
84- && yLetters.contains(text.substring(ofs - 3 , ofs - 1 ).toLowerCase)
85- && ! iotatedLetters.contains(text.substring(ofs - 2 , ofs).toLowerCase)
86- ) {
87- val cyrillic = uniGrams.getOrElse(text(ofs - 1 ).toLower, text(ofs - 1 ))
88- (0 , (if (text(ofs - 1 ).isUpper) cyrillic.toUpper else cyrillic).toString)
89- } else if (ofs >= 3 &&
90- triGrams.contains(text.substring(ofs - 3 , ofs).toLowerCase)) {
91- val chars = text.substring(ofs - 3 , ofs)
92- val cyrillic = triGrams(chars.toLowerCase)
93- (- 2 , restoreCaseFirst(chars, cyrillic).toString)
94- } else if (ofs >= 2 &&
95- biGrams.contains(text.substring(ofs - 2 , ofs).toLowerCase)) {
96- val chars = text.substring(ofs - 2 , ofs)
97- val cyrillic = biGrams(chars.toLowerCase)
98- (- 1 , restoreCaseFirst(chars, cyrillic).toString)
99- } else if (uniGrams.contains(text(ofs - 1 ).toLower)) {
100- val cyrillic = uniGrams(text(ofs - 1 ).toLower)
101- (0 , (if (text(ofs - 1 ).isUpper) cyrillic.toUpper else cyrillic).toString)
102- } else if (ofs >= 2 && uniGramsSpecial.contains(text(ofs - 1 ))) {
103- val result =
104- if (ofs >= 3 && text(ofs - 2 ).isUpper && text(ofs - 3 ).isUpper)
105- uniGramsSpecial(text(ofs - 1 )).toUpper
106- else uniGramsSpecial(text(ofs - 1 ))
107- (0 , result.toString)
108- } else {
109- (0 , text(ofs - 1 ).toString)
110- }
77+ val result =
78+ if (ofs >= 4 &&
79+ fourGrams.contains(text.substring(ofs - 4 , ofs).toLowerCase)) {
80+ val chars = text.substring(ofs - 4 , ofs)
81+ val cyrillic = fourGrams(chars.toLowerCase)
82+ (- 2 , restoreCaseFirst(chars, cyrillic).toString)
83+ } else if (ofs >= 3
84+ && yLetters.contains(text.substring(ofs - 3 , ofs - 1 ).toLowerCase)
85+ && ! iotatedLetters.contains(text.substring(ofs - 2 , ofs).toLowerCase)
86+ ) {
87+ val cyrillic = uniGrams.getOrElse(text(ofs - 1 ).toLower, text(ofs - 1 ))
88+ (0 , (if (text(ofs - 1 ).isUpper) cyrillic.toUpper else cyrillic).toString)
89+ } else if (ofs >= 3 &&
90+ triGrams.contains(text.substring(ofs - 3 , ofs).toLowerCase)) {
91+ val chars = text.substring(ofs - 3 , ofs)
92+ val cyrillic = triGrams(chars.toLowerCase)
93+ (- 2 , restoreCaseFirst(chars, cyrillic).toString)
94+ } else if (ofs >= 2 &&
95+ biGrams.contains(text.substring(ofs - 2 , ofs).toLowerCase)) {
96+ val chars = text.substring(ofs - 2 , ofs)
97+ val cyrillic = biGrams(chars.toLowerCase)
98+ (- 1 , restoreCaseFirst(chars, cyrillic).toString)
99+ } else if (uniGrams.contains(text(ofs - 1 ).toLower)) {
100+ val cyrillic = uniGrams(text(ofs - 1 ).toLower)
101+ (0 , (if (text(ofs - 1 ).isUpper) cyrillic.toUpper else cyrillic).toString)
102+ } else if (ofs >= 2 && uniGramsSpecial.contains(text(ofs - 1 ))) {
103+ val result =
104+ if (ofs >= 3 && text(ofs - 2 ).isUpper && text(ofs - 3 ).isUpper)
105+ uniGramsSpecial(text(ofs - 1 )).toUpper
106+ else uniGramsSpecial(text(ofs - 1 ))
107+ (0 , result.toString)
108+ } else {
109+ (0 , text(ofs - 1 ).toString)
110+ }
111+
112+ if (ofs >= 3 && uniGramsSpecial.contains(text(ofs - 2 ))) {
113+ val (l, r) = (text(ofs - 3 ), text(ofs - 1 ))
114+ val letter = uniGramsSpecial(text(ofs - 2 ))
115+ val replace = if (l.isUpper && r.isUpper) letter.toUpper else letter
116+ val cyrillicOfs = cyrillic.length - 1
117+
118+ if (replace == cyrillic(cyrillicOfs)) result
119+ else {
120+ val updated = replace + cyrillic.substring(
121+ cyrillicOfs + 1 , cyrillic.length + result._1)
122+ (- updated.length + result._1, updated + result._2)
123+ }
124+ } else result
111125 }
112126
113127 private def toLatin (letter : Char ): String = {
0 commit comments