Bug 1867190 - Add prefs for PHC probablities r=glandium
[gecko.git] / xpcom / string / RustStringAPI.cpp
blob55ce6b9eeb49501c35c753298f1efa534382a551
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsISupports.h"
8 #include "nsString.h"
10 // Extern "C" utilities used by the rust nsString bindings.
12 // Provide rust bindings to the nsA[C]String types
13 extern "C" {
15 // This is a no-op on release, so we ifdef it out such that using it in release
16 // results in a linker error.
17 #ifdef DEBUG
18 void Gecko_IncrementStringAdoptCount(void* aData) {
19 MOZ_LOG_CTOR(aData, "StringAdopt", 1);
21 #elif defined(MOZ_DEBUG_RUST)
22 void Gecko_IncrementStringAdoptCount(void* aData) {}
23 #endif
25 void Gecko_FinalizeCString(nsACString* aThis) { aThis->~nsACString(); }
27 void Gecko_AssignCString(nsACString* aThis, const nsACString* aOther) {
28 aThis->Assign(*aOther);
31 void Gecko_TakeFromCString(nsACString* aThis, nsACString* aOther) {
32 aThis->Assign(std::move(*aOther));
35 void Gecko_AppendCString(nsACString* aThis, const nsACString* aOther) {
36 aThis->Append(*aOther);
39 void Gecko_SetLengthCString(nsACString* aThis, uint32_t aLength) {
40 aThis->SetLength(aLength);
43 bool Gecko_FallibleAssignCString(nsACString* aThis, const nsACString* aOther) {
44 return aThis->Assign(*aOther, mozilla::fallible);
47 bool Gecko_FallibleTakeFromCString(nsACString* aThis, nsACString* aOther) {
48 return aThis->Assign(std::move(*aOther), mozilla::fallible);
51 bool Gecko_FallibleAppendCString(nsACString* aThis, const nsACString* aOther) {
52 return aThis->Append(*aOther, mozilla::fallible);
55 bool Gecko_FallibleSetLengthCString(nsACString* aThis, uint32_t aLength) {
56 return aThis->SetLength(aLength, mozilla::fallible);
59 char* Gecko_BeginWritingCString(nsACString* aThis) {
60 return aThis->BeginWriting();
63 char* Gecko_FallibleBeginWritingCString(nsACString* aThis) {
64 return aThis->BeginWriting(mozilla::fallible);
67 uint32_t Gecko_StartBulkWriteCString(nsACString* aThis, uint32_t aCapacity,
68 uint32_t aUnitsToPreserve,
69 bool aAllowShrinking) {
70 return aThis->StartBulkWriteImpl(aCapacity, aUnitsToPreserve, aAllowShrinking)
71 .unwrapOr(UINT32_MAX);
74 void Gecko_FinalizeString(nsAString* aThis) { aThis->~nsAString(); }
76 void Gecko_AssignString(nsAString* aThis, const nsAString* aOther) {
77 aThis->Assign(*aOther);
80 void Gecko_TakeFromString(nsAString* aThis, nsAString* aOther) {
81 aThis->Assign(std::move(*aOther));
84 void Gecko_AppendString(nsAString* aThis, const nsAString* aOther) {
85 aThis->Append(*aOther);
88 void Gecko_SetLengthString(nsAString* aThis, uint32_t aLength) {
89 aThis->SetLength(aLength);
92 bool Gecko_FallibleAssignString(nsAString* aThis, const nsAString* aOther) {
93 return aThis->Assign(*aOther, mozilla::fallible);
96 bool Gecko_FallibleTakeFromString(nsAString* aThis, nsAString* aOther) {
97 return aThis->Assign(std::move(*aOther), mozilla::fallible);
100 bool Gecko_FallibleAppendString(nsAString* aThis, const nsAString* aOther) {
101 return aThis->Append(*aOther, mozilla::fallible);
104 bool Gecko_FallibleSetLengthString(nsAString* aThis, uint32_t aLength) {
105 return aThis->SetLength(aLength, mozilla::fallible);
108 char16_t* Gecko_BeginWritingString(nsAString* aThis) {
109 return aThis->BeginWriting();
112 char16_t* Gecko_FallibleBeginWritingString(nsAString* aThis) {
113 return aThis->BeginWriting(mozilla::fallible);
116 uint32_t Gecko_StartBulkWriteString(nsAString* aThis, uint32_t aCapacity,
117 uint32_t aUnitsToPreserve,
118 bool aAllowShrinking) {
119 return aThis->StartBulkWriteImpl(aCapacity, aUnitsToPreserve, aAllowShrinking)
120 .unwrapOr(UINT32_MAX);
123 } // extern "C"