-
Notifications
You must be signed in to change notification settings - Fork 299
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
Open
crycrash
wants to merge
14
commits into
kontur-courses:master
Choose a base branch
from
crycrash:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Зиновьева Милана #224
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
f70afab
Added structure of project
crycrash f3b8fc8
Added tag processing
crycrash 2f9afb4
Improved algorithm, eliminated code duplication
crycrash 01e48b5
The header logic has been corrected
crycrash b43171f
Fixed screening
crycrash 294f785
extended tests have been added, the logic of working with spaces and …
crycrash cb9a405
Fixed strings with numbers
crycrash 9142d1f
Fixed header in header
crycrash bb22cb9
Added extra tests for headings
crycrash 3a0d8b9
Fixed formatting
crycrash 2201109
Small fixes
crycrash 883722f
Added links
crycrash c887712
Processing link names with nested tags
crycrash 02c538a
Specification added
crycrash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
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> |
This file contains 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
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; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using Markdown.Tags; | ||
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) | ||
{ | ||
List<ITagHandler> tagHandlers = new List<ITagHandler> | ||
{ | ||
new BoldTag(), | ||
new ItalicTag(), | ||
new EscapeTag(), | ||
new DefaultTagHandler() | ||
}; | ||
Md md = new Md(tagHandlers); | ||
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 bool ContainsSquareBrackets(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(Tuple<int, int> segment1, Tuple<int, int> segment2) | ||
{ | ||
return segment1.Item2 >= segment2.Item1 && segment1.Item1 <= segment2.Item2; | ||
} | ||
|
||
public static bool AreSegmentsNested(Tuple<int, int> segment1, Tuple<int, int> segment2) | ||
{ | ||
return (segment1.Item1 >= segment2.Item1 && segment1.Item2 <= segment2.Item2) || | ||
(segment2.Item1 >= segment1.Item1 && segment2.Item2 <= segment1.Item2); | ||
} | ||
|
||
public static string RemoveExtraSpaces(string input) | ||
{ | ||
return string.Join(" ", input.Split(' ', StringSplitOptions.RemoveEmptyEntries)); | ||
} | ||
} |
This file contains 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
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> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Markdown.Tags; | ||
|
||
namespace Markdown; | ||
|
||
public class Md | ||
{ | ||
private readonly List<ITagHandler> tagHandlers; | ||
|
||
public Md(List<ITagHandler>? customTagHandlers = null) | ||
{ | ||
tagHandlers = customTagHandlers ?? new List<ITagHandler> | ||
{ | ||
new BoldTag(), | ||
new ItalicTag(), | ||
new HeadingTag(), | ||
new EscapeTag(), | ||
new LinkTag(), | ||
new DefaultTagHandler() | ||
}; | ||
} | ||
|
||
public string Render(string markdownString) | ||
{ | ||
var index = 0; | ||
while (index < markdownString.Length) | ||
TryProcessTag(ref markdownString, ref index); | ||
|
||
return markdownString; | ||
} | ||
|
||
private void TryProcessTag(ref string markdownString, ref int index) | ||
{ | ||
foreach (var handler in tagHandlers) | ||
{ | ||
if (handler.IsTagStart(markdownString, index)){ | ||
index = handler.ProcessTag(ref markdownString, index); | ||
break; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Булы тут немного не к месту, хочется от них избавиться. Как вариант, можно добавить дефолтный хендлер для символов, которые не являются тегами, перестать опираться на tagChars и использовать handler.IsTagStart. Чтобы всё заработало, хендлеры должны быть расположены в списке в корректном порядке. Тогда получится, что для каждого символа, мы берем первый подходящий хендлер. Так же придется вынести хендлеры в конструктор, для гибкой конфигурации.