[123] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: strips.c 907 2008-01-06 07:26:17Z stevenhl $
|
---|
| 5 |
|
---|
| 6 | String strippers
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
---|
| 9 | Copyright (c) 2004 Steven H.Levine
|
---|
| 10 |
|
---|
[371] | 11 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
| 12 | 26 Jul 06 SHL Add chop_at_crnl
|
---|
[793] | 13 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[895] | 14 | 29 Dec 07 GKY Add remove_first_occurence_of_character
|
---|
[123] | 15 |
|
---|
| 16 | ***********************************************************************/
|
---|
| 17 |
|
---|
[2] | 18 | #include <string.h>
|
---|
| 19 |
|
---|
[907] | 20 | #include <os2.h>
|
---|
| 21 |
|
---|
[371] | 22 | VOID chop_at_crnl(PSZ pszSrc)
|
---|
| 23 | {
|
---|
| 24 | // Chop line at CR or NL
|
---|
| 25 | PSZ psz = strchr(pszSrc, '\r');
|
---|
[551] | 26 |
|
---|
[371] | 27 | if (psz)
|
---|
| 28 | *psz = 0;
|
---|
| 29 | psz = strchr(pszSrc, '\n');
|
---|
| 30 | if (psz)
|
---|
| 31 | *psz = 0;
|
---|
| 32 | }
|
---|
[2] | 33 |
|
---|
[371] | 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');
|
---|
[551] | 38 |
|
---|
[371] | 39 | if (psz) {
|
---|
| 40 | *psz = 0;
|
---|
| 41 | psz++;
|
---|
| 42 | }
|
---|
| 43 | return psz;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[551] | 46 | void strip_trail_char(char *pszStripChars, char *pszSrc)
|
---|
[371] | 47 | {
|
---|
[123] | 48 | char *psz;
|
---|
[2] | 49 |
|
---|
[551] | 50 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
---|
[123] | 51 | psz = pszSrc + strlen(pszSrc) - 1;
|
---|
| 52 | // while not empty and tail char in strip list
|
---|
[551] | 53 | while (*pszSrc && strchr(pszStripChars, *psz) != NULL) {
|
---|
[123] | 54 | *psz = 0;
|
---|
| 55 | psz--;
|
---|
[2] | 56 | }
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[551] | 60 | void strip_lead_char(char *pszStripChars, char *pszSrc)
|
---|
[371] | 61 | {
|
---|
[123] | 62 | char *psz = pszSrc;
|
---|
[2] | 63 |
|
---|
[551] | 64 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
---|
[123] | 65 | // while lead char in strip list
|
---|
[551] | 66 | while (*psz && strchr(pszStripChars, *psz) != NULL)
|
---|
[123] | 67 | psz++;
|
---|
[551] | 68 | if (psz != pszSrc)
|
---|
| 69 | memmove(pszSrc, psz, strlen(psz) + 1);
|
---|
[2] | 70 | }
|
---|
| 71 | }
|
---|
[793] | 72 |
|
---|
[895] | 73 | VOID remove_first_occurence_of_character(char *pszRemoveChar, char *pszSrc)
|
---|
| 74 | {
|
---|
| 75 | PSZ pszStrLocation;
|
---|
| 76 |
|
---|
| 77 | pszStrLocation = strchr(pszSrc, *pszRemoveChar);
|
---|
| 78 | if (pszStrLocation)
|
---|
| 79 | memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[906] | 82 | VOID remove_last_occurence_of_character(char *pszRemoveChar, char *pszSrc)
|
---|
| 83 | {
|
---|
| 84 | PSZ pszStrLocation;
|
---|
| 85 |
|
---|
| 86 | pszStrLocation = strrchr(pszSrc, *pszRemoveChar);
|
---|
| 87 | if (pszStrLocation)
|
---|
| 88 | memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[793] | 91 | #pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
|
---|