Loading ...
Sorry, an error occurred while loading the content.

Behaviour of char2nr() and nr2char()

Expand Messages
  • Christian Brabandt
    Bram, I have a question: The documentation for char2nr() says: ,---- ... `---- That is fine with me, except, that when using combining chars, I get unexpected
    Message 1 of 4 , Jul 11, 2011
    • 0 Attachment
      Bram,
      I have a question: The documentation for char2nr() says:

      ,----
      | char2nr({expr}) *char2nr()*
      | Return number value of the first char in {expr}.
      `----

      That is fine with me, except, that when using combining chars, I get
      unexpected results.

      If I use this character:

      which is U+0075 U+0308 (LATIN SMALL LETTER U WITH COMBINING DIAERESIS),
      yank that char into a register and use char2nr() with that register I
      get only the numeric value for LATIN SMALL LETTER U which is 117.
      Except, that I can't use nr2char again to get the small umlaut back
      again.

      Is that what is supposed to happen? If it is, than is should at least be
      mentioned in the help, I think.

      regards,
      Christian

      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • ZyX
      Reply to message «Behaviour of char2nr() and nr2char()», sent 01:37:37 12 July 2011, Tuesday by Christian Brabandt: Yes, it is what should happen (how do you
      Message 2 of 4 , Jul 11, 2011
      • 0 Attachment
        Reply to message «Behaviour of char2nr() and nr2char()»,
        sent 01:37:37 12 July 2011, Tuesday
        by Christian Brabandt:

        Yes, it is what should happen (how do you imagine converting a character to its
        code in this case?). And yes, it should be mentioned in help because in :h /.
        (and a number of other places like :h x) and in :h char2nr() word «character»
        has different meaning while :h mbyte-combining uses the same meaning of
        «character» as in :h char2nr(). :h mbyte-combining also does not define clearly
        where «character» has what meaning (only «mostly considered part of the
        preceding character» with one example).

        Original message:
        > Bram,
        > I have a question: The documentation for char2nr() says:
        >
        > ,----
        >
        > | char2nr({expr}) *char2nr()*
        > |
        > | Return number value of the first char in {expr}.
        >
        > `----
        >
        > That is fine with me, except, that when using combining chars, I get
        > unexpected results.
        >
        > If I use this character:
        > ü
        > which is U+0075 U+0308 (LATIN SMALL LETTER U WITH COMBINING DIAERESIS),
        > yank that char into a register and use char2nr() with that register I
        > get only the numeric value for LATIN SMALL LETTER U which is 117.
        > Except, that I can't use nr2char again to get the small umlaut back
        > again.
        >
        > Is that what is supposed to happen? If it is, than is should at least be
        > mentioned in the help, I think.
        >
        > regards,
        > Christian
      • Christian Brabandt
        Hi ZyX! ... Looking from a user s perspective, I don t care. May be use NFC form in that simple case. Or make char2nr optionally return a list with each code
        Message 3 of 4 , Jul 11, 2011
        • 0 Attachment
          Hi ZyX!

          On Di, 12 Jul 2011, ZyX wrote:

          > Reply to message «Behaviour of char2nr() and nr2char()»,
          > sent 01:37:37 12 July 2011, Tuesday
          > by Christian Brabandt:
          >

          > Yes, it is what should happen (how do you imagine converting a
          > character to its code in this case?).

          Looking from a user's perspective, I don't care. May be use NFC form in
          that simple case. Or make char2nr optionally return a list with each
          code for every character that has been given, so that nr2char would be
          able to return the correct glyph. That would need an optional argument
          to char2nr() not sure if it is worth it.

          regards,
          Christian

          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • ZyX
          Reply to message «Re: Behaviour of char2nr() and nr2char()», sent 01:55:15 12 July 2011, Tuesday ... nr2char(char2nr(str)) will no longer be equal to
          Message 4 of 4 , Jul 11, 2011
          • 0 Attachment
            Reply to message «Re: Behaviour of char2nr() and nr2char()»,
            sent 01:55:15 12 July 2011, Tuesday
            by Christian Brabandt:

            > Looking from a user's perspective, I don't care. May be use NFC form in
            > that simple case.
            nr2char(char2nr(str)) will no longer be equal to
            str[:(len(nr2char(char2nr(str)))-1)], won't it?

            > Or make char2nr optionally return a list with each
            > code for every character that has been given, so that nr2char would be
            > able to return the correct glyph. That would need an optional argument
            > to char2nr() not sure if it is worth it.
            I don't think it is, but I won't object to it.

            By the way, char2nr() is now the only way to obtain first character without any
            diacritics that I know. Having a `\%.' atom meaning «one character with
            combining characters taken separate» would be better because solutions with
            char2nr look ugly (especially if I want to care about invalid unicode).

            Original message:
            > Hi ZyX!
            >
            > On Di, 12 Jul 2011, ZyX wrote:
            > > Reply to message «Behaviour of char2nr() and nr2char()»,
            > > sent 01:37:37 12 July 2011, Tuesday
            > > by Christian Brabandt:
            > >
            > >
            > > Yes, it is what should happen (how do you imagine converting a
            > > character to its code in this case?).
            >
            > Looking from a user's perspective, I don't care. May be use NFC form in
            > that simple case. Or make char2nr optionally return a list with each
            > code for every character that has been given, so that nr2char would be
            > able to return the correct glyph. That would need an optional argument
            > to char2nr() not sure if it is worth it.
            >
            > regards,
            > Christian
          Your message has been successfully submitted and would be delivered to recipients shortly.