-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Зиновьева Милана #224
base: master
Are you sure you want to change the base?
Зиновьева Милана #224
Changes from 10 commits
f70afab
f3b8fc8
2f9afb4
01e48b5
b43171f
294f785
cb9a405
9142d1f
bb22cb9
3a0d8b9
2201109
883722f
c887712
02c538a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<LangVersion>8</LangVersion> | ||
<LangVersion>6</LangVersion> | ||
<TargetFramework>net6</TargetFramework> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" /> | ||
<PackageReference Include="NUnit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,65 @@ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NUnit.Framework.Internal.Execution; | ||
using System.Linq; | ||
|
||
namespace ControlDigit | ||
{ | ||
public static class SnilsExtensions | ||
{ | ||
public static int CalculateSnils(this long number) | ||
{ | ||
throw new NotImplementedException(); | ||
public static int CalculateSnils(this long number){ | ||
var dict = NumberDecompotion(number); | ||
var M = SummDecompotion(dict); | ||
var result = MakeControlDigit(M); | ||
return result; | ||
} | ||
|
||
private static Dictionary<int, int> NumberDecompotion(this long number){ | ||
var counter = 1; | ||
var dict = new Dictionary<int, int>(); | ||
while(number / 10 >= 1){ | ||
dict.Add(counter, (int)number % 10); | ||
counter++; | ||
number = number / 10; | ||
} | ||
dict.Add(counter, (int)number % 10); | ||
return dict; | ||
} | ||
|
||
private static int SummDecompotion(Dictionary<int, int> dict){ | ||
var summ = 0; | ||
foreach(var pair in dict){ | ||
summ += pair.Key * pair.Value; | ||
} | ||
return summ; | ||
} | ||
|
||
private static IEnumerable<int> MakeFactorsSnils(int length){ | ||
return Enumerable.Range(1, length); | ||
} | ||
|
||
private static IEnumerable<int> MakeFactorsUpc(int length){ | ||
return Enumerable.Range(1, length); | ||
} | ||
|
||
private static int CountControlDigit(IEnumerable<int> values, Func<int, IEnumerable<int>> evaluateFactors, int length){ | ||
var factors = evaluateFactors(length); | ||
var summ = 0; | ||
//for(int i = 0;i < length;i++){ | ||
//summ += factors[i] * values[i]; | ||
//} | ||
var ggygu = factors.Zip(values) | ||
} | ||
|
||
private static int MakeControlDigit(int summ){ | ||
if (summ > 101) | ||
summ = summ % 101; | ||
if (summ < 100) | ||
return summ; | ||
else | ||
return 0; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
namespace Markdown; | ||
|
||
public class HelperFunctions | ||
{ | ||
private static readonly char[] forbiddenChars = ['_', '#']; | ||
|
||
private static readonly char[] tagChars = ['_', '#', '\\']; | ||
|
||
public static int FindCorrectCloseSymbolForItalic(string text, int startIndex) | ||
{ | ||
for (int i = startIndex + 1; i < text.Length; i++) | ||
{ | ||
if (text[i] == '_' && !IsPartOfDoubleUnderscore(text, i) && IsValidCloseSymbol(text, i)) | ||
return i; | ||
} | ||
return -1; | ||
} | ||
|
||
private static bool IsValidCloseSymbol(string text, int index) | ||
{ | ||
if (index + 1 < text.Length && char.IsDigit(text[index + 1])) | ||
return false; | ||
if (index - 1 >= 0 && char.IsDigit(text[index - 1])) | ||
{ | ||
if (index + 1 == text.Length || text.Substring(index + 1).All(char.IsWhiteSpace)) | ||
return true; | ||
|
||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static string ProcessNestedTag(ref string text) | ||
{ | ||
Md md = new Md(['_', '\\']); | ||
return md.Render(text); | ||
} | ||
|
||
public static bool ContainsOnlyDash(string text) => | ||
text.All(symbol => forbiddenChars.Contains(symbol)); | ||
|
||
public static bool ContainsOnlyHeading(string text) => | ||
text.All(symbol => symbol == '#'); | ||
|
||
public static bool ContainsOnlySpases(string text) => | ||
string.IsNullOrWhiteSpace(text) || string.IsNullOrEmpty(text); | ||
|
||
private static bool IsPartOfDoubleUnderscore(string text, int index) => | ||
(index + 1 < text.Length && text[index + 1] == '_') || | ||
(index > 0 && text[index - 1] == '_'); | ||
|
||
public static bool ContainsUnderscore(string text) => text.Contains('_'); | ||
|
||
public static (List<int>, List<int>) GetUnderscoreIndexes(string text) | ||
{ | ||
List<int> singleUnderscoreIndexes = new List<int>(); | ||
List<int> doubleUnderscoreIndexes = new List<int>(); | ||
for (int i = 0; i < text.Length; i++) | ||
{ | ||
if (text[i] == '_' && ((i + 1 < text.Length && text[i + 1] != '_') || i == text.Length - 1)) | ||
{ | ||
singleUnderscoreIndexes.Add(i); | ||
} | ||
if (i + 1 < text.Length && text[i] == '_' && text[i + 1] == '_') | ||
{ | ||
doubleUnderscoreIndexes.Add(i); | ||
i++; | ||
} | ||
} | ||
return (singleUnderscoreIndexes, doubleUnderscoreIndexes); | ||
} | ||
|
||
public static bool HasUnpairedTags(List<int> indexes1, List<int> indexes2) | ||
{ | ||
if (indexes1.Count < 2 || indexes2.Count < 2 || indexes1.Count % 2 == 1 || indexes2.Count % 2 == 1) | ||
{ | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public static bool AreSegmentsIntersecting(int[] segment1, int[] segment2) | ||
{ | ||
return segment1[1] >= segment2[0] && segment1[0] <= segment2[1]; | ||
} | ||
|
||
public static bool AreSegmentsNested(int[] segment1, int[] segment2) | ||
{ | ||
return (segment1[0] >= segment2[0] && segment1[1] <= segment2[1]) || | ||
(segment2[0] >= segment1[0] && segment2[1] <= segment1[1]); | ||
} | ||
|
||
public static string RemoveExtraSpaces(string input) | ||
{ | ||
return string.Join(" ", input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>false</IsTestProject> | ||
</PropertyGroup> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown; | ||
|
||
public class Md | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Булы тут немного не к месту, хочется от них избавиться. Как вариант, можно добавить дефолтный хендлер для символов, которые не являются тегами, перестать опираться на tagChars и использовать handler.IsTagStart. Чтобы всё заработало, хендлеры должны быть расположены в списке в корректном порядке. Тогда получится, что для каждого символа, мы берем первый подходящий хендлер. Так же придется вынести хендлеры в конструктор, для гибкой конфигурации. |
||
{ | ||
private static readonly List<ITagHandler> TagHandlers = | ||
[ | ||
new BoldTag(), | ||
new ItalicTag(), | ||
new HeadingTag(), | ||
new EscapeTag() | ||
]; | ||
private readonly char[] tagChars; | ||
|
||
public Md(char[]? customTagChars = null) | ||
{ | ||
tagChars = customTagChars ?? ['_', '#', '\\']; | ||
} | ||
|
||
private bool CanBeTag(char symbol) => tagChars.Contains(symbol); | ||
|
||
public string Render(string markdownString) | ||
{ | ||
int index = 0; | ||
while (index < markdownString.Length) | ||
{ | ||
if (CanBeTag(markdownString[index])) | ||
{ | ||
if (TryProcessTag(ref markdownString, ref index)) | ||
continue; | ||
} | ||
index++; | ||
} | ||
|
||
return markdownString; | ||
} | ||
|
||
private static bool TryProcessTag(ref string markdownString, ref int index) | ||
{ | ||
foreach (var handler in TagHandlers) | ||
{ | ||
if (handler.IsTagStart(markdownString, index)) | ||
{ | ||
index = handler.ProcessTag(ref markdownString, index); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.