[go: up one dir, main page]

Menu

[r3]: / launchmenu / Strip.c  Maximize  Restore  History

Download this file

181 lines (159 with data), 4.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/*************************************************************************/
/* */
/* StringLib (C) by Gerhard W. Gruber in Vienna 1992 */
/* All rights reserved */
/* */
/*************************************************************************/
/******************************************************************************
*
* PROJECT: LaunchMenu
* $Source: /cvsroot/launchmenu/LaunchMenu/Strip.c,v $
* $Revision: 1.2 $
* $Date: 2003/10/04 22:01:14 $
* $Author: lightweave $
* $Name: $
*
* $Log: Strip.c,v $
* Revision 1.2 2003/10/04 22:01:14 lightweave
* Modifications for compiling the sources under Linux.
*
* Revision 1.1.1.1 2003/10/04 17:13:16 lightweave
* Initial Release to CVS.
*
*
* DESCRIPTION: Strips a string from whitespaces.
*
*****************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <string.h>
#include "Misc.h"
LONG FindChar(UBYTE *s, UBYTE *p, BOOL Case, BOOL Find, UBYTE SkipChar);
/**
*
* FUNCTION: strip(UBYTE *String, int Start)
*
* INPUT: UBYTE [IN/OUT] String - String that should be stripped
* [IN] Start - TRUE if strip from start of string
* FALSE if stripping from end. Any other
* value means both sides are stripped (i.e. 2).
*
* OUTPUT: BYTE Byte in Grossschreibung
*
* DESCRIPTION: This function strips the string from whitespaces
*
*/
UBYTE *Strip(UBYTE *s, int Start)
{
unsigned long n;
UBYTE *e;
BOOL d;
/* If neither true nor false we strip both parts */
if(Start != TRUE && Start != FALSE)
{
d = TRUE;
Start = FALSE;
}
else
d = Start;
n = strlen(s);
e = &s[n-1];
if(d == TRUE)
{
while(*s)
{
if(*s == ' ' || *s == '\t')
s++;
else
break;
}
d = Start;
}
// Check if we need a to strip at end as well.
// This may not be simply the else branch, because we change this
// when both parts are to be stripped.
if(d == FALSE)
{
while(e > s)
{
if(*e == ' ' || *e == '\t')
{
*e = 0;
e--;
}
else
break;
}
}
return(s);
}
/**
*
* FUNCTION: strstrip(UBYTE *String, int Start, UBYTE *Pattern)
*
* INPUT: UBYTE [IN/OUT] String - String that should be stripped
* [IN] Start - TRUE if strip from start of string
* FALSE if stripping from end. Any other
* value means both sides are stripped (i.e. 2).
* [IN Pattern - This string contains a list of characteres
* that should be removed from the string.
*
* OUTPUT: BYTE Byte in Grossschreibung
*
* DESCRIPTION: This function strips the string from all characteres listed in patter
* which are at the start or end of the string.
*
*/
UBYTE *StrStrip(UBYTE *s, int Start, char *p)
{
unsigned long n;
UBYTE *e, str[2];
BOOL d;
/* If neither true nor false we strip both parts */
if(Start != TRUE && Start != FALSE)
{
d = TRUE;
Start = FALSE;
}
else
d = Start;
str[1] = 0;
n = strlen(s);
e = &s[n-1];
if(d == TRUE)
{
while(*s)
{
str[0] = *s;
if(FindChar(str, p, FALSE, TRUE, 0) != -1)
s++;
else
break;
}
d = Start;
}
// Check if we need a to strip at end as well.
// This may not be simply the else branch, because we change this
// when both parts are to be stripped.
if(d == FALSE)
{
while(e > s)
{
str[0] = *e;
if(FindChar(str, p, FALSE, TRUE, 0) != -1)
{
*e = 0;
e--;
}
else
break;
}
}
return(s);
}