[xml] XPath normalize-string

Date view Thread view Subject view Author view

From: Bjorn Reese (breese@mail1.stofanet.dk)
Date: Sun Sep 24 2000 - 07:04:25 EDT


As a small exercise to familiarize myself with the code of libxml,
have I implemented the XPath normalize-string function.

I have tried to follow the existing coding style, but have been
unable to tell Emacs to increase its indentation level from 2 to
4 (c-indent-level isn't recognized in Emacs 20, so if anybody can
tell me how, I would be grateful).

I have attached a context diff against 2-2.2.3.

*** libxml2-2.2.3/xpath.c Sat Sep 16 21:46:39 2000
--- libxml/xpath.c Sun Sep 24 03:02:09 2000
***************
*** 2796,2803 ****
   */
  void
  xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
      CHECK_ARITY(1);
! TODO /* normalize isn't as boring as translate, but pretty much */
  }
  
  /**
--- 2796,2844 ----
   */
  void
  xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) {
+ xmlXPathObjectPtr obj = NULL;
+ xmlChar *source;
+ xmlBufferPtr target;
+ xmlChar blank;
+
+ if (nargs < 1) {
+ /* Use current context node */
+ CHECK_ARITY(0);
+ TODO /* source = xmlNodeGetContent(ctxt->context->node); */
+ } else if (nargs >= 1) {
+ /* Use argument */
      CHECK_ARITY(1);
! obj = valuePop(ctxt);
! if (obj == NULL) XP_ERROR(XPATH_INVALID_OPERAND);
! source = obj->stringval;
! }
! target = xmlBufferCreate();
! if (target && source) {
!
! /* Skip leading whitespaces */
! while (IS_BLANK(*source))
! source++;
!
! /* Collapse intermediate whitespaces, and skip trailing whitespaces */
! blank = 0;
! while (*source) {
! if (IS_BLANK(*source)) {
! blank = *source;
! } else {
! if (blank) {
! xmlBufferAdd(target, &blank, 1);
! blank = 0;
! }
! xmlBufferAdd(target, source, 1);
! }
! source++;
! }
!
! valuePush(ctxt, xmlXPathNewString(xmlBufferContent(target)));
! xmlBufferFree(target);
! }
! if (obj)
! xmlXPathFreeObject(obj);
  }
  
  /**

----
Message from the list xml@rpmfind.net
Archived at : http://xmlsoft.org/messages/
to unsubscribe: echo "unsubscribe xml" | mail  majordomo@rpmfind.net


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Sun Sep 24 2000 - 09:43:25 EDT