sbStringUtils.cpp File Reference
#include "sbStringUtils.h"
#include <prprf.h>
#include <nsDataHashtable.h>
#include <nsIStringBundle.h>
#include <nsIStringEnumerator.h>
#include <nsICharsetConverterManager.h>
#include <nsIUnicodeDecoder.h>
#include <nsServiceManagerUtils.h>
#include <sbIStringBundleService.h>
#include <sbMemoryUtils.h>
Include dependency graph for sbStringUtils.cpp:

Go to the source code of this file.

Functions

PRInt32 nsString_FindCharInSet (const nsAString &aString, const char *aPattern, PRInt32 aOffset)
 
void AppendInt (nsAString &str, PRUint64 val)
 
PRInt64 nsString_ToInt64 (const nsAString &str, nsresult *rv)
 
PRUint64 nsString_ToUint64 (const nsAString &str, nsresult *rv)
 
void SB_CompressWhitespace (nsAString &aString, PRBool aLeading, PRBool aTrailing)
 
nsresult SB_StringEnumeratorEquals (nsIStringEnumerator *aLeft, nsIStringEnumerator *aRight, PRBool *_retval)
 
void nsString_ReplaceChar (nsAString &aString, const nsAString &aOldChars, const PRUnichar aNewChar)
 
void nsCString_ReplaceChars (nsACString &aOldString, const nsACString &aOldChars, const char aNewChar)
 
void nsString_ReplaceSubstring (nsAString &aString, const nsAString &aOldString, const nsAString &aNewString)
 
PRBool IsLikelyUTF8 (const nsACString &aString)
 
PRBool IsUTF8 (const nsACString &aString)
 
void nsString_Split (const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
 
void nsCString_Split (const nsACString &aString, const nsACString &aDelimiter, nsTArray< nsCString > &aSubStringArray)
 
nsString SB_FormatISO8601TimeString (PRTime aTime)
 
nsresult SB_ParseISO8601TimeString (const nsAString &aISO8601TimeString, PRTime *aTime)
 
nsresult SBGetLocalizedString (nsAString &aString, const nsAString &aKey, const nsAString &aDefault, class nsIStringBundle *aStringBundle)
 
nsresult SBGetLocalizedString (nsAString &aString, const nsAString &aKey)
 
nsresult SBGetLocalizedString (nsAString &aString, const char *aKey, const char *aDefault, class nsIStringBundle *aStringBundle)
 
nsresult SBGetLocalizedFormattedString (nsAString &aString, const nsAString &aKey, const nsTArray< nsString > &aParams, const nsAString &aDefault, class nsIStringBundle *aStringBundle)
 

Function Documentation

void AppendInt ( nsAString &  str,
PRUint64  val 
)

Definition at line 58 of file sbStringUtils.cpp.

Here is the caller graph for this function:

PRBool IsLikelyUTF8 ( const nsACString &  aString)

Return true if the given string is possibly UTF8 (i.e. it errs on the side of returning true)

Note that it assumes all 7-bit encodings are utf8, and doesn't check for invalid characters (e.g. 0xFFFE, surrogates). This is a weaker check than the nsReadableUtils version.

Definition at line 274 of file sbStringUtils.cpp.

Here is the call graph for this function:

PRBool IsUTF8 ( const nsACString &  aString)

Returns true if the given string is UTF8

Note that this actually decodes the UTF8 string so it is significantly slower than IsLikelyUTF8.

Definition at line 328 of file sbStringUtils.cpp.

void nsCString_ReplaceChars ( nsACString &  aOldString,
const nsACString &  aOldChars,
const char  aNewChar 
)

Definition at line 239 of file sbStringUtils.cpp.

Here is the caller graph for this function:

void nsCString_Split ( const nsACString &  aString,
const nsACString &  aDelimiter,
nsTArray< nsCString > &  aSubStringArray 
)

Split the string specified by aString into sub-strings using the delimiter specified by aDelimiter and place the sub-strings in the array specified by aStringArray.

Parameters
aStringString to split.
aDelimiterSub-string delimiter.
aSubStringArrayArray of sub-strings.

Definition at line 394 of file sbStringUtils.cpp.

Here is the caller graph for this function:

PRInt32 nsString_FindCharInSet ( const nsAString &  aString,
const char *  aPattern,
PRInt32  aOffset = 0 
)
See Also
nsString::FindCharInSet

Definition at line 38 of file sbStringUtils.cpp.

void nsString_ReplaceChar ( nsAString &  aString,
const nsAString &  aOldChars,
const PRUnichar  aNewChar 
)

Searches a string for any occurences of any character of a set and replace them with a replacement character. Modifies the string in-place.

See Also
nsString_internal::ReplaceChar

Definition at line 225 of file sbStringUtils.cpp.

Here is the caller graph for this function:

void nsString_ReplaceSubstring ( nsAString &  aString,
const nsAString &  aOldString,
const nsAString &  aNewString 
)

Searches a string for any occurences of the substring and replaces it with the replacement string. Modifies the string in-place.

See Also
nsString_internal::ReplaceSubstring

Definition at line 252 of file sbStringUtils.cpp.

void nsString_Split ( const nsAString &  aString,
const nsAString &  aDelimiter,
nsTArray< nsString > &  aSubStringArray 
)

Split the string specified by aString into sub-strings using the delimiter specified by aDelimiter and place the sub-strings in the array specified by aStringArray.

Parameters
aStringString to split.
aDelimiterSub-string delimiter.
aSubStringArrayArray of sub-strings.

Definition at line 353 of file sbStringUtils.cpp.

Here is the caller graph for this function:

PRInt64 nsString_ToInt64 ( const nsAString &  str,
nsresult *  rv 
)

Definition at line 66 of file sbStringUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

PRUint64 nsString_ToUint64 ( const nsAString &  str,
nsresult *  rv 
)

Definition at line 91 of file sbStringUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void SB_CompressWhitespace ( nsAString &  aString,
PRBool  aLeading,
PRBool  aTrailing 
)

This is originated from CompressWhitespace in nsStringAPI, with modification. Make sure to update it when the upstream is changed.

Definition at line 120 of file sbStringUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

nsString SB_FormatISO8601TimeString ( PRTime  aTime)

Creates an ISO 8610 formatted time string from the aTime passed in

Parameters
aTimeThe time to create the formatted string
Returns
The time as an ISO 8601 formatted string

Definition at line 434 of file sbStringUtils.cpp.

nsresult SB_ParseISO8601TimeString ( const nsAString &  aISO8601TimeString,
PRTime *  aTime 
)

Parse the ISO 8601 formatted time string specified by aISO8601TimeString and return the time in aTime.

Parameters
aISO8601TimeStringISO 8601 formatted time string to parse.
aTimeReturned time.

Definition at line 444 of file sbStringUtils.cpp.

Here is the call graph for this function:

nsresult SB_StringEnumeratorEquals ( nsIStringEnumerator aLeft,
nsIStringEnumerator aRight,
PRBool *  _retval 
)

Definition at line 165 of file sbStringUtils.cpp.

nsresult SBGetLocalizedFormattedString ( nsAString &  aString,
const nsAString &  aKey,
const nsTArray< nsString > &  aParams,
const nsAString &  aDefault,
class nsIStringBundle *  aStringBundle 
)

Get and return in aString the formatted localized string with the key specified by aKey using the format parameters specified by aParams and the string bundle specified by aStringBundle. If the string cannot be found, return the default string specified by aDefault; if aDefault is void, return aKey. If aStringBundle is not specified, use the main Songbird string bundle.

Parameters
aStringReturned localized string.
aKeyLocalized string key.
aParamsFormat params array.
aDefaultOptional default string.
aStringBundleOptional string bundle.

Definition at line 593 of file sbStringUtils.cpp.

Here is the caller graph for this function:

nsresult SBGetLocalizedString ( nsAString &  aString,
const nsAString &  aKey,
const nsAString &  aDefault,
class nsIStringBundle *  aStringBundle 
)

Get and return in aString the localized string with the key specified by aKey using the string bundle specified by aStringBundle. If the string cannot be found, return the default string specified by aDefault; if aDefault is void, return aKey.

If aStringBundle is not specified, use the main Songbird string bundle.

Parameters
aStringReturned localized string.
aKeyLocalized string key.
aDefaultOptional default string.
aStringBundleOptional string bundle.

Definition at line 513 of file sbStringUtils.cpp.

Here is the caller graph for this function:

nsresult SBGetLocalizedString ( nsAString &  aString,
const nsAString &  aKey 
)

Definition at line 550 of file sbStringUtils.cpp.

Here is the call graph for this function:

nsresult SBGetLocalizedString ( nsAString &  aString,
const char *  aKey,
const char *  aDefault,
class nsIStringBundle *  aStringBundle 
)

Definition at line 557 of file sbStringUtils.cpp.

Here is the call graph for this function: