27 #ifndef __SBSTRINGUTILS_H__
28 #define __SBSTRINGUTILS_H__
30 #include <nsStringAPI.h>
45 AssignLiteral(aValue);
52 PR_snprintf(valueStr,
sizeof(valueStr),
"%d", aValue);
53 AssignLiteral(valueStr);
57 PRBool aHex = PR_FALSE,
58 PRBool aHexPrefix = PR_TRUE)
63 PR_snprintf(valueStr,
sizeof(valueStr),
"%lu",
long(aValue));
67 PR_snprintf(valueStr,
sizeof(valueStr),
"0x%lx",
long(aValue));
70 PR_snprintf(valueStr,
sizeof(valueStr),
"%lx",
long(aValue));
74 AssignLiteral(valueStr);
81 PR_snprintf(valueStr,
sizeof(valueStr),
"%lld", aValue);
82 AssignLiteral(valueStr);
89 PR_snprintf(valueStr,
sizeof(valueStr),
"%llu", aValue);
90 AssignLiteral(valueStr);
95 char idString[NSID_LENGTH];
96 aValue->ToProvidedString(idString);
97 AssignLiteral(idString);
109 AssignLiteral(aValue);
116 PR_snprintf(valueStr,
sizeof(valueStr),
"%d", aValue);
117 AssignLiteral(valueStr);
121 PRBool aHex = PR_FALSE,
122 PRBool aHexPrefix = PR_TRUE)
127 PR_snprintf(valueStr,
sizeof(valueStr),
"%lu",
long(aValue));
131 PR_snprintf(valueStr,
sizeof(valueStr),
"0x%lx",
long(aValue));
134 PR_snprintf(valueStr,
sizeof(valueStr),
"%lx",
long(aValue));
138 AssignLiteral(valueStr);
145 PR_snprintf(valueStr,
sizeof(valueStr),
"%lld", aValue);
146 AssignLiteral(valueStr);
153 PR_snprintf(valueStr,
sizeof(valueStr),
"%llu", aValue);
154 AssignLiteral(valueStr);
159 char idString[NSID_LENGTH];
160 aValue->ToProvidedString(idString);
161 AssignLiteral(idString);
194 const char *aPattern,
195 PRInt32 aOffset = 0);
214 PRBool aLeading = PR_TRUE,
215 PRBool aTrailing = PR_TRUE);
227 const nsAString& aOldChars,
228 const PRUnichar aNewChar);
232 const nsACString& aOldChars,
233 const char aNewChar);
241 const nsAString &aOldString,
242 const nsAString &aNewString);
260 PRBool
IsUTF8(
const nsACString& aString);
272 const nsAString& aDelimiter,
273 nsTArray<nsString>& aSubStringArray);
285 const nsACString& aDelimiter,
286 nsTArray<nsCString>& aSubStringArray);
308 #define SB_STRING_BUNDLE_URL "chrome://songbird/locale/songbird.properties"
324 const nsAString& aKey,
325 const nsAString& aDefault,
326 class nsIStringBundle* aStringBundle = nsnull);
329 const nsAString& aKey);
333 const char* aDefault = nsnull,
334 class nsIStringBundle* aStringBundle = nsnull);
337 const nsAString& aKey,
338 const nsTArray<nsString>& aParams,
339 const nsAString& aDefault,
340 class nsIStringBundle* aStringBundle);
351 const nsAString& aDefault,
352 class nsIStringBundle* aStringBundle = nsnull)
354 nsString stringValue;
361 nsString stringValue;
367 const char* aDefault = nsnull,
368 class nsIStringBundle* aStringBundle = nsnull)
370 nsString stringValue;
376 const nsTArray<nsString>& aParams,
377 const char* aDefault = nsnull,
378 class nsIStringBundle* aStringBundle = nsnull)
382 key.AssignLiteral(aKey);
385 _default.AssignLiteral(aDefault);
387 _default.SetIsVoid(PR_TRUE);
390 nsString stringValue;
400 const nsTArray<nsString>& aParams,
401 const nsAString& aDefault,
402 class nsIStringBundle* aStringBundle = nsnull)
404 nsString stringValue;
421 template <
class S,
class Sep,
class T,
class E>
424 Sep
const & aSeparator,
425 T
const & aStringArray,
429 PRUint32
const separatorLength = aSeparator.Length();
430 PRUint32
const stringLength = aTarget.Length();
431 PRUint32
const length = aStringArray.Length();
435 PRUint32 finalLength = stringLength + (separatorLength * (aStringArray.Length() - 1));
436 for (PRUint32 index = 0; index < length; ++index) {
437 finalLength += aStringArray[index].Length();
439 typename S::char_type
const *
const separator = aSeparator.BeginReading();
441 typename S::char_type * writePosition;
442 typename S::char_type * endPosition;
443 aTarget.BeginWriting(&writePosition, &endPosition, finalLength);
446 writePosition += stringLength;
448 PRBool
const isSeparatorEmpty = aSeparator.IsEmpty();
449 for (PRUint32 index = 0; index < length; ++index) {
450 if (index != 0 && !isSeparatorEmpty) {
451 memcpy(writePosition, separator, separatorLength *
sizeof(
typename S::char_type));
452 writePosition += separatorLength;
454 S
const &
value = aExtractor(aStringArray[index]);
455 memcpy(writePosition,
456 value.BeginReading(),
457 value.Length() *
sizeof(
typename S::char_type));
458 writePosition += value.Length();
463 template <
class S,
class Sep,
class T>
466 Sep
const & aSeparator,
467 T
const & aStringArray)
469 return sbAppendStringArray(aTarget, aSeparator, aStringArray, sbAppendStringArrayDefaultExtractor<S>);
486 template <
class StringType,
class EnumeratorType>
489 EnumeratorType* aEnumerator)
491 NS_ENSURE_ARG_POINTER(aEnumerator);
498 rv = aEnumerator->HasMore(&hasMore);
499 NS_ENSURE_SUCCESS(rv, rv);
504 typename StringType::elem_type stringElement;
505 rv = aEnumerator->GetNext(stringElement);
506 NS_ENSURE_SUCCESS(rv, rv);
507 NS_ENSURE_TRUE(aStringArray.AppendElement(stringElement),
508 NS_ERROR_OUT_OF_MEMORY);
531 typename T::char_type
const * src;
532 typename T::char_type
const * srcEnd;
533 aSrc.BeginReading(&src, &srcEnd);
535 typename T::char_type * destStart;
536 typename T::char_type * destEnd;
537 result.BeginWriting(&destStart, &destEnd, (aSrc.Length() * 6 + 1));
538 typename T::char_type * dest = destStart;
540 while (src != srcEnd) {
541 const char c = *src++;
584 result.SetLength(dest - destStart);
sbAutoString(nsID *aValue)
sbCAutoString(nsID *aValue)
SBLocalizedString(const nsAString &aKey)
void SB_CompressWhitespace(nsAString &aString, PRBool aLeading=PR_TRUE, PRBool aTrailing=PR_TRUE)
SBLocalizedString(const char *aKey, const char *aDefault=nsnull, class nsIStringBundle *aStringBundle=nsnull)
void AppendInt(nsAString &str, PRUint64 val)
S sbAppendStringArray(S &aTarget, Sep const &aSeparator, T const &aStringArray, E aExtractor)
sbCAutoString(int aValue)
sbAutoString(PRUint64 aValue)
SBLocalizedString(const nsAString &aKey, const nsTArray< nsString > &aParams, const nsAString &aDefault, class nsIStringBundle *aStringBundle=nsnull)
void nsString_ReplaceChar(nsAString &aString, const nsAString &aOldChars, const PRUnichar aNewChar)
SBLocalizedString(const char *aKey, const nsTArray< nsString > &aParams, const char *aDefault=nsnull, class nsIStringBundle *aStringBundle=nsnull)
PRInt32 nsString_FindCharInSet(const nsAString &aString, const char *aPattern, PRInt32 aOffset=0)
PRBool IsUTF8(const nsACString &aString)
nsString SB_FormatISO8601TimeString(PRTime aTime)
void nsCString_Split(const nsACString &aString, const nsACString &aDelimiter, nsTArray< nsCString > &aSubStringArray)
void nsString_ReplaceSubstring(nsAString &aString, const nsAString &aOldString, const nsAString &aNewString)
sbAutoString(const char *aValue)
nsresult SBGetLocalizedString(nsAString &aString, const nsAString &aKey, const nsAString &aDefault, class nsIStringBundle *aStringBundle=nsnull)
SBLocalizedString(const nsAString &aKey, const nsAString &aDefault, class nsIStringBundle *aStringBundle=nsnull)
void nsCString_ReplaceChars(nsACString &aOldString, const nsACString &aOldChars, const char aNewChar)
SB_AUTO_NULL_CLASS(sbAutoSmprintf, char *, PR_smprintf_free(mValue))
sbCAutoString(PRUint64 aValue)
this _dialogInput val(dateText)
nsresult sbAppendStringEnumerator(StringType &aStringArray, EnumeratorType *aEnumerator)
PRUint64 nsString_ToUint64(const nsAString &str, nsresult *rv=nsnull)
StringArrayEnumerator prototype hasMore
void nsString_Split(const nsAString &aString, const nsAString &aDelimiter, nsTArray< nsString > &aSubStringArray)
sbAutoString(PRInt64 aValue)
nsresult SB_ParseISO8601TimeString(const nsAString &aISO8601TimeString, PRTime *aTime)
T sbEscapeXML(T const &aSrc)
sbAutoString(PRUint32 aValue, PRBool aHex=PR_FALSE, PRBool aHexPrefix=PR_TRUE)
sbCAutoString(PRUint32 aValue, PRBool aHex=PR_FALSE, PRBool aHexPrefix=PR_TRUE)
sbCAutoString(const char *aValue)
T const & sbAppendStringArrayDefaultExtractor(T const &aArrayItem)
nsresult SB_StringEnumeratorEquals(nsIStringEnumerator *aLeft, nsIStringEnumerator *aRight, PRBool *_retval)
PRInt64 nsString_ToInt64(const nsAString &str, nsresult *rv=nsnull)
nsresult SBGetLocalizedFormattedString(nsAString &aString, const nsAString &aKey, const nsTArray< nsString > &aParams, const nsAString &aDefault, class nsIStringBundle *aStringBundle)
sbCAutoString(PRInt64 aValue)
PRBool IsLikelyUTF8(const nsACString &aString)