source: trunk/dll/strips.c@ 895

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

Added remove_first_occurence_of_character to strip.c; Refined mailrun to use <mailto:> syntax;

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 1.8 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: strips.c 895 2007-12-29 23:46:11Z 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
[123]15
16***********************************************************************/
17
[2]18#include <os2.h>
19#include <stdlib.h>
20#include <string.h>
21#include <ctype.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
[793]83#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.