Skip to content

Commit

Permalink
MAINTENANCE: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jslachta committed Oct 17, 2022
1 parent 46107bb commit 7a40ab6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion src/LocaleNames.Test/FindCountryCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public void LocaleNames_All_Country_Codes_Should_Not_Provide_Variants_And_Contin
{
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

var countryCodes = localeNames.AllCountryCodes;
var countryCodes = localeNames.GetAllCountryCodes();

Assert.IsTrue(countryCodes.Any(), "Testing on empty collection does not make sense.");

Expand Down
2 changes: 1 addition & 1 deletion src/LocaleNames.Test/FindLanguageCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void LocaleNames_All_Language_Codes_Should_Not_Provide_Variants()
{
var localeNames = LocaleNamesFactory.ForLanguageCode("en-US");

var languageCodes = localeNames.AllLanguageCodes;
var languageCodes = localeNames.GetAllLanguageCodes();

Assert.IsTrue(languageCodes.Any(), "Testing on empty collection does not make sense.");

Expand Down
12 changes: 6 additions & 6 deletions src/LocaleNames/LocaleNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public class LocaleNames
/// <summary>
/// Gets a value indicating whether are language translations empty.
/// </summary>
public bool AreLanguageTranslationsEmpty => !(LanguageNames.Value.Keys.Count > 0);
public bool AreLanguageTranslationsEmpty => LanguageNames.Value.Keys.Count <= 0;

/// <summary>
/// Gets a value indicating whether are countryname translations empty.
/// </summary>
public bool AreCountryNameTranslationsEmpty => !(CountryNames.Value.Keys.Count > 0);
public bool AreCountryNameTranslationsEmpty => CountryNames.Value.Keys.Count <= 0;

/// <summary>
/// Gets a value indicating whether this instance is from cache.
Expand All @@ -51,15 +51,15 @@ public class LocaleNames
/// <value>
/// The language names.
/// </value>
private Lazy<ReadOnlyDictionary<string, string>> LanguageNames;
private readonly Lazy<ReadOnlyDictionary<string, string>> LanguageNames;

/// <summary>
/// Gets the language names.
/// </summary>
/// <value>
/// The language names.
/// </value>
private Lazy<ReadOnlyDictionary<string, string>> CountryNames;
private readonly Lazy<ReadOnlyDictionary<string, string>> CountryNames;

#endregion PROPERTIES

Expand Down Expand Up @@ -160,7 +160,7 @@ private bool LoadDictionary(string key, string postfix, ref IDictionary<string,
/// <summary>
/// Provides all language codes.
/// </summary>
public IReadOnlyCollection<string> AllLanguageCodes
public IReadOnlyCollection<string> GetAllLanguageCodes()
=> new ReadOnlyCollection<string>(LanguageNames.Value.Select(i => i.Key.StripLocaleVariants()).Distinct().ToList());

/// <summary>
Expand Down Expand Up @@ -235,7 +235,7 @@ public string FindLanguageCode(string countryName)
/// <summary>
/// Provides all country codes.
/// </summary>
public IReadOnlyCollection<string> AllCountryCodes
public IReadOnlyCollection<string> GetAllCountryCodes()
=> new ReadOnlyCollection<string>(
CountryNames
.Value
Expand Down
64 changes: 32 additions & 32 deletions src/LocaleNames/Utils/GzipUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,50 @@ namespace LocaleNames.Utils
public static class GzipUtils
{
/// <summary>
/// Decompresses the specified input.
/// Compresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
public static string Decompress(string input)
public static string Compress(string input)
{
byte[] compressed = Convert.FromBase64String(input);
byte[] decompressed = Decompress(compressed);
return Encoding.UTF8.GetString(decompressed);
byte[] encoded = Encoding.UTF8.GetBytes(input);
byte[] compressed = Compress(encoded);
return Convert.ToBase64String(compressed);
}

/// <summary>
/// Compresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
public static string Compress(string input)
public static byte[] Compress(byte[] input)
{
byte[] encoded = Encoding.UTF8.GetBytes(input);
byte[] compressed = Compress(encoded);
return Convert.ToBase64String(compressed);
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);

using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}

return result.ToArray();
}
}

/// <summary>
/// Decompresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
public static string Decompress(string input)
{
byte[] compressed = Convert.FromBase64String(input);
byte[] decompressed = Decompress(compressed);
return Encoding.UTF8.GetString(decompressed);
}

/// <summary>
Expand All @@ -58,28 +81,5 @@ public static byte[] Decompress(byte[] input)
}
}
}

/// <summary>
/// Compresses the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <returns></returns>
public static byte[] Compress(byte[] input)
{
using (var result = new MemoryStream())
{
var lengthBytes = BitConverter.GetBytes(input.Length);
result.Write(lengthBytes, 0, 4);

using (var compressionStream = new GZipStream(result,
CompressionMode.Compress))
{
compressionStream.Write(input, 0, input.Length);
compressionStream.Flush();
}

return result.ToArray();
}
}
}
}

0 comments on commit 7a40ab6

Please sign in to comment.