summaryrefslogtreecommitdiff
path: root/src/format.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-02-12 02:34:39 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-02-12 02:34:39 -0400
commit6f2e3b88649543d625b76ac5542dd8838b28f0b1 (patch)
treeaf76d46718d4b2b3e51c05c3c53a09987505f02f /src/format.h
parent9c9320bc586bc80922921945bfe6bb704c36c624 (diff)
downloadfork-ledger-6f2e3b88649543d625b76ac5542dd8838b28f0b1.tar.gz
fork-ledger-6f2e3b88649543d625b76ac5542dd8838b28f0b1.tar.bz2
fork-ledger-6f2e3b88649543d625b76ac5542dd8838b28f0b1.zip
Properly handle UTF-8 characters in commodity strings.
Diffstat (limited to 'src/format.h')
-rw-r--r--src/format.h48
1 files changed, 1 insertions, 47 deletions
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<uint32_t> 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;
/**