Bug 1932613 - temporarily disable browser_ml_end_to_end.js for permanent failures...
[gecko.git] / xpcom / base / JSONStringWriteFuncs.h
blob65b688788cbf3d49012d59509850534feb8d3734
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef JSONSTRINGWRITEFUNCS_H
8 #define JSONSTRINGWRITEFUNCS_H
10 #include "mozilla/JSONWriter.h"
11 #include "nsString.h"
13 #include <type_traits>
15 namespace mozilla {
17 // JSONWriteFunc that writes to an owned string.
18 template <typename StringType>
19 class JSONStringWriteFunc final : public JSONWriteFunc {
20 static_assert(
21 !std::is_reference_v<StringType>,
22 "Use JSONStringRefWriteFunc instead to write to a referenced string");
24 public:
25 JSONStringWriteFunc() = default;
27 void Write(const Span<const char>& aStr) final { mString.Append(aStr); }
29 const StringType& StringCRef() const { return mString; }
31 StringType&& StringRRef() && { return std::move(mString); }
33 private:
34 StringType mString;
37 // JSONWriteFunc that writes to a given nsACString reference.
38 class JSONStringRefWriteFunc final : public JSONWriteFunc {
39 public:
40 MOZ_IMPLICIT JSONStringRefWriteFunc(nsACString& aString) : mString(aString) {}
42 void Write(const Span<const char>& aStr) final { mString.Append(aStr); }
44 const nsACString& StringCRef() const { return mString; }
46 private:
47 nsACString& mString;
50 } // namespace mozilla
52 #endif // JSONSTRINGWRITEFUNCS_H