summaryrefslogtreecommitdiffstats
path: root/xpcom/string
diff options
context:
space:
mode:
authortrav90 <travawine@palemoon.org>2018-10-06 17:29:50 -0500
committertrav90 <travawine@palemoon.org>2018-10-06 17:29:50 -0500
commitc2fa384d666aea1b119736f33116ac09e870fda0 (patch)
tree643a1009d32e68df792526c79db4a4921a7b02ec /xpcom/string
parent323cb98de19b6f63b52d3fde5d7144712384c058 (diff)
downloadUXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.gz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.lz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.tar.xz
UXP-c2fa384d666aea1b119736f33116ac09e870fda0.zip
Add mozilla::Span
Diffstat (limited to 'xpcom/string')
-rw-r--r--xpcom/string/nsTSubstring.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/xpcom/string/nsTSubstring.h b/xpcom/string/nsTSubstring.h
index a08036b1f..53b4fb9a8 100644
--- a/xpcom/string/nsTSubstring.h
+++ b/xpcom/string/nsTSubstring.h
@@ -7,6 +7,8 @@
#include "mozilla/Casting.h"
#include "mozilla/MemoryReporting.h"
+#include "mozilla/IntegerTypeTraits.h"
+#include "mozilla/Span.h"
#ifndef MOZILLA_INTERNAL_API
#error Cannot use internal string classes without MOZILLA_INTERNAL_API defined. Use the frozen header nsStringAPI.h instead.
@@ -798,6 +800,68 @@ public:
}
#endif
+ /**
+ * Span integration
+ */
+
+ operator mozilla::Span<char_type>()
+ {
+ return mozilla::MakeSpan(BeginWriting(), Length());
+ }
+
+ operator mozilla::Span<const char_type>() const
+ {
+ return mozilla::MakeSpan(BeginReading(), Length());
+ }
+
+ void Append(mozilla::Span<const char_type> aSpan)
+ {
+ auto len = aSpan.Length();
+ MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue<size_type>::value);
+ Append(aSpan.Elements(), len);
+ }
+
+ MOZ_MUST_USE bool Append(mozilla::Span<const char_type> aSpan,
+ const fallible_t& aFallible)
+ {
+ auto len = aSpan.Length();
+ if (len > mozilla::MaxValue<size_type>::value) {
+ return false;
+ }
+ return Append(aSpan.Elements(), len, aFallible);
+ }
+
+#if !defined(CharT_is_PRUnichar)
+ operator mozilla::Span<uint8_t>()
+ {
+ return mozilla::MakeSpan(reinterpret_cast<uint8_t*>(BeginWriting()),
+ Length());
+ }
+
+ operator mozilla::Span<const uint8_t>() const
+ {
+ return mozilla::MakeSpan(reinterpret_cast<const uint8_t*>(BeginReading()),
+ Length());
+ }
+
+ void Append(mozilla::Span<const uint8_t> aSpan)
+ {
+ auto len = aSpan.Length();
+ MOZ_RELEASE_ASSERT(len <= mozilla::MaxValue<size_type>::value);
+ Append(reinterpret_cast<const char*>(aSpan.Elements()), len);
+ }
+
+ MOZ_MUST_USE bool Append(mozilla::Span<const uint8_t> aSpan,
+ const fallible_t& aFallible)
+ {
+ auto len = aSpan.Length();
+ if (len > mozilla::MaxValue<size_type>::value) {
+ return false;
+ }
+ return Append(
+ reinterpret_cast<const char*>(aSpan.Elements()), len, aFallible);
+ }
+#endif
/**
* string data is never null, but can be marked void. if true, the
@@ -1184,3 +1248,22 @@ operator>(const nsTSubstring_CharT::base_string_type& aLhs,
{
return Compare(aLhs, aRhs) > 0;
}
+
+/**
+ * Span integration
+ */
+namespace mozilla {
+
+inline Span<CharT>
+MakeSpan(nsTSubstring_CharT& aString)
+{
+ return aString;
+}
+
+inline Span<const CharT>
+MakeSpan(const nsTSubstring_CharT& aString)
+{
+ return aString;
+}
+
+} // namespace mozilla