Changeset 161 for trunk/src/helpers/stringh.c
- Timestamp:
- May 2, 2002, 5:17:26 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/stringh.c
r159 r161 550 550 * 551 551 * Example: 552 * 552 553 + PSZ pszBuf = "KEYWORD { --blah-- } next", 553 554 + pEnd; … … 555 556 + '{', '}', 556 557 + &pEnd) 558 * 557 559 * would return a new buffer containing " --blah-- ", 558 560 * and ppEnd would afterwards point to the space … … 562 564 */ 563 565 564 PSZ strhExtract(P SZ pszBuf,// in: search buffer566 PSZ strhExtract(PCSZ pszBuf, // in: search buffer 565 567 CHAR cOpen, // in: opening char 566 568 CHAR cClose, // in: closing char 567 P SZ *ppEnd)// out: if != NULL, receives first character after closing char569 PCSZ *ppEnd) // out: if != NULL, receives first character after closing char 568 570 { 569 571 PSZ pszReturn = NULL; 570 571 if (pszBuf) 572 { 573 PSZ pOpen; 574 if (pOpen = strchr(pszBuf, cOpen)) 575 { 576 // opening char found: 577 // now go thru the whole rest of the buffer 578 PSZ p = pOpen+1; 579 LONG lLevel = 1; // if this goes 0, we're done 580 while (*p) 572 PCSZ pOpen; 573 if ( (pszBuf) 574 && (pOpen = strchr(pszBuf, cOpen)) 575 ) 576 { 577 // opening char found: 578 // now go thru the whole rest of the buffer 579 PCSZ p = pOpen + 1; 580 LONG lLevel = 1; // if this goes 0, we're done 581 while (*p) 582 { 583 if (*p == cOpen) 584 lLevel++; 585 else if (*p == cClose) 581 586 { 582 if (*p == cOpen) 583 lLevel++; 584 else if (*p == cClose) 587 lLevel--; 588 if (lLevel <= 0) 585 589 { 586 lLevel--; 587 if (lLevel <= 0) 588 { 589 // matching closing bracket found: 590 // extract string 591 pszReturn = strhSubstr(pOpen+1, // after cOpen 592 p); // excluding cClose 593 if (ppEnd) 594 *ppEnd = p+1; 595 break; // while (*p) 596 } 590 // matching closing bracket found: 591 // extract string 592 pszReturn = strhSubstr(pOpen + 1, // after cOpen 593 p); // excluding cClose 594 if (ppEnd) 595 *ppEnd = p + 1; 596 break; // while (*p) 597 597 } 598 else if (*p == '\"')599 {600 // beginning of string:601 PSZ p2 = p+1;602 // find end of string603 while ((*p2) && (*p2 != '\"'))604 p2++;605 606 if (*p2 == '\"')607 // closing quote found:608 // search on after that609 p = p2; // raised below610 else611 break; // while (*p)612 }613 614 p++;615 598 } 599 else if (*p == '\"') 600 { 601 // beginning of string: 602 PCSZ p2 = p+1; 603 // find end of string 604 while ((*p2) && (*p2 != '\"')) 605 p2++; 606 607 if (*p2 == '\"') 608 // closing quote found: 609 // search on after that 610 p = p2; // raised below 611 else 612 break; // while (*p) 613 } 614 615 p++; 616 616 } 617 617 }
Note:
See TracChangeset
for help on using the changeset viewer.