Skip to content

Commit

Permalink
Format from/to custom number base (#430)
Browse files Browse the repository at this point in the history
* Number conversion using custom bases functionalities and few tests

* Functionalities to format numbers using any base and dictionary

* Add new language text

* Change models to fit new features

* Add new communication messages between number converter view models

* Add views and functionalities to allow custom dictionaries

* Activate model to receive messages

* Include language generated component

* Rebase and cleanup code

* Update InfoBar message to show/hide it correctly

* Remove remaining code generating compile errors

* Code refactoring

* Fix test cases

* Added the possibility to Favorite/Unfavorite a tool. (#437)

* Added the possibility to Favorite/Unfavorite a tool.

* Updated localization

* addressed feedback

* Fix README.md minor typo (#441)

* Update japanese translation. (#444)

* Bumped up version number

* Feature/add refresh button lorem ipsum (#413)

* Add StartWithLoremIpsum option

* Updated language bundles

* Added refresh buttom for lorem ipsum

* Replaced click handler with Refresh ICommand

* Fixing error

Co-authored-by: Guus Beltman <[email protected]>

* Added some assets

* Updated chocolatey

* updated wikiUrl in Chocolatey

* Update Traditional Chinese translation (#442)

* Updates to cs-CZ localization (#447)

* feature: 💬 add new lang (Portuguese-Brazil) (#449)

* Update japanese translation. (lorem ipsum) (#450)

* Update japanese translation. (lorem ipsum)

* Fix typo.

* Update chinese translation (#451)

* Added String Escape / Unescape tool (#446)

* Set nullable

* Set nullable and change to string dictionaries

* Fix errors, inject view models and improve code

* Add translations

* Number conversion using custom bases functionalities and few tests

* Functionalities to format numbers using any base and dictionary

* Add new language text

* Change models to fit new features

* Add new communication messages between number converter view models

* Add views and functionalities to allow custom dictionaries

* Activate model to receive messages

* Include language generated component

* Rebase and cleanup code

* Update InfoBar message to show/hide it correctly

* Remove remaining code generating compile errors

* Code refactoring

* Fix test cases

* Set nullable

* Set nullable and change to string dictionaries

* Fix errors, inject view models and improve code

* Add translations

* Automatic input when navigating to the tool

Co-authored-by: Etienne BAUDOUX <[email protected]>
Co-authored-by: kspc1000 <[email protected]>
Co-authored-by: Sou Niyari <[email protected]>
Co-authored-by: Guus Beltman <[email protected]>
Co-authored-by: Guus Beltman <[email protected]>
Co-authored-by: SiderealArt <[email protected]>
Co-authored-by: Morning4coffe <[email protected]>
Co-authored-by: Rafael Andrade de Oliveira <[email protected]>
Co-authored-by: Boring3 <[email protected]>
  • Loading branch information
10 people authored Mar 26, 2022
1 parent 3e8b744 commit 646ceca
Show file tree
Hide file tree
Showing 38 changed files with 1,617 additions and 317 deletions.
23 changes: 23 additions & 0 deletions src/dev/impl/DevToys/DevToys.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
<Compile Include="Helpers\SqlFormatter\SqlFormatterHelper.cs" />
<Compile Include="Helpers\SqlFormatter\SqlFormatterOptions.cs" />
<Compile Include="Helpers\SqlFormatter\SqlLanguage.cs" />
<Compile Include="Messages\ChangeInfoBarStatusMessage.cs" />
<Compile Include="Messages\ChangeNumberFormattingMessage.cs" />
<Compile Include="Messages\RemoveFromFavoritesMessage.cs" />
<Compile Include="Messages\AddToFavoritesMessage.cs" />
<Compile Include="Messages\PinToolToStartMessage.cs" />
Expand All @@ -67,6 +69,7 @@
<Compile Include="Models\HashingAlgorithm.cs" />
<Compile Include="Models\HashingAlgorithmDisplayPair.cs" />
<Compile Include="Models\HashingProgress.cs" />
<Compile Include="Models\NumberBaseDictionary.cs" />
<Compile Include="Models\SqlLanguageDisplayPair.cs" />
<Compile Include="Models\NoResultFoundMockToolProvider.cs" />
<Compile Include="Models\Radix.cs" />
Expand All @@ -84,6 +87,12 @@
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolProvider.cs" />
<Compile Include="ViewModels\Tools\AllTools\AllToolsToolViewModel.cs" />
<Compile Include="ViewModels\Tools\Converters\ConvertersGroupToolProvider.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControlViewModel.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\BasicNumberBaseConverterControlViewModel.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\Exceptions\InvalidBaseNumberException.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\Exceptions\InvalidDictionaryBaseNumberPairException.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\Exceptions\InvalidDictionarySizeException.cs" />
<Compile Include="ViewModels\Tools\Converters\NumberBaseConverter\NumberBaseFormatBuilder.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolProvider.cs" />
<Compile Include="ViewModels\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolViewModel.cs" />
<Compile Include="Helpers\JsonYaml\Core\DecimalJsonConverter.cs" />
Expand Down Expand Up @@ -120,6 +129,12 @@
<Compile Include="Views\Tools\AllTools\AllToolsToolPage.xaml.cs">
<DependentUpon>AllToolsToolPage.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControl.xaml.cs">
<DependentUpon>AdvancedNumberBaseConverterControl.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\Converters\NumberBaseConverter\BasicNumberBaseConverterControl.xaml.cs">
<DependentUpon>BasicNumberBaseConverterControl.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolPage.xaml.cs">
<DependentUpon>GZipEncoderDecoderToolPage.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -578,6 +593,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\Converters\NumberBaseConverter\AdvancedNumberBaseConverterControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\Converters\NumberBaseConverter\BasicNumberBaseConverterControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Tools\EncodersDecoders\GZipEncoderDecoder\GZipEncoderDecoderToolPage.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand Down
35 changes: 35 additions & 0 deletions src/dev/impl/DevToys/LanguageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,6 +1732,41 @@ public string GetFormattedValueOverflow(string? param0)
/// Gets the resource SearchKeywords.
/// </summary>
public string SearchKeywords => _resources.GetString("SearchKeywords");

/// <summary>
/// Gets the resource AdvancedModeLabel.
/// </summary>
public string AdvancedModeLabel => _resources.GetString("AdvancedModeLabel");

/// <summary>
/// Gets the resource InputDictionaryLabel.
/// </summary>
public string InputDictionaryLabel => _resources.GetString("InputDictionaryLabel");

/// <summary>
/// Gets the resource OutputDictionaryLabel.
/// </summary>
public string OutputDictionaryLabel => _resources.GetString("OutputDictionaryLabel");

/// <summary>
/// Gets the resource Output.
/// </summary>
public string Output => _resources.GetString("Output");

/// <summary>
/// Gets the resource BaseNumberError.
/// </summary>
public string BaseNumberError => _resources.GetString("BaseNumberError");

/// <summary>
/// Gets the resource DictionarySizeError.
/// </summary>
public string DictionarySizeError => _resources.GetString("DictionarySizeError");

/// <summary>
/// Gets the resource IncompatibleBaseDictionaryError.
/// </summary>
public string IncompatibleBaseDictionaryError => _resources.GetString("IncompatibleBaseDictionaryError");
}

public class PngJpgCompressorStrings : ObservableObject
Expand Down
21 changes: 21 additions & 0 deletions src/dev/impl/DevToys/Messages/ChangeInfoBarStatusMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevToys.Messages
{
public sealed class ChangeInfoBarStatusMessage
{
public string Message { get; set; }
public bool IsOpen { get; set; }

public ChangeInfoBarStatusMessage(bool isOpen, string message)
{
Message = message;
IsOpen = isOpen;
}
}
}
19 changes: 19 additions & 0 deletions src/dev/impl/DevToys/Messages/ChangeNumberFormattingMessage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevToys.Messages
{
public sealed class ChangeNumberFormattingMessage
{
public bool IsFormatted { get; set; }

public ChangeNumberFormattingMessage(bool formatted)
{
IsFormatted = formatted;
}
}
}
69 changes: 69 additions & 0 deletions src/dev/impl/DevToys/Models/NumberBaseDictionary.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DevToys.Models
{
public class NumberBaseDictionary : IEquatable<NumberBaseDictionary>
{
public static readonly NumberBaseDictionary Base16Dictionary = new(
_dictionary: "0123456789ABCDEF",
formatting: true);

public static readonly NumberBaseDictionary RFC4648Base32Dictionary = new(
_dictionary: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",
formatting: false);

public static readonly NumberBaseDictionary RFC4648Base32ExHexDictionary = new(
_dictionary: "0123456789ABCDEFGHIJKLMNOPQRSTUV",
formatting: false);

public static readonly NumberBaseDictionary RFC4648Base64Dictionary = new(
_dictionary: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
formatting: false);

public static readonly NumberBaseDictionary RFC4648Base64UrlEncodeDictionary = new(
_dictionary: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",
formatting: false);
public static NumberBaseDictionary DefaultDictionary { get; } = RFC4648Base64Dictionary;

public string Dictionary { get; }
public bool AllowsFormatting { get; }

public NumberBaseDictionary(string _dictionary, bool formatting)
{
Dictionary = _dictionary;
AllowsFormatting = formatting;
}

public static implicit operator NumberBaseDictionary(string dict)
{
return new NumberBaseDictionary(dict, dict.All(c => char.IsLower(c)));
}

public char this[int index]
{
get
{
return Dictionary[index];
}
}

public override bool Equals(object obj)
{
if (obj is not NumberBaseDictionary other)
{
return false;
}
return Equals(other);
}

public bool Equals(NumberBaseDictionary other)
{
return AllowsFormatting == other.AllowsFormatting && Dictionary.SequenceEqual(other.Dictionary);
}
}
}
89 changes: 80 additions & 9 deletions src/dev/impl/DevToys/Models/NumberBaseFormat.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Globalization;

namespace DevToys.Models
Expand All @@ -12,51 +13,121 @@ public class NumberBaseFormat : IEquatable<NumberBaseFormat>
value: Radix.Binary,
baseNumber: 2,
groupSize: 4,
groupSeparator: ' ');
groupSeparator: ' ',
dictionary: NumberBaseDictionary.Base16Dictionary);

public static readonly NumberBaseFormat Octal = new(
displayName: Strings.OctalLabel,
value: Radix.Octal,
baseNumber: 8,
groupSize: CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes[0],
groupSeparator: ' ');
groupSeparator: ' ',
dictionary: NumberBaseDictionary.Base16Dictionary);

public static readonly NumberBaseFormat Decimal = new(
displayName: Strings.DecimalLabel,
value: Radix.Decimal,
baseNumber: 10,
groupSize: CultureInfo.CurrentCulture.NumberFormat.NumberGroupSizes[0],
groupSeparator: Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator));
groupSeparator: Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator),
dictionary: NumberBaseDictionary.Base16Dictionary);

public static readonly NumberBaseFormat Hexadecimal = new(
displayName: Strings.HexadecimalLabel,
value: Radix.Hexdecimal,
baseNumber: 16,
groupSize: 4,
groupSeparator: ' ');
groupSeparator: ' ',
dictionary: NumberBaseDictionary.Base16Dictionary);

public static readonly NumberBaseFormat RFC4648_Base16 = new(
displayName: "RFC-4648 Base16",
value: Radix.RFC4648Standard,
baseNumber: 16,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.Base16Dictionary);

public static readonly NumberBaseFormat RFC4648_Base32 = new(
displayName: "RFC-4648 Base32",
value: Radix.RFC4648Standard,
baseNumber: 32,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.RFC4648Base32Dictionary);

public static readonly NumberBaseFormat RFC4648_Base32_ExtendedHex = new(
displayName: "RFC-4648 Base32 Extended Hex",
value: Radix.RFC4648Standard,
baseNumber: 32,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.RFC4648Base32ExHexDictionary);

public static readonly NumberBaseFormat RFC4648_Base64 = new(
displayName: "RFC-4648 Base64",
value: Radix.RFC4648Standard,
baseNumber: 64,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.RFC4648Base64Dictionary);

public static readonly NumberBaseFormat RFC4648_Base64UrlEncode = new(
displayName: "RFC-4648 Base64 Url Encode",
value: Radix.RFC4648Standard,
baseNumber: 64,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.RFC4648Base64UrlEncodeDictionary);

public static readonly NumberBaseFormat DefaultCustom = new(
displayName: "Custom format",
value: Radix.Custom,
baseNumber: 16,
groupSize: 4,
groupSeparator: ' ',
dictionary: NumberBaseDictionary.Base16Dictionary);

public string DisplayName { get; }

public Radix Value { get; }

public int BaseNumber { get; }
public int BaseNumber { get; set; }

public int GroupSize { get; }

public char GroupSeparator { get; }

private NumberBaseFormat(string displayName, Radix value, int baseNumber, int groupSize, char groupSeparator)
public NumberBaseDictionary Dictionary { get; set; }

internal NumberBaseFormat(string displayName, Radix value, int baseNumber, int groupSize, char groupSeparator, NumberBaseDictionary? dictionary = null)
{
DisplayName = displayName;
Value = value;
BaseNumber = baseNumber;
GroupSize = groupSize;
GroupSeparator = groupSeparator;
Dictionary = dictionary ?? NumberBaseDictionary.DefaultDictionary;
}

internal NumberBaseFormat(NumberBaseFormat other, int baseNumber, NumberBaseDictionary dictionary)
{
DisplayName = other.DisplayName;
Value = other.Value;
BaseNumber = baseNumber;
GroupSeparator = other.GroupSeparator;
GroupSize = other.GroupSize;
Dictionary = dictionary;
}

public override string ToString()
{
return DisplayName;
}

public bool Equals(NumberBaseFormat other)
public virtual bool Equals(NumberBaseFormat other)
{
return other.Value == Value;
return other.Value == Value && other.BaseNumber == BaseNumber && Dictionary.Equals(other.Dictionary);
}
}
}
4 changes: 3 additions & 1 deletion src/dev/impl/DevToys/Models/Radix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public enum Radix
Octal,
Binary,
Decimal,
Hexdecimal
Hexdecimal,
RFC4648Standard,
Custom
}
}
21 changes: 21 additions & 0 deletions src/dev/impl/DevToys/Strings/cs-CZ/NumberBaseConverter.resw
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,25 @@
<data name="SearchKeywords" xml:space="preserve">
<value>Binary Octal Decimal Hexadecimal</value>
</data>
<data name="AdvancedModeLabel" xml:space="preserve">
<value>Advanced mode</value>
</data>
<data name="InputDictionaryLabel" xml:space="preserve">
<value>Input dictionary</value>
</data>
<data name="OutputDictionaryLabel" xml:space="preserve">
<value>Output dictionary</value>
</data>
<data name="Output" xml:space="preserve">
<value>Output</value>
</data>
<data name="BaseNumberError" xml:space="preserve">
<value>Base number should be greater than 1.</value>
</data>
<data name="DictionarySizeError" xml:space="preserve">
<value>Dictionary size should be greater than 1.</value>
</data>
<data name="IncompatibleBaseDictionaryError" xml:space="preserve">
<value>Dictionary size could not be smaller than the base number.</value>
</data>
</root>
Loading

0 comments on commit 646ceca

Please sign in to comment.