source: trunk/dll/strips.c@ 1570

Last change on this file since 1570 was 1193, checked in by John Small, 17 years ago

Improved comment on new "#if 0" lines.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
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
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 29 Dec 07 GKY Add remove_first_occurence_of_character
15 29 Dec 07 GKY Add remove_last_occurence_of_character
16
17***********************************************************************/
18
19#include <string.h>
20
21#include <os2.h>
22#include "strips.h"
23
24//static VOID remove_last_occurence_of_character(char *pszRemoveChar, char *pszSrc);
25
26VOID chop_at_crnl(PSZ pszSrc)
27{
28 // Chop line at CR or NL
29 PSZ psz = strchr(pszSrc, '\r');
30
31 if (psz)
32 *psz = 0;
33 psz = strchr(pszSrc, '\n');
34 if (psz)
35 *psz = 0;
36}
37
38PSZ convert_nl_to_nul(PSZ pszSrc)
39{
40 // Convert newline to nul, return pointer to next or NULL
41 PSZ psz = strchr(pszSrc, '\n');
42
43 if (psz) {
44 *psz = 0;
45 psz++;
46 }
47 return psz;
48}
49
50void strip_trail_char(char *pszStripChars, char *pszSrc)
51{
52 char *psz;
53
54 if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
55 psz = pszSrc + strlen(pszSrc) - 1;
56 // while not empty and tail char in strip list
57 while (*pszSrc && strchr(pszStripChars, *psz) != NULL) {
58 *psz = 0;
59 psz--;
60 }
61 }
62}
63
64void strip_lead_char(char *pszStripChars, char *pszSrc)
65{
66 char *psz = pszSrc;
67
68 if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
69 // while lead char in strip list
70 while (*psz && strchr(pszStripChars, *psz) != NULL)
71 psz++;
72 if (psz != pszSrc)
73 memmove(pszSrc, psz, strlen(psz) + 1);
74 }
75}
76
77VOID 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
86#if 0 // JBS 11 Sep 08
87VOID 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}
95#endif
96
97#pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
98#pragma alloc_text(MISC8,remove_first_occurence_of_character,remove_last_occurence_of_character)
Note: See TracBrowser for help on using the repository browser.