Exemplo n.º 1
0
        private void CharInfo_Click(object sender, RoutedEventArgs e)
        {
            var text = CharInfoConvertHelper.ConvertToElementInfoTableString(this.RxCurrentText.Value);

            Clipboard.SetText(text);
            var item = sender as Control;

            item.Visibility = Visibility.Hidden;
            Task.Delay(kCopyFlashInterval).ContinueWith(x => { this.Dispatcher.Invoke(() => { item.Visibility = Visibility.Visible; }); });
        }
Exemplo n.º 2
0
        public static string ConvertToElementLengthInfoString(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }

            var ci = new CharInfo(str);
            var s  = CharInfoConvertHelper.Ellipsize(ci.PrintableText, 20);

            return($"'{s}' | {ci.ElementCount} elements | {ci.Utf16Count} bytes (16BE) | {ci.Utf8Count} bytes (8)");
        }
Exemplo n.º 3
0
        public static string ConvertToElementInfoString(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(null);
            }

            var ci = new CharInfo(str);
            var s  = CharInfoConvertHelper.Ellipsize(ci.PrintableText, 20);

            return($"'{s}' | {ci.CodePointText} | {ci.Utf16BECodeText} (16BE) | {ci.Utf8CodeText} (8)");
        }
Exemplo n.º 4
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var result = CharInfoConverter.InvalidValueString;

            if (!(values[0] is string currentText))
            {
                return(result);
            }
            if (!(values[1] is int selectionLength))
            {
                return(result);
            }
            return((selectionLength == 0) ?
                   (CharInfoConvertHelper.ConvertToElementInfoString(currentText) ?? result) :
                   (CharInfoConvertHelper.ConvertToElementLengthInfoString(currentText) ?? result));
        }
Exemplo n.º 5
0
        private void InputTextBox_SelectionChanged(object sender, RoutedEventArgs e)
        {
            if (!this.IsInitialized)
            {
                return;
            }

            var caretIndex = this.InputTextBox.CaretIndex;
            var lineIndex  = this.InputTextBox.GetLineIndexFromCharacterIndex(caretIndex);
            var lines      = LineString.Split(this.InputTextBox.Text).ToArray();
            // GetLineText and GetCharacterIndexFromLineIndex does not work correctly in full-screen mode.
            var currentLine  = lines[lineIndex]; //this.InputTextBox.GetLineText(lineIndex);
            var selectedText = this.InputTextBox.SelectedText;

            if (lineIndex != this.lastCalculatedLineIndex || this.RxSelectionLength.Value != selectedText.Length)
            {
                // Recalculate current line
                this.calculator.Reset();
                for (int i = 0; i <= lineIndex; i++)
                {
                    this.calculator.Calculate(lines[i].Text);
                }
                if (0 < selectedText.Length)
                {
                    this.calculator.Calculate(selectedText);
                }
                if (this.calculator.Error == null)
                {
                    this.RxResult.Value = this.calculator.Result.ToString();
                }
                this.RxErrorText.Value       = this.calculator.Error;
                this.lastCalculatedLineIndex = lineIndex;
            }

            if (selectedText.Length == 0)
            {
                int lineStartCharIndex = TextBoxHelper.GetCharacterIndexOfLineStartFromLineIndex(lines, lineIndex);
                int charIndexOfLine    = caretIndex - lineStartCharIndex;
                var offset             = (charIndexOfLine < currentLine.Text.Length) ? 0 : -1;
                selectedText = CharInfoConvertHelper.GetUnicodeElement(currentLine.Text, charIndexOfLine + offset);
            }
            this.RxCurrentText.Value     = selectedText;
            this.RxSelectionLength.Value = this.InputTextBox.SelectionLength;
        }
Exemplo n.º 6
0
        public CharInfo(string input)
        {
            var si         = new StringInfo(input);
            var codePoints = new List <string>();
            var utf8Codes  = new List <string>();
            var utf16Codes = new List <string>();

            for (int i = 0; i < si.LengthInTextElements; i++)
            {
                var element = si.SubstringByTextElements(i, 1);
                codePoints.Add($"U+{char.ConvertToUtf32(element, 0):X}");
                utf8Codes.Add(string.Join(":", Encoding.UTF8.GetBytes(element).Select(c => $"{c:X2}")));
                utf16Codes.Add(string.Join(":", Encoding.BigEndianUnicode.GetBytes(element).Select(c => $"{c:X2}")));
            }
            this.Text            = input;
            this.PrintableText   = CharInfoConvertHelper.ConvertToPrintable(input);
            this.CodePointText   = string.Join(" ", codePoints);
            this.Utf8CodeText    = string.Join(" ", utf8Codes);
            this.Utf16BECodeText = string.Join(" ", utf16Codes);
            this.ElementCount    = si.LengthInTextElements;
            this.Utf8Count       = Encoding.UTF8.GetBytes(input).Length;
            this.Utf16Count      = Encoding.BigEndianUnicode.GetBytes(input).Length;
        }