Created
September 20, 2016 13:12
-
-
Save mvacha/71b5e2aac939ac268e85731c0e2ec4f3 to your computer and use it in GitHub Desktop.
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
internal class Typografie | |
{ | |
public Typografie() | |
{ | |
} | |
public static void HledejMezery(string s, ref List<int> indexy) | |
{ | |
indexy.Clear(); | |
s = Typografie.SmazSpecialniJazyky(s); | |
for (Match i = (new Regex(">[^<]*<", RegexOptions.Singleline)).Match(s); i.Success; i = i.NextMatch()) | |
{ | |
string str = s.Substring(i.Index + 1, i.Length - 2); | |
string str1 = "(\\s| | )[szvkouiSZVKOUIA] |(\\s| | )[A-Z]\\. [A-Z]|(Ing.|Doc.|Dr.|Prof.|Bc.|BcA.|Mgr.|MgA.) [A-Z]|[0-9] (Kč|%|‰|kg|°|mm|cm|dm|m(\\.|,))|[0-9]{1,2}\\. [0-9]{1,2}\\. [0-9]{2,4}|(s\\. r\\. o\\.)|(a\\. s\\.)|[0-9]{3} [0-9]{3} [0-9]{3}"; | |
Regex regex = new Regex(str1); | |
Regex regex1 = new Regex(str1, RegexOptions.RightToLeft); | |
MatchCollection matchCollections = regex.Matches(str); | |
MatchCollection matchCollections1 = regex1.Matches(str); | |
Label0: | |
foreach (Match match in matchCollections) | |
{ | |
string str2 = str.Substring(match.Index, match.Length); | |
int num = 0; | |
while (true) | |
{ | |
int num1 = str2.IndexOf(" ", num); | |
int num2 = num1; | |
if (num1 == -1) | |
{ | |
goto Label0; | |
} | |
if (num2 != 0) | |
{ | |
int index = i.Index + 1 + match.Index + num2; | |
indexy.Add(index); | |
} | |
num = num2 + 1; | |
} | |
} | |
Label1: | |
foreach (Match match1 in matchCollections1) | |
{ | |
string str3 = str.Substring(match1.Index, match1.Length); | |
int num3 = 0; | |
while (true) | |
{ | |
int num4 = str3.IndexOf(" ", num3); | |
int num5 = num4; | |
if (num4 == -1) | |
{ | |
goto Label1; | |
} | |
if (num5 != 0) | |
{ | |
int index1 = i.Index + 1 + match1.Index + num5; | |
if (!indexy.Contains(index1)) | |
{ | |
indexy.Add(index1); | |
} | |
} | |
num3 = num5 + 1; | |
} | |
} | |
} | |
indexy.Sort(); | |
} | |
private static string SmazSpecialniJazyky(string s) | |
{ | |
int num = 0; | |
string[] strArrays = new string[] { "<script", "<style" }; | |
string[] strArrays1 = new string[] { "</script>", "</style>" }; | |
for (int i = 0; i < (int)strArrays.Length; i++) | |
{ | |
while (true) | |
{ | |
int num1 = s.ToLower().IndexOf(strArrays[i], num); | |
int num2 = s.ToLower().IndexOf(strArrays1[i], num); | |
if (num1 == -1 || num2 == -1 || num2 <= num1) | |
{ | |
break; | |
} | |
int length = num2 - num1 + strArrays1[i].Length; | |
s = s.Remove(num1, length); | |
s = s.Insert(num1, new string('*', length)); | |
} | |
} | |
return s; | |
} | |
public static string VlozNbsp(string s, string nbsp) | |
{ | |
List<int> nums = new List<int>(); | |
return Typografie.VlozNbsp(s, ref nums, nbsp); | |
} | |
public static string VlozNbsp(string s, ref List<int> indexy, string nbsp) | |
{ | |
indexy.Clear(); | |
Typografie.HledejMezery(s, ref indexy); | |
for (int i = 0; i < indexy.Count; i++) | |
{ | |
s = s.Remove(indexy[i], 1); | |
s = s.Insert(indexy[i], nbsp); | |
if (i < indexy.Count - 1) | |
{ | |
for (int j = i + 1; j < indexy.Count; j++) | |
{ | |
List<int> item = indexy; | |
List<int> nums = item; | |
int num = j; | |
int num1 = num; | |
item[num] = nums[num1] + (nbsp.Length - 1); | |
} | |
} | |
} | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment