summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2014-11-17 08:59:01 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2014-11-17 09:22:14 +0100
commitacd78552de4179d869cf7061dffab22063466f1c (patch)
treef6a4290977b5c9a7ea35373ac5f9b366b5b0f48a /include
parente47b43f4c2fd2a634469b3f2797352d0e3d09ca3 (diff)
Add rtl::OUString::toUtf8()
There is rtl::OUStringToOString() already to do OUString to OString conversion using UTF-8 encoding on a best effort basis. However multiple modules have code where we assume that such a conversion is perfect. Add a new method that asserts such an expected success instead of duplicating it at multiple places. Change-Id: I0e55b53f558df82b67af6a463c8144655cf0ca74
Diffstat (limited to 'include')
-rw-r--r--include/rtl/ustring.hxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/rtl/ustring.hxx b/include/rtl/ustring.hxx
index b9a868b314a0..66b320f09636 100644
--- a/include/rtl/ustring.hxx
+++ b/include/rtl/ustring.hxx
@@ -2106,6 +2106,29 @@ public:
}
/**
+ * Convert this string to an OString, assuming that the string can be
+ * UTF-8-encoded successfully.
+ *
+ * In other words, you must not use this method on a random sequence of
+ * UTF-16 code units, but only at places where it is assumed that the
+ * content is a proper string.
+ *
+ * @since LibreOffice 4.4
+ */
+ inline OString toUtf8() const
+ {
+ OString aTarget;
+ bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
+ getStr(),
+ getLength(),
+ RTL_TEXTENCODING_UTF8,
+ RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
+ (void) bSuccess;
+ assert(bSuccess);
+ return aTarget;
+ }
+
+ /**
Returns the string representation of the integer argument.
This function can't be used for language specific conversion.