mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 22:53:28 +00:00
69d1f32ff7
- Bug 1268085 - Remove unused post barrier callbacks r=terrence (0ab13411c9) - Bug 1267699 - Move some public types to the right namespace; r=sfink (3d5008e610) - Bug 1267550 (part 1) - Rename MOZ_MUST_USE as MOZ_MUST_USE_TYPE. r=ehsan. (6f47375796) - Bug 1259021 - Rename Vector::extractRawBuffer to extractOrCopyRawBuffer r=Waldo (97ca94495b) - Bug 1259021 - Add Vector::extractRawBuffer method that doesn't copy the buffer r=Waldo (e58deec48f) - Bug 1265892 - Change Vector to use Impl::new_ consistently. r=Waldo (7a52d21b29) - Bug 1267912 - Rename nsNetUtil.inl as nsNetUtilInlines.h. r=valentin. (548a41b293) - Bug 1265690 part 1 - Mark StringBuffer methods WARN_UNUSED_RESULT, fix OOM issues. r=jonco (0d7e6837e3) - Bug 1265690 part 2 - Fix some more OOM issues in TypedObject code. r=jonco (b60902453e) - Bug 1263490 - Part 2: Add GetFirstDollarIndex intrinsic and use it inRegExpReplace. r=till (4ba19db8c4) - Bug 1263490 - Part 3: Inline GetFirstDollarIndex intrinsic. r=h4writer (e7d9b5d1cc) - Bug 1263490 - Part 4: Fold GetFirstDollarIndex into a integer constant. r=h4writer (3479c7d1af) - Bug 1267269 - Make MIRType an enum class. r=bbouvier (d580ef372a) - Bug 1259295 - BaldrMonkey: Postorder (r=luke) (6ef7a77663) - Bug 1254142: BaldrMonkey: make br_table yield (r=luke) (80e7635e58) - Bug 1263202 - BaldrMonkey: switch to arities on branches, calls and return (r=bbouvier) (f5a0358634) - Bug 1236358 - Improper reading of string16 in Pickle::ReadString16. r=jld (8370ba6a0b) - Bug 1263205 - BaldrMonkey: Update section headers for proposed spec changes (r=luke) (0def2e6bc2) - Bug 1263205 - BaldrMonkey: Update for proposed new section names (r=luke) (e57f0e3367) - Bug 1263205 - BaldrMonkey: Add 'form' field to types section (r=bbouvier) (794edc890f) - Bug 1259021 - Use in-place storage in AutoStableStringChars to avoid allocation for short strings r=jandem r=Waldo (ffb53cbcf4) - Bug 1267550 (part 2) - Rename MOZ_WARN_UNUSED_RESULT as MOZ_MUST_USE. r=froydnj. (47bc674b86) - Bug 1268518: Baldr: implement int32/int64 rotations; r=luke (0d5eedccce) - Bug 1255008: IonMonkey - Add a by default disabled flow sensitive alias analysis pass, r=jandem (521c585d75) - Bug 1266781: Baldr: implement proper checked truncations to integer types; r=sunfish (46078fb3d3) - Bug 1266781: Rename MTruncateToInt64 into MWasmTruncateInt64; r=sunfish (c7d7d1ac11) - Bug 1266781: Add new traps; r=luke (b7ed3d44e6) - Bug 1268024: Pass the atomic attribute down to EmitHeapAccess; r=luke (6195f7d7a3) - Bug 1268024: A few cleanups related to loads/stores; r=luke (88141e3a01) - Bug 1258312 - Make Pickle::Resize infallible r=jld (241ee9b60d) - Bug 1162772, part 1 - Allow CompartmentCreationOptions to store Secure Context state. r=jorendorff (ff666384cf) - Bug 1162772, part 2 - Expose whether SEC_FORCE_INHERIT_PRINCIPAL was dropped from an nsILoadInfo. r=bz (ada46f86bf) - Bug 1162772, part 3 - Add a getChannelResultPrincipalIfNotSandboxed method to nsIScriptSecurityManager. r=bz (5b1d9f6807) - Bug 1162772, part 4 - Implement nsGlobalWindow::IsSecureContext. r=bz (f392f439c9) - Bug 1162772, part 5 - Expose Window.isSecureContext to content. r=bz (e7296e2cf1) - Bug 1267509 - Make nsContentSecurityManager::IsURIPotentiallyTrustworthy act on an nsIPrincipal. r=bz (83de80350a) - Bug 1219098 - Use UniquePtr in UncompressedSourceCache, for it is good (r=jandem) (b68769c729) - Bug 1244279 - Part 1: Take a bit in ObjectElements::Flags to indicate whether the object is in the whole cell store buffer. r=terrence (968cf373f9) - Bug 1244279 - Part 0: Add a GC ubench for large arrays with both elements and properties. r=terrence (ec76b48323) - Bug 1255925 - Give a name to getters/setters and integer-named methods. r=efaust (f978cc6916) - Bug 888969 - Make the getPrototypeOf/setPrototypeOf traps scriptable. r=efaust, r=bholley (eb2325a9ea) - Bug 1267557 part 0 - Move JS poison constants to jsutil.h. r=jonco (65afc690d2) - Bug 1267557 part 1 - Also poison bytes allocated before the actual jitcode. r=nbp (70f0b327d3) - Bug 1267557 part 2 - Use different jitcode poison values. r=nbp (08008ab9dc) - Bug 1267557 part 3 - Define JS_SWEPT_CODE_PATTERN for mips. r=nbp (17e894d59d) - Bug 1267449 - Do not infinite loop in js_fputs; r=jimb (67f961b6cd) - Bug 1219098 - Reenable compression on large sources, but revert to uncompressed if decompression happens (r=jandem) (b44ee8d77d) - Bug 1267551 (part 1) - Use MOZ_MUST_USE more in jsnum.h. r=jonco. (d2476bf8f4) - Bug 1267551 (part 2) - Use MOZ_MUST_USE more in js/src/ds/. r=jonco. (4ff5d9aa88) - Bug 1267412 - Use MutableHandleValue instead of pointer-to-AutoValueVector; r=sfink (3f6dd284bb) - Bug 1266406 - Use EnumSet<AllocKind> to simplify GC sweeping phase information r=terrence (64811500e7) - Bug 1266457 - Update pointers in GC things in two phases when compacting r=terrence (f6f5bc4e4d) - Bug 1266457 - Simplify typed object trace hook r=terence (3b06c8d1e5) - Bug 1268541 - Compact arenas containing base shapes r=terrence (b458b92eea) - Bug 1268805 - Implement PrivateGCThingValue. (r=terrence) (deec9a83ae) - Bug 1268415: Initialize members in UpdatePointerTasks; r=jonco (6cb219005a) - Bug 1268501 - Release the GC lock periodically when releasing arenas on the backgound thread r=terrence (37f0997682) - Bug 1263572 - Wait for background sweeping to finish before checking base shapes r=terrence (354801a411) - Bug 1266887 - Store Rooted heads on the Zone; r=sfink (91c0101ee3) - Bug 1266402 - Add iteration to EnumSet<T> so that it can be used in range-based for loops r=Waldo (e9507a2524) - Bug 1266404 - Allow construction of an EnumSet<T> using an initializer list r=Waldo (1b6d340e99) - Bug 1254020 - Always compute theme scaling factor when per-monitor dpi aware, even if only a single display is currently present. r=emk (a00cda21f4) - Bug 1263525 - Add dedicated function for std_Array self-hosted intrinsic. r=efaust (449d8bb7eb) - Bug 1255925 - Change JSFunction::name to return a JSAtom. r=efaust (5ab396ce83) - Bug 888969 - Make our tree's sole implementation of nsIRemoteTagService.getRemoteObjectTag not depend upon the infallibility of [[GetPrototypeOf]] on the object provided to it. r=bz (f388f4bf1f) - Bug 1264896 - Kill off nsIRemoteTagService and do what it does, in its sole caller, in far-faster C++. r=billm (5ed3fb103d) - Bug 1268246 - Add a simple Poison class lifetime checker. r=froydnj (7b237bc70e) - Bug 1249496 - Don't apply dpi-based scaling for window titlebar dimensions when on a secondary display, because windows doesn't scale it. r=emk (64dd706dbc) - Bug 1164518 - Avoid unnecessary DB updates when caching Safe Browsing results. r=gcp (3cafd9a4df) - Bug 1264472 - Use nsRunnables in FIDO U2F. r=keeler (3aa9570132) - Bug 1236060 - Dispatch error should advance queue. r=smaug (74155b75dd) - Bug 1251697 part 1. Thread an ErrorResult reference through the worker XHR WorkerThreadProxySyncRunnable implementations. r=khuey (77804cbb7c) - Bug 1251697 part 2. Have WorkerThreadProxySyncRunnable hand the ErrorResult reference it holds to its ResponseRunnable so it can report exceptions on there instead of on a JSContext. r=khuey (355c9ee313) - Bug 1251697 part 3. Remove the JSContext argument of StopSyncLoopRunnable::MaybeSetException. r=khuey (010f5b1058) - Bug 1155328. r=smaug (e1f8dac304) - Bug 1265927: Move nsRunnable to mozilla::Runnable, CancelableRunnable to mozilla::CancelableRunnable. r=froydnj (f83bfcae02) - Bug 1239946 - Change test to return error on Speak. r=eeejay (1d402beb02) - Bug 1254378 - Update synth tests and introduce no voiceschanged test. r=smaug (f5823bb70e) - Bug 1251627. Fix XMLHttpRequest.send() to follow the spec better in terms of the exceptions it throws. r=khuey (cd0e321948) - Bug 1268868: [MSE] P1. Re-enable gap detection within a media segment. r=gerald (b8b8df4bc2) - Bug 1268868: [MSE] P2. Reset longest duration after keyframe is seen. r=gerald (2b1401465c) - Bug 1268868: [MSE] P3. Prevent crash should gap be detected in content. r=gerald (063d9376fc) - Bug 1254378 - Implement nsISynthVoiceRegistry.notifyVoicesChanged. r=smaug (4b63b1c360) - Bug 1266804 - Un-inline js::Unbox(); r=jorendorff (0f288b6173) - Bug 1268863 - Report ScriptSources that are only reachable via AsmJSModule (r=njn) (5ba40acb64) - bump version to 45.1b1 (1414db0ca8) - Bug 1262062 - remove old futex names. r=bbouvier (62662bdd2e) - memory: build fix after renaming MOZ_WARN_UNUSED_RESULT (7254dc8d53) - import from mozilla: - Bug 1268725 - BaldrMonkey: Refactor away the internal storage from ExprIter. r=luke (1931bd636f17) - Bug 1268725 - BaldrMonkey: Convert default arguments into explicit arguments. r=luke (c8a11b8b6bbd) (867ec715d6)
882 lines
23 KiB
C++
882 lines
23 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
// IWYU pragma: private, include "nsString.h"
|
|
|
|
/**
|
|
* This is the canonical null-terminated string class. All subclasses
|
|
* promise null-terminated storage. Instances of this class allocate
|
|
* strings on the heap.
|
|
*
|
|
* NAMES:
|
|
* nsString for wide characters
|
|
* nsCString for narrow characters
|
|
*
|
|
* This class is also known as nsAFlat[C]String, where "flat" is used
|
|
* to denote a null-terminated string.
|
|
*/
|
|
class nsTString_CharT : public nsTSubstring_CharT
|
|
{
|
|
public:
|
|
|
|
typedef nsTString_CharT self_type;
|
|
|
|
public:
|
|
|
|
/**
|
|
* constructors
|
|
*/
|
|
|
|
nsTString_CharT()
|
|
: substring_type()
|
|
{
|
|
}
|
|
|
|
explicit
|
|
nsTString_CharT(const char_type* aData, size_type aLength = size_type(-1))
|
|
: substring_type()
|
|
{
|
|
Assign(aData, aLength);
|
|
}
|
|
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
explicit
|
|
nsTString_CharT(char16ptr_t aStr, size_type aLength = size_type(-1))
|
|
: substring_type()
|
|
{
|
|
Assign(static_cast<const char16_t*>(aStr), aLength);
|
|
}
|
|
#endif
|
|
|
|
nsTString_CharT(const self_type& aStr)
|
|
: substring_type()
|
|
{
|
|
Assign(aStr);
|
|
}
|
|
|
|
MOZ_IMPLICIT nsTString_CharT(const substring_tuple_type& aTuple)
|
|
: substring_type()
|
|
{
|
|
Assign(aTuple);
|
|
}
|
|
|
|
explicit
|
|
nsTString_CharT(const substring_type& aReadable)
|
|
: substring_type()
|
|
{
|
|
Assign(aReadable);
|
|
}
|
|
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
|
self_type& operator=(char_type aChar)
|
|
{
|
|
Assign(aChar);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const char_type* aData)
|
|
{
|
|
Assign(aData);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const self_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
self_type& operator=(const char16ptr_t aStr)
|
|
{
|
|
Assign(static_cast<const char16_t*>(aStr));
|
|
return *this;
|
|
}
|
|
#endif
|
|
self_type& operator=(const substring_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
{
|
|
Assign(aTuple);
|
|
return *this;
|
|
}
|
|
|
|
/**
|
|
* returns the null-terminated string
|
|
*/
|
|
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
char16ptr_t get() const
|
|
#else
|
|
const char_type* get() const
|
|
#endif
|
|
{
|
|
return mData;
|
|
}
|
|
|
|
|
|
/**
|
|
* returns character at specified index.
|
|
*
|
|
* NOTE: unlike nsTSubstring::CharAt, this function allows you to index
|
|
* the null terminator character.
|
|
*/
|
|
|
|
char_type CharAt(index_type aIndex) const
|
|
{
|
|
NS_ASSERTION(aIndex <= mLength, "index exceeds allowable range");
|
|
return mData[aIndex];
|
|
}
|
|
|
|
char_type operator[](index_type aIndex) const
|
|
{
|
|
return CharAt(aIndex);
|
|
}
|
|
|
|
|
|
#if MOZ_STRING_WITH_OBSOLETE_API
|
|
|
|
|
|
/**
|
|
* Search for the given substring within this string.
|
|
*
|
|
* @param aString is substring to be sought in this
|
|
* @param aIgnoreCase selects case sensitivity
|
|
* @param aOffset tells us where in this string to start searching
|
|
* @param aCount tells us how far from the offset we are to search. Use
|
|
* -1 to search the whole string.
|
|
* @return offset in string, or kNotFound
|
|
*/
|
|
|
|
int32_t Find(const nsCString& aString, bool aIgnoreCase = false,
|
|
int32_t aOffset = 0, int32_t aCount = -1) const;
|
|
int32_t Find(const char* aString, bool aIgnoreCase = false,
|
|
int32_t aOffset = 0, int32_t aCount = -1) const;
|
|
|
|
#ifdef CharT_is_PRUnichar
|
|
int32_t Find(const nsAFlatString& aString, int32_t aOffset = 0,
|
|
int32_t aCount = -1) const;
|
|
int32_t Find(const char16_t* aString, int32_t aOffset = 0,
|
|
int32_t aCount = -1) const;
|
|
#ifdef MOZ_USE_CHAR16_WRAPPER
|
|
int32_t Find(char16ptr_t aString, int32_t aOffset = 0,
|
|
int32_t aCount = -1) const
|
|
{
|
|
return Find(static_cast<const char16_t*>(aString), aOffset, aCount);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
/**
|
|
* This methods scans the string backwards, looking for the given string
|
|
*
|
|
* @param aString is substring to be sought in this
|
|
* @param aIgnoreCase tells us whether or not to do caseless compare
|
|
* @param aOffset tells us where in this string to start searching.
|
|
* Use -1 to search from the end of the string.
|
|
* @param aCount tells us how many iterations to make starting at the
|
|
* given offset.
|
|
* @return offset in string, or kNotFound
|
|
*/
|
|
|
|
int32_t RFind(const nsCString& aString, bool aIgnoreCase = false,
|
|
int32_t aOffset = -1, int32_t aCount = -1) const;
|
|
int32_t RFind(const char* aCString, bool aIgnoreCase = false,
|
|
int32_t aOffset = -1, int32_t aCount = -1) const;
|
|
|
|
#ifdef CharT_is_PRUnichar
|
|
int32_t RFind(const nsAFlatString& aString, int32_t aOffset = -1,
|
|
int32_t aCount = -1) const;
|
|
int32_t RFind(const char16_t* aString, int32_t aOffset = -1,
|
|
int32_t aCount = -1) const;
|
|
#endif
|
|
|
|
|
|
/**
|
|
* Search for given char within this string
|
|
*
|
|
* @param aChar is the character to search for
|
|
* @param aOffset tells us where in this string to start searching
|
|
* @param aCount tells us how far from the offset we are to search.
|
|
* Use -1 to search the whole string.
|
|
* @return offset in string, or kNotFound
|
|
*/
|
|
|
|
// int32_t FindChar( char16_t aChar, int32_t aOffset=0, int32_t aCount=-1 ) const;
|
|
int32_t RFindChar(char16_t aChar, int32_t aOffset = -1,
|
|
int32_t aCount = -1) const;
|
|
|
|
|
|
/**
|
|
* This method searches this string for the first character found in
|
|
* the given string.
|
|
*
|
|
* @param aString contains set of chars to be found
|
|
* @param aOffset tells us where in this string to start searching
|
|
* (counting from left)
|
|
* @return offset in string, or kNotFound
|
|
*/
|
|
|
|
int32_t FindCharInSet(const char* aString, int32_t aOffset = 0) const;
|
|
int32_t FindCharInSet(const self_type& aString, int32_t aOffset = 0) const
|
|
{
|
|
return FindCharInSet(aString.get(), aOffset);
|
|
}
|
|
|
|
#ifdef CharT_is_PRUnichar
|
|
int32_t FindCharInSet(const char16_t* aString, int32_t aOffset = 0) const;
|
|
#endif
|
|
|
|
|
|
/**
|
|
* This method searches this string for the last character found in
|
|
* the given string.
|
|
*
|
|
* @param aString contains set of chars to be found
|
|
* @param aOffset tells us where in this string to start searching
|
|
* (counting from left)
|
|
* @return offset in string, or kNotFound
|
|
*/
|
|
|
|
int32_t RFindCharInSet(const char_type* aString, int32_t aOffset = -1) const;
|
|
int32_t RFindCharInSet(const self_type& aString, int32_t aOffset = -1) const
|
|
{
|
|
return RFindCharInSet(aString.get(), aOffset);
|
|
}
|
|
|
|
|
|
/**
|
|
* Compares a given string to this string.
|
|
*
|
|
* @param aString is the string to be compared
|
|
* @param aIgnoreCase tells us how to treat case
|
|
* @param aCount tells us how many chars to compare
|
|
* @return -1,0,1
|
|
*/
|
|
|
|
#ifdef CharT_is_char
|
|
int32_t Compare(const char* aString, bool aIgnoreCase = false,
|
|
int32_t aCount = -1) const;
|
|
#endif
|
|
|
|
|
|
/**
|
|
* Equality check between given string and this string.
|
|
*
|
|
* @param aString is the string to check
|
|
* @param aIgnoreCase tells us how to treat case
|
|
* @param aCount tells us how many chars to compare
|
|
* @return boolean
|
|
*/
|
|
#ifdef CharT_is_char
|
|
bool EqualsIgnoreCase(const char* aString, int32_t aCount = -1) const
|
|
{
|
|
return Compare(aString, true, aCount) == 0;
|
|
}
|
|
#else
|
|
bool EqualsIgnoreCase(const char* aString, int32_t aCount = -1) const;
|
|
|
|
|
|
#endif // !CharT_is_PRUnichar
|
|
|
|
/**
|
|
* Perform string to double-precision float conversion.
|
|
*
|
|
* @param aErrorCode will contain error if one occurs
|
|
* @return double-precision float rep of string value
|
|
*/
|
|
double ToDouble(nsresult* aErrorCode) const;
|
|
|
|
/**
|
|
* Perform string to single-precision float conversion.
|
|
*
|
|
* @param aErrorCode will contain error if one occurs
|
|
* @return single-precision float rep of string value
|
|
*/
|
|
float ToFloat(nsresult* aErrorCode) const
|
|
{
|
|
return (float)ToDouble(aErrorCode);
|
|
}
|
|
|
|
|
|
/**
|
|
* Perform string to int conversion.
|
|
* @param aErrorCode will contain error if one occurs
|
|
* @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
|
|
* @return int rep of string value, and possible (out) error code
|
|
*/
|
|
int32_t ToInteger(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
|
|
|
|
/**
|
|
* Perform string to 64-bit int conversion.
|
|
* @param aErrorCode will contain error if one occurs
|
|
* @param aRadix tells us which radix to assume; kAutoDetect tells us to determine the radix for you.
|
|
* @return 64-bit int rep of string value, and possible (out) error code
|
|
*/
|
|
int64_t ToInteger64(nsresult* aErrorCode, uint32_t aRadix = kRadix10) const;
|
|
|
|
|
|
/**
|
|
* |Left|, |Mid|, and |Right| are annoying signatures that seem better almost
|
|
* any _other_ way than they are now. Consider these alternatives
|
|
*
|
|
* aWritable = aReadable.Left(17); // ...a member function that returns a |Substring|
|
|
* aWritable = Left(aReadable, 17); // ...a global function that returns a |Substring|
|
|
* Left(aReadable, 17, aWritable); // ...a global function that does the assignment
|
|
*
|
|
* as opposed to the current signature
|
|
*
|
|
* aReadable.Left(aWritable, 17); // ...a member function that does the assignment
|
|
*
|
|
* or maybe just stamping them out in favor of |Substring|, they are just duplicate functionality
|
|
*
|
|
* aWritable = Substring(aReadable, 0, 17);
|
|
*/
|
|
|
|
size_type Mid(self_type& aResult, uint32_t aStartPos, uint32_t aCount) const;
|
|
|
|
size_type Left(self_type& aResult, size_type aCount) const
|
|
{
|
|
return Mid(aResult, 0, aCount);
|
|
}
|
|
|
|
size_type Right(self_type& aResult, size_type aCount) const
|
|
{
|
|
aCount = XPCOM_MIN(mLength, aCount);
|
|
return Mid(aResult, mLength - aCount, aCount);
|
|
}
|
|
|
|
|
|
/**
|
|
* Set a char inside this string at given index
|
|
*
|
|
* @param aChar is the char you want to write into this string
|
|
* @param anIndex is the ofs where you want to write the given char
|
|
* @return TRUE if successful
|
|
*/
|
|
|
|
bool SetCharAt(char16_t aChar, uint32_t aIndex);
|
|
|
|
|
|
/**
|
|
* These methods are used to remove all occurrences of the
|
|
* characters found in aSet from this string.
|
|
*
|
|
* @param aSet -- characters to be cut from this
|
|
*/
|
|
void StripChars(const char* aSet);
|
|
|
|
|
|
/**
|
|
* This method strips whitespace throughout the string.
|
|
*/
|
|
void StripWhitespace();
|
|
|
|
|
|
/**
|
|
* swaps occurence of 1 string for another
|
|
*/
|
|
|
|
void ReplaceChar(char_type aOldChar, char_type aNewChar);
|
|
void ReplaceChar(const char* aSet, char_type aNewChar);
|
|
#ifdef CharT_is_PRUnichar
|
|
void ReplaceChar(const char16_t* aSet, char16_t aNewChar);
|
|
#endif
|
|
/**
|
|
* Replace all occurrences of aTarget with aNewValue.
|
|
* The complexity of this function is O(n+m), n being the length of the string
|
|
* and m being the length of aNewValue.
|
|
*/
|
|
void ReplaceSubstring(const self_type& aTarget, const self_type& aNewValue);
|
|
void ReplaceSubstring(const char_type* aTarget, const char_type* aNewValue);
|
|
MOZ_MUST_USE bool ReplaceSubstring(const self_type& aTarget,
|
|
const self_type& aNewValue,
|
|
const fallible_t&);
|
|
MOZ_MUST_USE bool ReplaceSubstring(const char_type* aTarget,
|
|
const char_type* aNewValue,
|
|
const fallible_t&);
|
|
|
|
|
|
/**
|
|
* This method trims characters found in aTrimSet from
|
|
* either end of the underlying string.
|
|
*
|
|
* @param aSet -- contains chars to be trimmed from both ends
|
|
* @param aEliminateLeading
|
|
* @param aEliminateTrailing
|
|
* @param aIgnoreQuotes -- if true, causes surrounding quotes to be ignored
|
|
* @return this
|
|
*/
|
|
void Trim(const char* aSet, bool aEliminateLeading = true,
|
|
bool aEliminateTrailing = true, bool aIgnoreQuotes = false);
|
|
|
|
/**
|
|
* This method strips whitespace from string.
|
|
* You can control whether whitespace is yanked from start and end of
|
|
* string as well.
|
|
*
|
|
* @param aEliminateLeading controls stripping of leading ws
|
|
* @param aEliminateTrailing controls stripping of trailing ws
|
|
*/
|
|
void CompressWhitespace(bool aEliminateLeading = true,
|
|
bool aEliminateTrailing = true);
|
|
|
|
|
|
/**
|
|
* assign/append/insert with _LOSSY_ conversion
|
|
*/
|
|
|
|
void AssignWithConversion(const nsTAString_IncompatibleCharT& aString);
|
|
void AssignWithConversion(const incompatible_char_type* aData,
|
|
int32_t aLength = -1);
|
|
|
|
#endif // !MOZ_STRING_WITH_OBSOLETE_API
|
|
|
|
/**
|
|
* Allow this string to be bound to a character buffer
|
|
* until the string is rebound or mutated; the caller
|
|
* must ensure that the buffer outlives the string.
|
|
*/
|
|
void Rebind(const char_type* aData, size_type aLength);
|
|
|
|
/**
|
|
* verify restrictions for dependent strings
|
|
*/
|
|
void AssertValidDependentString()
|
|
{
|
|
NS_ASSERTION(mData, "nsTDependentString must wrap a non-NULL buffer");
|
|
NS_ASSERTION(mLength != size_type(-1), "nsTDependentString has bogus length");
|
|
NS_ASSERTION(mData[mLength] == 0,
|
|
"nsTDependentString must wrap only null-terminated strings. "
|
|
"You are probably looking for nsTDependentSubstring.");
|
|
}
|
|
|
|
|
|
protected:
|
|
|
|
explicit
|
|
nsTString_CharT(uint32_t aFlags)
|
|
: substring_type(aFlags)
|
|
{
|
|
}
|
|
|
|
// allow subclasses to initialize fields directly
|
|
nsTString_CharT(char_type* aData, size_type aLength, uint32_t aFlags)
|
|
: substring_type(aData, aLength, aFlags)
|
|
{
|
|
}
|
|
|
|
struct Segment {
|
|
uint32_t mBegin, mLength;
|
|
Segment(uint32_t aBegin, uint32_t aLength)
|
|
: mBegin(aBegin)
|
|
, mLength(aLength)
|
|
{}
|
|
};
|
|
};
|
|
|
|
|
|
class nsTFixedString_CharT : public nsTString_CharT
|
|
{
|
|
public:
|
|
|
|
typedef nsTFixedString_CharT self_type;
|
|
typedef nsTFixedString_CharT fixed_string_type;
|
|
|
|
public:
|
|
|
|
/**
|
|
* @param aData
|
|
* fixed-size buffer to be used by the string (the contents of
|
|
* this buffer may be modified by the string)
|
|
* @param aStorageSize
|
|
* the size of the fixed buffer
|
|
* @param aLength (optional)
|
|
* the length of the string already contained in the buffer
|
|
*/
|
|
|
|
nsTFixedString_CharT(char_type* aData, size_type aStorageSize)
|
|
: string_type(aData, uint32_t(char_traits::length(aData)),
|
|
F_TERMINATED | F_FIXED | F_CLASS_FIXED)
|
|
, mFixedCapacity(aStorageSize - 1)
|
|
, mFixedBuf(aData)
|
|
{
|
|
}
|
|
|
|
nsTFixedString_CharT(char_type* aData, size_type aStorageSize,
|
|
size_type aLength)
|
|
: string_type(aData, aLength, F_TERMINATED | F_FIXED | F_CLASS_FIXED)
|
|
, mFixedCapacity(aStorageSize - 1)
|
|
, mFixedBuf(aData)
|
|
{
|
|
// null-terminate
|
|
mFixedBuf[aLength] = char_type(0);
|
|
}
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
|
self_type& operator=(char_type aChar)
|
|
{
|
|
Assign(aChar);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const char_type* aData)
|
|
{
|
|
Assign(aData);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
{
|
|
Assign(aTuple);
|
|
return *this;
|
|
}
|
|
|
|
protected:
|
|
|
|
friend class nsTSubstring_CharT;
|
|
|
|
size_type mFixedCapacity;
|
|
char_type* mFixedBuf;
|
|
};
|
|
|
|
|
|
/**
|
|
* nsTAutoString_CharT
|
|
*
|
|
* Subclass of nsTString_CharT that adds support for stack-based string
|
|
* allocation. It is normally not a good idea to use this class on the
|
|
* heap, because it will allocate space which may be wasted if the string
|
|
* it contains is significantly smaller or any larger than 64 characters.
|
|
*
|
|
* NAMES:
|
|
* nsAutoString for wide characters
|
|
* nsAutoCString for narrow characters
|
|
*/
|
|
class MOZ_NON_MEMMOVABLE nsTAutoString_CharT : public nsTFixedString_CharT
|
|
{
|
|
public:
|
|
|
|
typedef nsTAutoString_CharT self_type;
|
|
|
|
public:
|
|
|
|
/**
|
|
* constructors
|
|
*/
|
|
|
|
nsTAutoString_CharT()
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
}
|
|
|
|
explicit
|
|
nsTAutoString_CharT(char_type aChar)
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
Assign(aChar);
|
|
}
|
|
|
|
explicit
|
|
nsTAutoString_CharT(const char_type* aData, size_type aLength = size_type(-1))
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
Assign(aData, aLength);
|
|
}
|
|
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
explicit
|
|
nsTAutoString_CharT(char16ptr_t aData, size_type aLength = size_type(-1))
|
|
: nsTAutoString_CharT(static_cast<const char16_t*>(aData), aLength)
|
|
{
|
|
}
|
|
#endif
|
|
|
|
nsTAutoString_CharT(const self_type& aStr)
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
Assign(aStr);
|
|
}
|
|
|
|
explicit
|
|
nsTAutoString_CharT(const substring_type& aStr)
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
Assign(aStr);
|
|
}
|
|
|
|
MOZ_IMPLICIT nsTAutoString_CharT(const substring_tuple_type& aTuple)
|
|
: fixed_string_type(mStorage, kDefaultStorageSize, 0)
|
|
{
|
|
Assign(aTuple);
|
|
}
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
|
self_type& operator=(char_type aChar)
|
|
{
|
|
Assign(aChar);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const char_type* aData)
|
|
{
|
|
Assign(aData);
|
|
return *this;
|
|
}
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
self_type& operator=(char16ptr_t aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
#endif
|
|
self_type& operator=(const self_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
{
|
|
Assign(aTuple);
|
|
return *this;
|
|
}
|
|
|
|
enum
|
|
{
|
|
kDefaultStorageSize = 64
|
|
};
|
|
|
|
private:
|
|
|
|
char_type mStorage[kDefaultStorageSize];
|
|
};
|
|
|
|
|
|
//
|
|
// nsAutoString stores pointers into itself which are invalidated when an
|
|
// nsTArray is resized, so nsTArray must not be instantiated with nsAutoString
|
|
// elements!
|
|
//
|
|
template<class E> class nsTArrayElementTraits;
|
|
template<>
|
|
class nsTArrayElementTraits<nsTAutoString_CharT>
|
|
{
|
|
public:
|
|
template<class A> struct Dont_Instantiate_nsTArray_of;
|
|
template<class A> struct Instead_Use_nsTArray_of;
|
|
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT>*
|
|
Construct(Instead_Use_nsTArray_of<nsTString_CharT>* aE)
|
|
{
|
|
return 0;
|
|
}
|
|
template<class A>
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT>*
|
|
Construct(Instead_Use_nsTArray_of<nsTString_CharT>* aE, const A& aArg)
|
|
{
|
|
return 0;
|
|
}
|
|
static Dont_Instantiate_nsTArray_of<nsTAutoString_CharT>*
|
|
Destruct(Instead_Use_nsTArray_of<nsTString_CharT>* aE)
|
|
{
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* nsTXPIDLString extends nsTString such that:
|
|
*
|
|
* (1) mData can be null
|
|
* (2) objects of this type can be automatically cast to |const CharT*|
|
|
* (3) getter_Copies method is supported to adopt data allocated with
|
|
* NS_Alloc, such as "out string" parameters in XPIDL.
|
|
*
|
|
* NAMES:
|
|
* nsXPIDLString for wide characters
|
|
* nsXPIDLCString for narrow characters
|
|
*/
|
|
class nsTXPIDLString_CharT : public nsTString_CharT
|
|
{
|
|
public:
|
|
|
|
typedef nsTXPIDLString_CharT self_type;
|
|
|
|
public:
|
|
|
|
nsTXPIDLString_CharT()
|
|
: string_type(char_traits::sEmptyBuffer, 0, F_TERMINATED | F_VOIDED)
|
|
{
|
|
}
|
|
|
|
// copy-constructor required to avoid default
|
|
nsTXPIDLString_CharT(const self_type& aStr)
|
|
: string_type(char_traits::sEmptyBuffer, 0, F_TERMINATED | F_VOIDED)
|
|
{
|
|
Assign(aStr);
|
|
}
|
|
|
|
// return nullptr if we are voided
|
|
#if defined(CharT_is_PRUnichar) && defined(MOZ_USE_CHAR16_WRAPPER)
|
|
char16ptr_t get() const
|
|
#else
|
|
const char_type* get() const
|
|
#endif
|
|
{
|
|
return (mFlags & F_VOIDED) ? nullptr : mData;
|
|
}
|
|
|
|
// this case operator is the reason why this class cannot just be a
|
|
// typedef for nsTString
|
|
operator const char_type*() const
|
|
{
|
|
return get();
|
|
}
|
|
|
|
// need this to diambiguous operator[int]
|
|
char_type operator[](int32_t aIndex) const
|
|
{
|
|
return CharAt(index_type(aIndex));
|
|
}
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
|
self_type& operator=(char_type aChar)
|
|
{
|
|
Assign(aChar);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const char_type* aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const self_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
{
|
|
Assign(aTuple);
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* getter_Copies support for use with raw string out params:
|
|
*
|
|
* NS_IMETHOD GetBlah(char**);
|
|
*
|
|
* void some_function()
|
|
* {
|
|
* nsXPIDLCString blah;
|
|
* GetBlah(getter_Copies(blah));
|
|
* // ...
|
|
* }
|
|
*/
|
|
class MOZ_STACK_CLASS nsTGetterCopies_CharT
|
|
{
|
|
public:
|
|
typedef CharT char_type;
|
|
|
|
explicit nsTGetterCopies_CharT(nsTSubstring_CharT& aStr)
|
|
: mString(aStr)
|
|
, mData(nullptr)
|
|
{
|
|
}
|
|
|
|
~nsTGetterCopies_CharT()
|
|
{
|
|
mString.Adopt(mData); // OK if mData is null
|
|
}
|
|
|
|
operator char_type**()
|
|
{
|
|
return &mData;
|
|
}
|
|
|
|
private:
|
|
nsTSubstring_CharT& mString;
|
|
char_type* mData;
|
|
};
|
|
|
|
inline nsTGetterCopies_CharT
|
|
getter_Copies(nsTSubstring_CharT& aString)
|
|
{
|
|
return nsTGetterCopies_CharT(aString);
|
|
}
|
|
|
|
|
|
/**
|
|
* nsTAdoptingString extends nsTXPIDLString such that:
|
|
*
|
|
* (1) Adopt given string on construction or assignment, i.e. take
|
|
* the value of what's given, and make what's given forget its
|
|
* value. Note that this class violates constness in a few
|
|
* places. Be careful!
|
|
*/
|
|
class nsTAdoptingString_CharT : public nsTXPIDLString_CharT
|
|
{
|
|
public:
|
|
|
|
typedef nsTAdoptingString_CharT self_type;
|
|
|
|
public:
|
|
|
|
explicit nsTAdoptingString_CharT()
|
|
{
|
|
}
|
|
explicit nsTAdoptingString_CharT(char_type* aStr,
|
|
size_type aLength = size_type(-1))
|
|
{
|
|
Adopt(aStr, aLength);
|
|
}
|
|
|
|
// copy-constructor required to adopt on copy. Note that this
|
|
// will violate the constness of |aStr| in the operator=()
|
|
// call. |aStr| will be truncated as a side-effect of this
|
|
// constructor.
|
|
nsTAdoptingString_CharT(const self_type& aStr)
|
|
{
|
|
*this = aStr;
|
|
}
|
|
|
|
// |operator=| does not inherit, so we must define our own
|
|
self_type& operator=(const substring_type& aStr)
|
|
{
|
|
Assign(aStr);
|
|
return *this;
|
|
}
|
|
self_type& operator=(const substring_tuple_type& aTuple)
|
|
{
|
|
Assign(aTuple);
|
|
return *this;
|
|
}
|
|
|
|
// Adopt(), if possible, when assigning to a self_type&. Note
|
|
// that this violates the constness of aStr, aStr is always
|
|
// truncated when this operator is called.
|
|
self_type& operator=(const self_type& aStr);
|
|
|
|
private:
|
|
self_type& operator=(const char_type* aData) = delete;
|
|
self_type& operator=(char_type* aData) = delete;
|
|
};
|
|
|