Subversion Repositories SvarDOS

Compare Revisions

Ignore whitespace Rev 219 → Rev 256

/pkginst/trim.c/rtrim.c
1,30 → 1,14
/*
* Right trim any space, tab, cr or lf
* Copyright (C) 2012-2016 Mateusz Viste
* trims any space, tab, cr or lf
* Copyright (C) 2012-2021 Mateusz Viste
*/
 
#include "rtrim.h"
#include "trim.h"
 
void rtrim(char *str) {
int x, realendofstr = 0;
for (x = 0; str[x] != 0; x++) {
switch (str[x]) {
case ' ':
case '\t':
case '\r':
case '\n':
break;
default:
realendofstr = x + 1;
break;
}
}
str[realendofstr] = 0;
}
 
 
void trim(char *str) {
int x, y, firstchar = -1, lastchar = -1;
 
/* find out first and last non-whitespace char */
for (x = 0; str[x] != 0; x++) {
switch (str[x]) {
case ' ':
38,8 → 22,12
break;
}
}
str[lastchar + 1] = 0; /* right trim */
if (firstchar > 0) { /* left trim (shift to the left ) */
 
/* right trim */
str[lastchar + 1] = 0;
 
/* left trim (shift to the left ) */
if (firstchar > 0) {
y = 0;
for (x = firstchar; str[x] != 0; x++) str[y++] = str[x];
str[y] = 0;