public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Leif Lindholm" <leif@nuviainc.com>
To: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ray Ni <ray.ni@intel.com>, Zhichao Gao <zhichao.gao@intel.com>,
	Ard Biesheuvel <ard.biesheuvel@arm.com>,
	devel@edk2.groups.io, Laszlo Ersek <lersek@redhat.com>,
	Liming Gao <liming.gao@intel.com>
Subject: Re: [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit
Date: Tue, 3 Nov 2020 23:42:26 +0000	[thread overview]
Message-ID: <20201103234226.GR1664@vanye> (raw)
In-Reply-To: <20201102231114.31099-1-xypron.glpk@gmx.de>

Ray, Zhichao - please comment.
I'm not sure what the correct answer is here, but current behaviour
seems suboptimal.

Best Regards,

Leif

On Tue, Nov 03, 2020 at 00:11:14 +0100, Heinrich Schuchardt wrote:
> REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2339
> 
> Currently it is not possible to add letters outside the range
> U+0020 - U+007F to a file using the edit command.
> 
> In Unicode the following are control characters:
> 
> * U+0000—U+001F (C0 controls)
> * U+007F (DEL)
> * U+0080—U+009F (C1 controls).
> 
> For reference see:
> 
> * https://unicode.org/charts/PDF/U0000.pdf
> * https://unicode.org/charts/PDF/U0080.pdf
> 
> So the characters we should exclude from the file buffer are:
> U+0000 - U+001f, U+007f - U009F
> 
> Allow all other characters as input to the file buffer in Unicode mode.
> Allow only ASCII characters as input in ASCII mode.
> 
> When saving a file in ASCII mode replace non-ASCII characters by a question
> mark ('?').
> 
> For editing texts with double width characters (e.g. Japanese) further
> adjustments will be needed.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
> Resent.
> Original message https://edk2.groups.io/g/devel/message/51205
> ---
>  .../Edit/FileBuffer.c                         | 21 +++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
> 
> diff --git a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> index 5659ec981054..3923b83670fa 100644
> --- a/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> +++ b/ShellPkg/Library/UefiShellDebug1CommandsLib/Edit/FileBuffer.c
> @@ -1360,6 +1360,8 @@ GetNewLine (
>  /**
>    Change a Unicode string to an ASCII string.
> 
> +  Non-ASCII characters are replaced by '?'.
> +
>    @param[in] UStr     The Unicode string.
>    @param[in] Length   The maximum size of AStr.
>    @param[out] AStr    ASCII string to pass out.
> @@ -1378,8 +1380,12 @@ UnicodeToAscii (
>    //
>    // just buffer copy, not character copy
>    //
> -  for (Index = 0; Index < Length; Index++) {
> -    *AStr++ = (CHAR8) *UStr++;
> +  for (Index = 0; Index < Length; Index++, UStr++) {
> +    if (*UStr < 0x80) {
> +      *AStr++ = (CHAR8) *UStr;
> +    } else {
> +      *AStr++ = '?';
> +    }
>    }
> 
>    return Index;
> @@ -2154,9 +2160,16 @@ FileBufferDoCharInput (
> 
>    default:
>      //
> -    // DEAL WITH ASCII CHAR, filter out thing like ctrl+f
> +    // Do not add Unicode control characters to the file buffer:
>      //
> -    if (Char > 127 || Char < 32) {
> +    // * U+0000-U+001f (C0 controls)
> +    // * U+007f (DEL)
> +    // * U+0080-U+009f (C1 controls)
> +    //
> +    // Do not add non-ASCII characters in ASCII mode.
> +    //
> +    if (Char < 0x20 || (Char >= 0x7f &&
> +        (Char <= 0x9f || FileBuffer.FileType == FileTypeAscii))) {
>        Status = StatusBarSetStatusString (L"Unknown Command");
>      } else {
>        Status = FileBufferAddChar (Char);
> --
> 2.28.0
> 

  reply	other threads:[~2020-11-03 23:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 23:11 [edk] [PATCH] ShellPkg/edit: allow non-ASCII characters in edit Heinrich Schuchardt
2020-11-03 23:42 ` Leif Lindholm [this message]
2020-11-04 17:23 ` Laszlo Ersek
  -- strict thread matches above, loose matches on Subject: below --
2019-11-24 10:37 Heinrich Schuchardt
2019-11-24 10:15 Heinrich Schuchardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103234226.GR1664@vanye \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox