From 6f2e3b88649543d625b76ac5542dd8838b28f0b1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 12 Feb 2009 02:34:39 -0400 Subject: Properly handle UTF-8 characters in commodity strings. --- src/format.h | 48 +----------------------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) (limited to 'src/format.h') diff --git a/src/format.h b/src/format.h index 49350104..d1716dbf 100644 --- a/src/format.h +++ b/src/format.h @@ -47,58 +47,12 @@ #define _FORMAT_H #include "expr.h" +#include "unistring.h" namespace ledger { DECLARE_EXCEPTION(format_error, std::runtime_error); -#if defined(SUPPORT_UNICODE) - -/** - * @class unistring - * - * @brief Abstract working with UTF-32 encoded Unicode strings - * - * The input to the string is a UTF8 encoded ledger::string, which can - * then have its true length be taken, or characters extracted. - */ -class unistring -{ - std::vector utf32chars; - -public: - unistring(const string& input) - { - TRACE_CTOR(unistring, ""); - - const char * p = input.c_str(); - std::size_t len = input.length(); - - VERIFY(utf8::is_valid(p, p + len)); - - utf8::utf8to32(p, p + len, std::back_inserter(utf32chars)); - } - ~unistring() { - TRACE_DTOR(unistring); - } - - std::size_t length() const { - return utf32chars.size(); - } - - string extract(const std::size_t begin = 0, - const std::size_t len = 0) const - { - string utf8result; - utf8::utf32to8(utf32chars.begin() + begin, - utf32chars.begin() + begin + (len ? len : length()), - std::back_inserter(utf8result)); - return utf8result; - } -}; - -#endif // SUPPORT_UNICODE - class report_t; /** -- cgit v1.2.3