source: trunk/dll/strips.c@ 907

Last change on this file since 907 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.1 KB
Line 
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
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
16***********************************************************************/
17
18#include <string.h>
19
20#include <os2.h>
21
22VOID 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
34PSZ 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
46void 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
60void 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
73VOID 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
82VOID 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
91#pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
Note: See TracBrowser for help on using the repository browser.