Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
nsXPointer.cpp File Reference
#include "nsIDOMNode.h"
#include "nsIDOMNodeList.h"
#include "nsIDOMElement.h"
#include "nsIDOMDocument.h"
#include "nsIDOMClassInfo.h"
#include "nsCOMPtr.h"
#include "nsXPointer.h"
#include "nsIModifyableXPointer.h"
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsIXPointer.h"
#include "nsFIXptr.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsContentCID.h"

Go to the source code of this file.

Classes

class  nsXPointerSchemeContext

Functions

static NS_DEFINE_IID (kRangeCID, NS_RANGE_CID)
 Implementation for the XPointer family of specifications, practically the XPointer Processor.
nsresult NS_NewXPointerResult (nsIXPointerResult **aResult)
static nsresult NS_NewXPointerResult (nsIDOMRange *aRange, nsIXPointerResult **aResult)
static nsresult NS_NewXPointerResult (nsIDOMNode *aNode, nsIXPointerResult **aResult)
static nsresult GetNextSchemeNameAndData (nsString &aExpression, nsString &aScheme, nsString &aData)

Function Documentation

static nsresult GetNextSchemeNameAndData ( nsString aExpression,
nsString aScheme,
nsString aData 
) [static]

Definition at line 268 of file nsXPointer.cpp.

{
  aScheme.Truncate();
  aData.Truncate();

  PRInt32 lp = aExpression.FindChar('(');
  if (lp < 1) {
    return NS_ERROR_FAILURE; // format |scheme + '(' [ + data + ] + ')'| required
  }

  PRInt32 i = lp + 1, len = aExpression.Length();
  if (i >= len) {
    return NS_ERROR_FAILURE; // format |scheme + '(' [ + data + ] + ')'| required
  }

  aScheme = Substring(aExpression, 0, lp);
  aScheme.CompressWhitespace(PR_TRUE, PR_FALSE);
  if (aScheme.FindCharInSet(" \t\r\n") > 0) {
    return NS_ERROR_FAILURE; // scheme name can't contain ws (we'd really need to check a lot more...)
  }

  // XXX perf: Switch to string iterators
  PRBool escapeOn = PR_FALSE;
  PRInt32 balance = 1;
  for (; i < len; ++i) {
    // Circumflex is the escape character that can precede ^, ( and ) only
    if (aExpression[i] == '^') {
      if (!escapeOn) {
        escapeOn = PR_TRUE;
        continue;
      }
    } else if (escapeOn) {
      if ((aExpression[i] != '(') && (aExpression[i] != ')')) {
        return NS_ERROR_FAILURE; // illegal use of ^
      }
    } else if (aExpression[i] == '(') {
      ++balance;
    } else if (aExpression[i] == ')') {
      if (--balance == 0) {
        aExpression.Cut(0, i + 1);
        break;
      }
    }

    aData.Append(aExpression[i]);
    escapeOn = PR_FALSE;
  }

  if (balance != 0) {
    return NS_ERROR_FAILURE; // format |scheme + '(' [ + data + ] + ')'| required
  }

  return NS_OK;
}

Here is the call graph for this function:

static NS_DEFINE_IID ( kRangeCID  ,
NS_RANGE_CID   
) [static]

Implementation for the XPointer family of specifications, practically the XPointer Processor.

The processor can call optional modules that implement some XPointer schemes that were not implemented in this file. Please note that implementation of the xmlns scheme is left to the optional scheme implementations - all the information they need will be passed in.

The framework: http://www.w3.org/TR/xptr-framework/ The element scheme: http://www.w3.org/TR/xptr-element/

Additionally this module implements 'fixptr' scheme for the FIXptr W3C proposal: http://lists.w3.org/Archives/Public/www-xml-linking-comments/2001AprJun/att-0074/01-NOTE-FIXptr-20010425.htm

Definition at line 134 of file nsXPointer.cpp.

{
  NS_ENSURE_ARG_POINTER(aResult);

  *aResult = new nsXPointerResult();
  if (!*aResult) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  
  NS_ADDREF(*aResult);

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult NS_NewXPointerResult ( nsIDOMRange aRange,
nsIXPointerResult **  aResult 
) [static]

Definition at line 148 of file nsXPointer.cpp.

{
  NS_ENSURE_ARG(aRange);
  NS_ENSURE_ARG_POINTER(aResult);

  nsCOMPtr<nsXPointerResult> result(new nsXPointerResult());
  if (!result) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  
  nsresult rv = result->AppendRange(aRange);
  if (NS_FAILED(rv)) {
    return rv;
  }

  *aResult = result.get();
  NS_ADDREF(*aResult);

  return NS_OK;
}

Here is the call graph for this function:

static nsresult NS_NewXPointerResult ( nsIDOMNode aNode,
nsIXPointerResult **  aResult 
) [static]

Definition at line 170 of file nsXPointer.cpp.

{
  NS_ENSURE_ARG(aNode);
  NS_ENSURE_ARG_POINTER(aResult);

  nsCOMPtr<nsIDOMRange> range(do_CreateInstance(kRangeCID));
  if (!range) {
    return NS_ERROR_OUT_OF_MEMORY;
  }

  nsresult rv = range->SelectNode(aNode);
  if (NS_FAILED(rv)) {
    return rv;
  }

  return NS_NewXPointerResult(range, aResult);
}

Here is the call graph for this function: