Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Private Attributes
nsStringBundle Class Reference

#include <nsStringBundle.h>

Inheritance diagram for nsStringBundle:
Inheritance graph
Collaboration diagram for nsStringBundle:
Collaboration graph

List of all members.

Public Member Functions

 nsStringBundle (const char *aURLSpec, nsIStringBundleOverride *)
nsresult LoadProperties ()
virtual ~nsStringBundle ()
wstring GetStringFromID (in long aID)
wstring GetStringFromName (in wstring aName)
wstring formatStringFromID (in long aID,[array, size_is(length)] in wstring params, in unsigned long length)
wstring formatStringFromName (in wstring aName,[array, size_is(length)] in wstring params, in unsigned long length)
nsISimpleEnumerator getSimpleEnumeration ()

Static Public Member Functions

static nsresult FormatString (const PRUnichar *formatStr, const PRUnichar **aParams, PRUint32 aLength, PRUnichar **aResult)

Public Attributes

< nsIPersistentProperties

Protected Member Functions

nsresult GetStringFromID (PRInt32 aID, nsAString &aResult)
nsresult GetStringFromName (const nsAString &aName, nsAString &aResult)
nsresult GetCombinedEnumeration (nsIStringBundleOverride *aOverrideString, nsISimpleEnumerator **aResult)

Private Attributes

nsCString mPropertiesURL
nsCOMPtr< nsIStringBundleOverridemOverrideStrings
PRPackedBool mAttemptedLoad
PRPackedBool mLoaded

Detailed Description

Definition at line 48 of file nsStringBundle.h.

Constructor & Destructor Documentation

nsStringBundle::nsStringBundle ( const char *  aURLSpec,
nsIStringBundleOverride aOverrideStrings 

Definition at line 90 of file nsStringBundle.cpp.


Definition at line 86 of file nsStringBundle.cpp.


Member Function Documentation

nsresult nsStringBundle::FormatString ( const PRUnichar formatStr,
const PRUnichar **  aParams,
PRUint32  aLength,
PRUnichar **  aResult 
) [static]

Definition at line 378 of file nsStringBundle.cpp.

  NS_ENSURE_ARG(aLength <= 10); // enforce 10-parameter limit

  // implementation note: you would think you could use vsmprintf
  // to build up an arbitrary length array.. except that there
  // is no way to build up a va_list at runtime!
  // Don't believe me? See:
  // -alecf
  *aResult = 
                              aLength >= 1 ? aParams[0] : nsnull,
                              aLength >= 2 ? aParams[1] : nsnull,
                              aLength >= 3 ? aParams[2] : nsnull,
                              aLength >= 4 ? aParams[3] : nsnull,
                              aLength >= 5 ? aParams[4] : nsnull,
                              aLength >= 6 ? aParams[5] : nsnull,
                              aLength >= 7 ? aParams[6] : nsnull,
                              aLength >= 8 ? aParams[7] : nsnull,
                              aLength >= 9 ? aParams[8] : nsnull,
                              aLength >= 10 ? aParams[9] : nsnull);
  return NS_OK;
wstring nsIStringBundle::formatStringFromID ( in long  aID,
[array, size_is(length)] in wstring  params,
in unsigned long  length 
) [inherited]
wstring nsIStringBundle::formatStringFromName ( in wstring  aName,
[array, size_is(length)] in wstring  params,
in unsigned long  length 
) [inherited]

Definition at line 297 of file nsStringBundle.cpp.

  nsCOMPtr<nsISupports> supports;
  nsCOMPtr<nsIPropertyElement> propElement;
  nsresult rv;

  nsCOMPtr<nsIMutableArray> resultArray;
  rv = NS_NewArray(getter_AddRefs(resultArray));

  // first, append the override elements
  nsCOMPtr<nsISimpleEnumerator> overrideEnumerator;
  rv = aOverrideStrings->EnumerateKeysInBundle(mPropertiesURL,
  PRBool hasMore;
  rv = overrideEnumerator->HasMoreElements(&hasMore);
  while (hasMore) {

    rv = overrideEnumerator->GetNext(getter_AddRefs(supports));
    if (NS_SUCCEEDED(rv))
      resultArray->AppendElement(supports, PR_FALSE);

    rv = overrideEnumerator->HasMoreElements(&hasMore);
    NS_ENSURE_SUCCESS(rv, rv);

  // ok, now we have the override elements in resultArray
  nsCOMPtr<nsISimpleEnumerator> propEnumerator;
  rv = mProps->Enumerate(getter_AddRefs(propEnumerator));
  if (NS_FAILED(rv)) {
    // no elements in mProps anyway, just return what we have
    return NS_NewArrayEnumerator(aResult, resultArray);

  // second, append all the elements that are in mProps
  do {
    rv = propEnumerator->GetNext(getter_AddRefs(supports));
    if (NS_SUCCEEDED(rv) &&
        (propElement = do_QueryInterface(supports, &rv))) {

      // now check if its in the override bundle
      nsCAutoString key;

      nsAutoString value;
      rv = aOverrideStrings->GetStringFromName(mPropertiesURL, key, value);

      // if it isn't there, then it is safe to append
      if (NS_FAILED(rv))
        resultArray->AppendElement(propElement, PR_FALSE);

    rv = propEnumerator->HasMoreElements(&hasMore);
    NS_ENSURE_SUCCESS(rv, rv);
  } while (hasMore);

  return resultArray->Enumerate(aResult);

Here is the call graph for this function:

wstring nsIStringBundle::GetStringFromID ( in long  aID) [inherited]

Here is the caller graph for this function:

nsresult nsStringBundle::GetStringFromID ( PRInt32  aID,
nsAString &  aResult 
) [protected]

Definition at line 152 of file nsStringBundle.cpp.

  nsCAutoString name;
  name.AppendInt(aID, 10);

  nsresult rv;
  // try override first
  if (mOverrideStrings) {
    rv = mOverrideStrings->GetStringFromName(mPropertiesURL,
    if (NS_SUCCEEDED(rv)) return rv;
  rv = mProps->GetStringProperty(name, aResult);

#ifdef DEBUG_tao_
  char *s = ToNewCString(aResult);
  printf("\n** GetStringFromID: aResult=%s, len=%d\n", s?s:"null", 
  if (s) nsMemory::Free(s);
#endif /* DEBUG_tao_ */

  return rv;

Here is the call graph for this function:

wstring nsIStringBundle::GetStringFromName ( in wstring  aName) [inherited]

Here is the caller graph for this function:

NS_IMETHODIMP nsStringBundle::GetStringFromName ( const nsAString &  aName,
nsAString &  aResult 
) [protected]

Definition at line 181 of file nsStringBundle.cpp.

  nsresult rv;

  // try override first
  if (mOverrideStrings) {
    rv = mOverrideStrings->GetStringFromName(mPropertiesURL,
    if (NS_SUCCEEDED(rv)) return rv;
  rv = mProps->GetStringProperty(NS_ConvertUCS2toUTF8(aName), aResult);
#ifdef DEBUG_tao_
  char *s = ToNewCString(aResult),
       *ss = ToNewCString(aName);
  printf("\n** GetStringFromName: aName=%s, aResult=%s, len=%d\n", 
         ss?ss:"null", s?s:"null", aResult.Length());
  if (s)  nsMemory::Free(s);
  if (ss) nsMemory::Free(ss);
#endif /* DEBUG_tao_ */
  return rv;

Here is the call graph for this function:

Definition at line 100 of file nsStringBundle.cpp.

  // this is different than mLoaded, because we only want to attempt
  // to load once
  // we only want to load once, but if we've tried once and failed,
  // continue to throw an error!
  if (mAttemptedLoad) {
    if (mLoaded)
      return NS_OK;
  mAttemptedLoad = PR_TRUE;

  nsresult rv;

  // do it synchronously
  nsCOMPtr<nsIURI> uri;
  rv = NS_NewURI(getter_AddRefs(uri), mPropertiesURL);
  if (NS_FAILED(rv)) return rv;

  // We don't use NS_OpenURI because we want to tweak the channel
  nsCOMPtr<nsIChannel> channel;
  rv = NS_NewChannel(getter_AddRefs(channel), uri);
  if (NS_FAILED(rv)) return rv;

  // It's a string bundle.  We expect a text/plain type, so set that as hint
  nsCOMPtr<nsIInputStream> in;
  rv = channel->Open(getter_AddRefs(in));
  if (NS_FAILED(rv)) return rv;

  NS_TIMELINE_MARK_FUNCTION("loading properties");

  NS_ASSERTION(NS_SUCCEEDED(rv) && in, "Error in OpenBlockingStream");
  mProps = do_CreateInstance(kPersistentPropertiesCID, &rv);
  mAttemptedLoad = mLoaded = PR_TRUE;
  rv = mProps->Load(in);

  mLoaded = NS_SUCCEEDED(rv);
  return rv;

Here is the call graph for this function:

Member Data Documentation

Definition at line 73 of file nsStringBundle.h.

Definition at line 74 of file nsStringBundle.h.

Definition at line 72 of file nsStringBundle.h.

Definition at line 71 of file nsStringBundle.h.

Definition at line 59 of file nsStringBundle.h.

The documentation for this class was generated from the following files: