diff options
Diffstat (limited to 'src/unistring.h')
-rw-r--r-- | src/unistring.h | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/unistring.h b/src/unistring.h index eb38f8b1..340115eb 100644 --- a/src/unistring.h +++ b/src/unistring.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003-2013, John Wiegley. All rights reserved. + * Copyright (c) 2003-2014, John Wiegley. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -44,6 +44,8 @@ namespace ledger { +int mk_wcwidth(boost::uint32_t ucs); + /** * @class unistring * @@ -81,6 +83,14 @@ public: return utf32chars.size(); } + std::size_t width() const { + std::size_t width = 0; + foreach (const boost::uint32_t& ch, utf32chars) { + width += mk_wcwidth(ch); + } + return width; + } + std::string extract(const std::string::size_type begin = 0, const std::string::size_type len = 0) const { @@ -133,7 +143,7 @@ inline void justify(std::ostream& out, unistring temp(str); - int spacing = width - int(temp.length()); + int spacing = width - int(temp.width()); while (spacing-- > 0) out << ' '; |