diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-04-06 13:18:12 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-04-06 13:18:12 +0200 |
commit | 9d40128afd7fcd038ff6532722b55b1a8c189ce8 (patch) | |
tree | 158eb1ffa1c9e3b6a152284c96668d666677d3f3 /runtime | |
parent | 4a5711b5ea54525a262a57ec0d418f76504bad46 (diff) | |
download | vim-git-9d40128afd7fcd038ff6532722b55b1a8c189ce8.tar.gz |
patch 8.1.1122: char2nr() does not handle composing charactersv8.1.1122
Problem: char2nr() does not handle composing characters.
Solution: Add str2list() and list2str(). (Ozaki Kiichi, closes #4190)
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 29 | ||||
-rw-r--r-- | runtime/doc/usr_41.txt | 6 |
2 files changed, 33 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 0b9fb5425..67f548d26 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2442,6 +2442,7 @@ libcallnr({lib}, {func}, {arg}) Number idem, but return a Number line({expr}) Number line nr of cursor, last line or mark line2byte({lnum}) Number byte count of line {lnum} lispindent({lnum}) Number Lisp indent for line {lnum} +list2str({list} [, {utf8}]) String turn numbers in {list} into a String localtime() Number current time log({expr}) Float natural logarithm (base e) of {expr} log10({expr}) Float logarithm of Float {expr} to base 10 @@ -2609,6 +2610,8 @@ split({expr} [, {pat} [, {keepempty}]]) List make |List| from {pat} separated {expr} sqrt({expr}) Float square root of {expr} str2float({expr}) Float convert String to Float +str2list({expr} [, {utf8}]) List convert each character of {expr} to + ASCII/UTF8 value str2nr({expr} [, {base}]) Number convert String to Number strchars({expr} [, {skipcc}]) Number character length of the String {expr} strcharpart({str}, {start} [, {len}]) @@ -6193,6 +6196,20 @@ lispindent({lnum}) *lispindent()* When {lnum} is invalid or Vim was not compiled the |+lispindent| feature, -1 is returned. +list2str({list} [, {utf8}]) *list2str()* + Convert each number in {list} to a character string can + concatenate them all. Examples: > + list2str([32]) returns " " + list2str([65, 66, 67]) returns "ABC" +< The same can be done (slowly) with: > + join(map(list, {nr, val -> nr2char(val)}), '') +< |str2list()| does the opposite. + + When {utf8} is omitted or zero, the current 'encoding' is used. + With {utf8} is 1, always return utf-8 characters. + With utf-8 composing characters work as expected: > + list2str([97, 769]) returns "á" +< localtime() *localtime()* Return the current time, measured as seconds since 1st Jan 1970. See also |strftime()| and |getftime()|. @@ -8722,6 +8739,18 @@ str2float({expr}) *str2float()* let f = str2float(substitute(text, ',', '', 'g')) < {only available when compiled with the |+float| feature} +str2list({expr} [, {utf8}]) *str2list()* + Return a list containing the number values which represent + each character in String {expr}. Examples: > + str2list(" ") returns [32] + str2list("ABC") returns [65, 66, 67] +< |list2str()| does the opposite. + + When {utf8} is omitted or zero, the current 'encoding' is used. + With {utf8} set to 1, always treat the String as utf-8 + characters. With utf-8 composing characters are handled + properly: > + str2list("á") returns [97, 769] str2nr({expr} [, {base}]) *str2nr()* Convert string {expr} to a number. diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index b3b9d3eb9..e8fab8847 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -577,8 +577,10 @@ used for. You can find an alphabetical list here: |functions|. Use CTRL-] on the function name to jump to detailed help on it. String manipulation: *string-functions* - nr2char() get a character by its ASCII value - char2nr() get ASCII value of a character + nr2char() get a character by its number value + list2str() get a character string from a list of numbers + char2nr() get number value of a character + str2list() get list of numbers from a string str2nr() convert a string to a Number str2float() convert a string to a Float printf() format a string according to % items |