Skip to content

Commit

Permalink
Merge pull request #16 from hmlendea/code-quality
Browse files Browse the repository at this point in the history
Improved the code quality
  • Loading branch information
hmlendea authored Apr 12, 2022
2 parents e167971 + da71198 commit 1bdf5d0
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 13 deletions.
1 change: 1 addition & 0 deletions Controllers/TransliterationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public ActionResult Get(
{
string decodedText = HttpUtility.UrlDecode(text);
string transliteratedText = transliterationService.Transliterate(text, language).Result; // TODO: Broken async

return Ok(transliteratedText);
}
catch (ArgumentException ex)
Expand Down
3 changes: 0 additions & 3 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

Expand Down
4 changes: 1 addition & 3 deletions Service/HttpRequestManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public async Task<string> Post(

public async Task<string> RetrieveCookies(string url)
{
Uri uri = new Uri(url);

HttpRequestMessage request = new HttpRequestMessage()
{
RequestUri = new Uri(url),
Expand All @@ -94,7 +92,7 @@ public async Task<string> RetrieveCookies(string url)

string cook = string.Empty;

foreach (var cookie in cookies.GetCookies(uri))
foreach (var cookie in cookies.GetCookies(request.RequestUri))
{
cook += cookie.ToString() + ";";
}
Expand Down
3 changes: 1 addition & 2 deletions Service/TransliterationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public TransliterationService(
public async Task<string> Transliterate(string text, string language)
{
string normalisedText = NormaliseText(text);

string cacheKey = GetCacheId(normalisedText, language);

if (cache.ContainsKey(cacheKey))
Expand Down Expand Up @@ -191,7 +190,7 @@ string GetCacheId(string text, string language)
string GetSha256FromString(string strData)
{
byte[] message = Encoding.ASCII.GetBytes(strData);
SHA256Managed hashString = new SHA256Managed();
SHA256 hashString = SHA256.Create();
string hex = "";

byte[] hashValue = hashString.ComputeHash(message);
Expand Down
1 change: 1 addition & 0 deletions Service/Transliterators/MarathiTransliterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public string Transliterate(string text)
transliteratedText = transliteratedText.Replace("", "g");
transliteratedText = transliteratedText.Replace("", "om");
transliteratedText = transliteratedText.Replace("", "'");

transliteratedText = Regex.Replace(transliteratedText, "e.a", "a");

return transliteratedText.ToTitleCase();
Expand Down
8 changes: 3 additions & 5 deletions Service/Transliterators/PodolakTransliterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,12 @@ private string GetUrl(string language)
{
const string url = "https://podolak.net/en/transliteration";

if (language == "cu")
{
return $"{url}/old-church-slavonic";
}
else
if (!language.Equals("cu"))
{
throw new ArgumentException($"Unsupported language \"{language}\"");
}

return $"{url}/old-church-slavonic";
}

private string ExtractResultFromResponse(string response)
Expand Down

0 comments on commit 1bdf5d0

Please sign in to comment.