Changeset 8598


Ignore:
Timestamp:
Feb 4, 2020, 7:36:52 PM (2 years ago)
Author:
Sven Rech
Message:

KeySearcher: Improved displaying of raw text strings (avoid showing non-displayable characters, because it will mess up internal state of WPF components)

Location:
trunk/CrypPlugins/KeySearcher
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypPlugins/KeySearcher/Converter/ByteArrayToUtf8StringConverter.cs

    r8109 r8598  
    11using System;
     2using System.Linq;
    23using System.Text;
    34using System.Text.RegularExpressions;
     
    1314        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    1415        {
    15             var bytes = (byte[])value;
    16             return Regex.Replace(Encoding.UTF8.GetString(bytes), @"\r\n?|\n", "");
     16            string input;
     17            if (value is byte[])
     18            {
     19                input = Encoding.UTF8.GetString((byte[])value);
     20            }
     21            else if (value is string)
     22            {
     23                input = (string)value;
     24            }
     25            else
     26            {
     27                throw new ArgumentException();
     28            }
     29
     30            input = new string(input.Where(c => !char.IsControl(c)).ToArray());
     31            return Regex.Replace(input, @"\r\n?|\n", "");
    1732        }
    1833         
  • trunk/CrypPlugins/KeySearcher/Presentation/Controls/LocalQuickWatchPresentation.xaml

    r8394 r8598  
    33    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    44    xmlns:properties="clr-namespace:KeySearcher.Properties"
     5    xmlns:con="clr-namespace:KeySearcher.Converter"
    56    xmlns:crypanalysisviewcontrol="clr-namespace:Cryptool.CrypAnalysisViewControl;assembly=CrypAnalysisViewControl"
    67    x:Name="LocalQuickWatch">
    7    
     8
     9    <UserControl.Resources>
     10        <con:ByteArrayToUtf8StringConverter x:Key="ByteArrayToUtf8StringConverter" />
     11    </UserControl.Resources>
     12
    813    <crypanalysisviewcontrol:CrypAnalysisViewControl ResultHeaderCaption="{x:Static properties:Resources.Local_}" ResultListCaption="{x:Static properties:Resources.Top_Ten_}">
    914        <crypanalysisviewcontrol:CrypAnalysisViewControl.ResultHeaderLabels>
     
    5358                        </GridViewColumn.CellTemplate>
    5459                    </GridViewColumn>
    55                     <GridViewColumn Header="{x:Static properties:Resources.Text}" DisplayMemberBinding="{Binding Path=Text}">
     60                    <GridViewColumn Header="{x:Static properties:Resources.Text}" DisplayMemberBinding="{Binding Path=Text, Converter={StaticResource ByteArrayToUtf8StringConverter}}">
    5661                        <GridViewColumn.CellTemplate>
    5762                            <DataTemplate>
Note: See TracChangeset for help on using the changeset viewer.