source: trunk/dll/strips.c@ 1036

Last change on this file since 1036 was 911, checked in by Gregg Young, 18 years ago

Commenting, help file, history update for recent changes; Minor clean up.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: strips.c 911 2008-01-07 01:01:29Z gyoung $
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>
22
[371]23VOID chop_at_crnl(PSZ pszSrc)
24{
25 // Chop line at CR or NL
26 PSZ psz = strchr(pszSrc, '\r');
[551]27
[371]28 if (psz)
29 *psz = 0;
30 psz = strchr(pszSrc, '\n');
31 if (psz)
32 *psz = 0;
33}
[2]34
[371]35PSZ convert_nl_to_nul(PSZ pszSrc)
36{
37 // Convert newline to nul, return pointer to next or NULL
38 PSZ psz = strchr(pszSrc, '\n');
[551]39
[371]40 if (psz) {
41 *psz = 0;
42 psz++;
43 }
44 return psz;
45}
46
[551]47void strip_trail_char(char *pszStripChars, char *pszSrc)
[371]48{
[123]49 char *psz;
[2]50
[551]51 if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
[123]52 psz = pszSrc + strlen(pszSrc) - 1;
53 // while not empty and tail char in strip list
[551]54 while (*pszSrc && strchr(pszStripChars, *psz) != NULL) {
[123]55 *psz = 0;
56 psz--;
[2]57 }
58 }
59}
60
[551]61void strip_lead_char(char *pszStripChars, char *pszSrc)
[371]62{
[123]63 char *psz = pszSrc;
[2]64
[551]65 if (pszSrc && *pszSrc && pszStripChars && *pszStripChars) {
[123]66 // while lead char in strip list
[551]67 while (*psz && strchr(pszStripChars, *psz) != NULL)
[123]68 psz++;
[551]69 if (psz != pszSrc)
70 memmove(pszSrc, psz, strlen(psz) + 1);
[2]71 }
72}
[793]73
[895]74VOID remove_first_occurence_of_character(char *pszRemoveChar, char *pszSrc)
75{
76 PSZ pszStrLocation;
77
78 pszStrLocation = strchr(pszSrc, *pszRemoveChar);
79 if (pszStrLocation)
80 memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
81}
82
[906]83VOID remove_last_occurence_of_character(char *pszRemoveChar, char *pszSrc)
84{
85 PSZ pszStrLocation;
86
87 pszStrLocation = strrchr(pszSrc, *pszRemoveChar);
88 if (pszStrLocation)
89 memmove(pszStrLocation, pszStrLocation + 1, strlen(pszStrLocation) + 1);
90}
91
[793]92#pragma alloc_text(MISC8,chop_at_crnl,convert_nl_to_nul,strip_trail_char,strip_lead_char)
[911]93#pragma alloc_text(MISC8,remove_first_occurence_of_character,remove_last_occurence_of_character)
Note: See TracBrowser for help on using the repository browser.