** Return a substring from instr between [tag] and [/tag] ** char * returned must be freed by caller. ** pszNextInstr will be a pointer at the end of the ** first occurence found. */
| 593 | ** first occurence found. |
| 594 | */ |
| 595 | int getInlineTag(char *pszTag, char *pszInstr, char **pszResult) |
| 596 | { |
| 597 | char *pszStart, *pszEnd=NULL, *pszEndTag, *pszPatIn, *pszPatOut=NULL, *pszTmp; |
| 598 | int nInst=0; |
| 599 | int nLength; |
| 600 | |
| 601 | *pszResult = NULL; |
| 602 | |
| 603 | if(!pszInstr || !pszTag) { |
| 604 | msSetError(MS_WEBERR, "Invalid pointer.", "getInlineTag()"); |
| 605 | return MS_FAILURE; |
| 606 | } |
| 607 | |
| 608 | pszEndTag = (char*)msSmallMalloc(strlen(pszTag) + 3); |
| 609 | strcpy(pszEndTag, "[/"); |
| 610 | strcat(pszEndTag, pszTag); |
| 611 | |
| 612 | /* find start tag */ |
| 613 | pszPatIn = findTag(pszInstr, pszTag); |
| 614 | pszPatOut = strstr(pszInstr, pszEndTag); |
| 615 | |
| 616 | pszStart = pszPatIn; |
| 617 | |
| 618 | pszTmp = pszInstr; |
| 619 | |
| 620 | if(pszPatIn) |
| 621 | { |
| 622 | do |
| 623 | { |
| 624 | if(pszPatIn && pszPatIn < pszPatOut) |
| 625 | { |
| 626 | nInst++; |
| 627 | |
| 628 | pszTmp = pszPatIn; |
| 629 | } |
| 630 | |
| 631 | if(pszPatOut && ((pszPatIn == NULL) || pszPatOut < pszPatIn)) |
| 632 | { |
| 633 | pszEnd = pszPatOut; |
| 634 | nInst--; |
| 635 | |
| 636 | pszTmp = pszPatOut; |
| 637 | } |
| 638 | |
| 639 | pszPatIn = findTag(pszTmp+1, pszTag); |
| 640 | pszPatOut = strstr(pszTmp+1, pszEndTag); |
| 641 | |
| 642 | }while (pszTmp != NULL && nInst > 0); |
| 643 | } |
| 644 | |
| 645 | if(pszStart && pszEnd) { |
| 646 | /* find end of start tag */ |
| 647 | pszStart = strchr(pszStart, ']'); |
| 648 | |
| 649 | if(pszStart) { |
| 650 | pszStart++; |
| 651 | |
| 652 | nLength = pszEnd - pszStart; |
no test coverage detected