| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: strips.c 793 2007-08-21 02:53:38Z gyoung $
|
|---|
| 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 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 14 |
|
|---|
| 15 | ***********************************************************************/
|
|---|
| 16 |
|
|---|
| 17 | #include <os2.h>
|
|---|
| 18 | #include <stdlib.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <ctype.h>
|
|---|
| 21 |
|
|---|
| 22 | VOID chop_at_crnl(PSZ pszSrc)
|
|---|
| 23 | {
|
|---|
| 24 | // Chop line at CR or NL
|
|---|
| 25 | PSZ psz = strchr(pszSrc, '\r');
|
|---|
| 26 |
|
|---|
| 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 |
|
|---|
| 39 | if (psz) {
|
|---|
| 40 | *psz = 0;
|
|---|
| 41 | psz++;
|
|---|
| 42 | }
|
|---|
| 43 | return psz;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | void strip_trail_char(char *pszStripChars, char *pszSrc)
|
|---|
| 47 | {
|
|---|
| 48 | char *psz;
|
|---|
| 49 |
|
|---|
| 50 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
|---|
| 51 | psz = pszSrc + strlen(pszSrc) - 1;
|
|---|
| 52 | // while not empty and tail char in strip list
|
|---|
| 53 | while (*pszSrc && strchr(pszStripChars, *psz) != NULL) {
|
|---|
| 54 | *psz = 0;
|
|---|
| 55 | psz--;
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | void strip_lead_char(char *pszStripChars, char *pszSrc)
|
|---|
| 61 | {
|
|---|
| 62 | char *psz = pszSrc;
|
|---|
| 63 |
|
|---|
| 64 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
|---|
| 65 | // while lead char in strip list
|
|---|
| 66 | while (*psz && strchr(pszStripChars, *psz) != NULL)
|
|---|
| 67 | psz++;
|
|---|
| 68 | if (psz != pszSrc)
|
|---|
| 69 | memmove(pszSrc, psz, strlen(psz) + 1);
|
|---|
| 70 | }
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | #pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
|
|---|