[123] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: strips.c 1193 2008-09-11 11:08:14Z jbs $
|
---|
| 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
|
---|
[911] | 15 | 29 Dec 07 GKY Add remove_last_occurence_of_character
|
---|
[123] | 16 |
|
---|
| 17 | ***********************************************************************/
|
---|
| 18 |
|
---|
[2] | 19 | #include <string.h>
|
---|
| 20 |
|
---|
[907] | 21 | #include <os2.h>
|
---|
[1156] | 22 | #include "strips.h"
|
---|
[907] | 23 |
|
---|
[1156] | 24 | //static VOID remove_last_occurence_of_character(char *pszRemoveChar, char *pszSrc);
|
---|
| 25 |
|
---|
[371] | 26 | VOID chop_at_crnl(PSZ pszSrc)
|
---|
| 27 | {
|
---|
| 28 | // Chop line at CR or NL
|
---|
| 29 | PSZ psz = strchr(pszSrc, '\r');
|
---|
[551] | 30 |
|
---|
[371] | 31 | if (psz)
|
---|
| 32 | *psz = 0;
|
---|
| 33 | psz = strchr(pszSrc, '\n');
|
---|
| 34 | if (psz)
|
---|
| 35 | *psz = 0;
|
---|
| 36 | }
|
---|
[2] | 37 |
|
---|
[371] | 38 | PSZ convert_nl_to_nul(PSZ pszSrc)
|
---|
| 39 | {
|
---|
| 40 | // Convert newline to nul, return pointer to next or NULL
|
---|
| 41 | PSZ psz = strchr(pszSrc, '\n');
|
---|
[551] | 42 |
|
---|
[371] | 43 | if (psz) {
|
---|
| 44 | *psz = 0;
|
---|
| 45 | psz++;
|
---|
| 46 | }
|
---|
| 47 | return psz;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[551] | 50 | void strip_trail_char(char *pszStripChars, char *pszSrc)
|
---|
[371] | 51 | {
|
---|
[123] | 52 | char *psz;
|
---|
[2] | 53 |
|
---|
[551] | 54 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
---|
[123] | 55 | psz = pszSrc + strlen(pszSrc) - 1;
|
---|
| 56 | // while not empty and tail char in strip list
|
---|
[551] | 57 | while (*pszSrc && strchr(pszStripChars, *psz) != NULL) {
|
---|
[123] | 58 | *psz = 0;
|
---|
| 59 | psz--;
|
---|
[2] | 60 | }
|
---|
| 61 | }
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[551] | 64 | void strip_lead_char(char *pszStripChars, char *pszSrc)
|
---|
[371] | 65 | {
|
---|
[123] | 66 | char *psz = pszSrc;
|
---|
[2] | 67 |
|
---|
[551] | 68 | if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
|
---|
[123] | 69 | // while lead char in strip list
|
---|
[551] | 70 | while (*psz && strchr(pszStripChars, *psz) != NULL)
|
---|
[123] | 71 | psz++;
|
---|
[551] | 72 | if (psz != pszSrc)
|
---|
| 73 | memmove(pszSrc, psz, strlen(psz) + 1);
|
---|
[2] | 74 | }
|
---|
| 75 | }
|
---|
[793] | 76 |
|
---|
[895] | 77 | VOID remove_first_occurence_of_character(char *pszRemoveChar, char *pszSrc)
|
---|
| 78 | {
|
---|
| 79 | PSZ pszStrLocation;
|
---|
| 80 |
|
---|
| 81 | pszStrLocation = strchr(pszSrc, *pszRemoveChar);
|
---|
| 82 | if (pszStrLocation)
|
---|
| 83 | memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[1193] | 86 | #if 0 // JBS 11 Sep 08
|
---|
[906] | 87 | VOID remove_last_occurence_of_character(char *pszRemoveChar, char *pszSrc)
|
---|
| 88 | {
|
---|
| 89 | PSZ pszStrLocation;
|
---|
| 90 |
|
---|
| 91 | pszStrLocation = strrchr(pszSrc, *pszRemoveChar);
|
---|
| 92 | if (pszStrLocation)
|
---|
| 93 | memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
|
---|
| 94 | }
|
---|
[1156] | 95 | #endif
|
---|
[906] | 96 |
|
---|
[793] | 97 | #pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
|
---|
[911] | 98 | #pragma alloc_text(MISC8,remove_first_occurence_of_character,remove_last_occurence_of_character)
|
---|