* xmlXPathNormalizeFunction: * @ctxt: the XPath Parser context * @nargs: the number of arguments * * Implement the normalize-space() XPath function * string normalize-space(string?) * The normalize-space function returns the argument string with white * space normalized by stripping leading and trailing whitespace * and replacing sequences of whitespace characters by a single * space
| 8228 | * node converted to a string, in other words the value of the context node. |
| 8229 | */ |
| 8230 | void |
| 8231 | xmlXPathNormalizeFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
| 8232 | xmlChar *source, *target; |
| 8233 | int blank; |
| 8234 | |
| 8235 | if (ctxt == NULL) return; |
| 8236 | if (nargs == 0) { |
| 8237 | /* Use current context node */ |
| 8238 | source = xmlXPathCastNodeToString(ctxt->context->node); |
| 8239 | if (source == NULL) |
| 8240 | xmlXPathPErrMemory(ctxt); |
| 8241 | valuePush(ctxt, xmlXPathCacheWrapString(ctxt, source)); |
| 8242 | nargs = 1; |
| 8243 | } |
| 8244 | |
| 8245 | CHECK_ARITY(1); |
| 8246 | CAST_TO_STRING; |
| 8247 | CHECK_TYPE(XPATH_STRING); |
| 8248 | source = ctxt->value->stringval; |
| 8249 | if (source == NULL) |
| 8250 | return; |
| 8251 | target = source; |
| 8252 | |
| 8253 | /* Skip leading whitespaces */ |
| 8254 | while (IS_BLANK_CH(*source)) |
| 8255 | source++; |
| 8256 | |
| 8257 | /* Collapse intermediate whitespaces, and skip trailing whitespaces */ |
| 8258 | blank = 0; |
| 8259 | while (*source) { |
| 8260 | if (IS_BLANK_CH(*source)) { |
| 8261 | blank = 1; |
| 8262 | } else { |
| 8263 | if (blank) { |
| 8264 | *target++ = 0x20; |
| 8265 | blank = 0; |
| 8266 | } |
| 8267 | *target++ = *source; |
| 8268 | } |
| 8269 | source++; |
| 8270 | } |
| 8271 | *target = 0; |
| 8272 | } |
| 8273 | |
| 8274 | /** |
| 8275 | * xmlXPathTranslateFunction: |
nothing calls this directly
no test coverage detected