| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: strips.c 371 2006-07-27 02:27:18Z root $
|
|---|
| 5 |
|
|---|
| 6 | String strippers
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2004 Steven H.Levine
|
|---|
| 10 |
|
|---|
| 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
|---|
| 12 | 26 Jul 06 SHL Add chop_at_crnl
|
|---|
| 13 |
|
|---|
| 14 | ***********************************************************************/
|
|---|
| 15 |
|
|---|
| 16 | #include <os2.h>
|
|---|
| 17 | #include <stdlib.h>
|
|---|
| 18 | #include <string.h>
|
|---|
| 19 | #include <ctype.h>
|
|---|
| 20 |
|
|---|
| 21 | #pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
|
|---|
| 22 |
|
|---|
| 23 | VOID chop_at_crnl(PSZ pszSrc)
|
|---|
| 24 | {
|
|---|
| 25 | // Chop line at CR or NL
|
|---|
| 26 | PSZ psz = strchr(pszSrc, '\r');
|
|---|
| 27 | if (psz)
|
|---|
| 28 | *psz = 0;
|
|---|
| 29 | psz = strchr(pszSrc, '\n');
|
|---|
| 30 | if (psz)
|
|---|
| 31 | *psz = 0;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | PSZ convert_nl_to_nul(PSZ pszSrc)
|
|---|
| 35 | {
|
|---|
| 36 | // Convert newline to nul, return pointer to next or NULL
|
|---|
| 37 | PSZ psz = strchr(pszSrc, '\n');
|
|---|
| 38 | if (psz) {
|
|---|
| 39 | *psz = 0;
|
|---|
| 40 | psz++;
|
|---|
| 41 | }
|
|---|
| 42 | return psz;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | void strip_trail_char (char *pszStripChars,char *pszSrc)
|
|---|
| 46 | {
|
|---|
| 47 | char *psz;
|
|---|
| 48 |
|
|---|
| 49 | if(pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
|---|
| 50 | psz = pszSrc + strlen(pszSrc) - 1;
|
|---|
| 51 | // while not empty and tail char in strip list
|
|---|
| 52 | while (*pszSrc && strchr(pszStripChars,*psz) != NULL) {
|
|---|
| 53 | *psz = 0;
|
|---|
| 54 | psz--;
|
|---|
| 55 | }
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | void strip_lead_char (char *pszStripChars,char *pszSrc)
|
|---|
| 60 | {
|
|---|
| 61 | char *psz = pszSrc;
|
|---|
| 62 |
|
|---|
| 63 | if(pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
|---|
| 64 | // while lead char in strip list
|
|---|
| 65 | while(*psz && strchr(pszStripChars,*psz) != NULL)
|
|---|
| 66 | psz++;
|
|---|
| 67 | if(psz != pszSrc)
|
|---|
| 68 | memmove(pszSrc,psz,strlen(psz) + 1);
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|