From a8e45b48415d60d6a2d37bb2a09de97881f91c20 Mon Sep 17 00:00:00 2001
From: ilor <kailoran@gmail.com>
Date: Wed, 9 Feb 2011 14:54:17 +0100
Subject: [PATCH] add UnicodeString variants of to_raw_string and to_string to
 Value

---
 libwccl/values/strset.cpp | 17 +++++++++++++++++
 libwccl/values/strset.h   |  3 +++
 libwccl/values/value.h    | 14 ++++++++++++++
 3 files changed, 34 insertions(+)

diff --git a/libwccl/values/strset.cpp b/libwccl/values/strset.cpp
index 18f1946..e3c6999 100644
--- a/libwccl/values/strset.cpp
+++ b/libwccl/values/strset.cpp
@@ -23,6 +23,23 @@ std::string StrSet::to_raw_string() const
 	return ss.str();
 }
 
+UnicodeString StrSet::to_raw_string_u() const
+{
+	UnicodeString u;
+	u.append(UNICODE_STRING("[", 1));
+	value_type::const_iterator it = set_.begin();
+	while(it != set_.end()) {
+		u.append(UNICODE_STRING("\"", 1));
+		u.append(*it); //TODO escaping
+		u.append(UNICODE_STRING("\"", 1));
+		if(++it != set_.end()) {
+			u.append(UNICODE_STRING(", ", 2));
+		}
+	}
+	u.append(UNICODE_STRING("]", 1));
+	return u;
+}
+
 bool StrSet::intersects(const StrSet &other) const {
 	if (empty() || other.empty()) {
 		return false;
diff --git a/libwccl/values/strset.h b/libwccl/values/strset.h
index 5b95467..e1abb89 100644
--- a/libwccl/values/strset.h
+++ b/libwccl/values/strset.h
@@ -96,6 +96,9 @@ public:
 	/// Value override
 	std::string to_raw_string() const;
 
+	/// Value override
+	UnicodeString to_raw_string_u() const;
+
 private:
 	value_type set_;
 };
diff --git a/libwccl/values/value.h b/libwccl/values/value.h
index f4048c0..89b276d 100644
--- a/libwccl/values/value.h
+++ b/libwccl/values/value.h
@@ -49,6 +49,13 @@ public:
 		return to_raw_string();
 	}
 
+	/**
+	 * Unicode variant of to_string
+	 */
+	virtual UnicodeString to_string_u(const Corpus2::Tagset& /*tagset*/) const {
+		return to_raw_string_u();
+	}
+
 	/**
 	 * String representation of the Value that does not require a tagset,
 	 * might be incomplete and/or contain internal info.
@@ -57,6 +64,13 @@ public:
 	 */
 	virtual std::string to_raw_string() const = 0;
 
+	/**
+	 * Unicode variant of to_raw_string
+	 */
+	virtual UnicodeString to_raw_string_u() const {
+		return UnicodeString::fromUTF8(to_raw_string());
+	}
+
 protected:
 	Value() {}
 };
-- 
GitLab