nsTDependentSubstring.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. void
  6. nsTDependentSubstring_CharT::Rebind(const substring_type& str,
  7. uint32_t startPos, uint32_t length)
  8. {
  9. // If we currently own a buffer, release it.
  10. Finalize();
  11. size_type strLength = str.Length();
  12. if (startPos > strLength) {
  13. startPos = strLength;
  14. }
  15. mData = const_cast<char_type*>(static_cast<const char_type*>(str.Data())) + startPos;
  16. mLength = XPCOM_MIN(length, strLength - startPos);
  17. SetDataFlags(F_NONE);
  18. }
  19. void
  20. nsTDependentSubstring_CharT::Rebind(const char_type* data, size_type length)
  21. {
  22. NS_ASSERTION(data, "nsTDependentSubstring must wrap a non-NULL buffer");
  23. // If we currently own a buffer, release it.
  24. Finalize();
  25. mData = const_cast<char_type*>(static_cast<const char_type*>(data));
  26. mLength = length;
  27. SetDataFlags(F_NONE);
  28. }