Bug 1874684 - Part 4: Prefer const references instead of copying Instant values....
[gecko.git] / xpcom / string / nsTString.cpp
blob4e845f62df2ea845778e4ed22de2af12b7e9d5f1
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 #include "nsTString.h"
8 #include "nsString.h"
9 #include "prdtoa.h"
11 /**
12 * nsTString::SetCharAt
15 template <typename T>
16 bool nsTString<T>::SetCharAt(char16_t aChar, index_type aIndex) {
17 if (aIndex >= this->mLength) {
18 return false;
21 if (!this->EnsureMutable()) {
22 this->AllocFailed(this->mLength);
25 this->mData[aIndex] = char_type(aChar);
26 return true;
29 template <typename T>
30 void nsTString<T>::Rebind(const char_type* data, size_type length) {
31 // If we currently own a buffer, release it.
32 this->Finalize();
34 this->SetData(const_cast<char_type*>(data), length, DataFlags::TERMINATED);
35 this->AssertValidDependentString();
38 template class nsTString<char>;
39 template class nsTString<char16_t>;
41 template class nsTAutoStringN<char, 64>;
42 template class nsTAutoStringN<char16_t, 64>;