diff options
author | Kan-Ru Chen (陳侃如) <kanru@kanru.info> | 2014-02-13 18:40:06 +0800 |
---|---|---|
committer | Kan-Ru Chen (陳侃如) <kanru@kanru.info> | 2014-02-13 18:40:06 +0800 |
commit | d5b5ea02138107918642532a266550d1ab4122d3 (patch) | |
tree | 58ec47b437965f551416bfd3d125a542cd382d8e /src/wcwidth.c.patch | |
parent | c59aadaace0b142eacb89d40921ac331887bb671 (diff) | |
download | fork-ledger-d5b5ea02138107918642532a266550d1ab4122d3.tar.gz fork-ledger-d5b5ea02138107918642532a266550d1ab4122d3.tar.bz2 fork-ledger-d5b5ea02138107918642532a266550d1ab4122d3.zip |
Correctly justify Unicode characters in terminal
Many Unicode characters take more spaces than one ASCII character. For
example, Chinese characters are two characters wide when using monospace
font in terminal. This patch use wcwidth of Markus Kuhn to count the
correct width for justification.
Diffstat (limited to 'src/wcwidth.c.patch')
-rw-r--r-- | src/wcwidth.c.patch | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/wcwidth.c.patch b/src/wcwidth.c.patch new file mode 100644 index 00000000..5864a056 --- /dev/null +++ b/src/wcwidth.c.patch @@ -0,0 +1,74 @@ +--- wcwidth.c 2007-05-26 18:06:24.000000000 +0800 ++++ wcwidth.cc 2014-02-13 18:36:18.668331252 +0800 +@@ -59,15 +59,23 @@ + * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c + */ + +-#include <wchar.h> ++/* This file is modified to work with C++ and present Unicode ++ * characters in uint32_t type. ++ */ ++ ++#include <system.hh> ++ ++namespace ledger { + +-struct interval { +- int first; +- int last; +-}; ++namespace { ++ struct interval { ++ int first; ++ int last; ++ }; ++} + + /* auxiliary function for binary search in interval table */ +-static int bisearch(wchar_t ucs, const struct interval *table, int max) { ++static int bisearch(boost::uint32_t ucs, const struct interval *table, int max) { + int min = 0; + int mid; + +@@ -119,7 +127,7 @@ + * in ISO 10646. + */ + +-int mk_wcwidth(wchar_t ucs) ++int mk_wcwidth(boost::uint32_t ucs) + { + /* sorted list of non-overlapping intervals of non-spacing characters */ + /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ +@@ -204,7 +212,7 @@ + } + + +-int mk_wcswidth(const wchar_t *pwcs, size_t n) ++int mk_wcswidth(const boost::uint32_t *pwcs, size_t n) + { + int w, width = 0; + +@@ -227,7 +235,7 @@ + * the traditional terminal character-width behaviour. It is not + * otherwise recommended for general use. + */ +-int mk_wcwidth_cjk(wchar_t ucs) ++int mk_wcwidth_cjk(boost::uint32_t ucs) + { + /* sorted list of non-overlapping intervals of East Asian Ambiguous + * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ +@@ -295,7 +303,7 @@ + } + + +-int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) ++int mk_wcswidth_cjk(const boost::uint32_t *pwcs, size_t n) + { + int w, width = 0; + +@@ -307,3 +315,5 @@ + + return width; + } ++ ++} // namespace ledger |