summaryrefslogtreecommitdiffstats
path: root/lanbrowsing/lisa/mystring.cpp
blob: 901c5db36f70801a8db3a441a99bd934dcb3b524 (plain)
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
#include "mystring.h"

#include <ctype.h>

//this one is taken from TQt/TQCString

MyString stripWhiteSpace(MyString str)
{
   if ( str.isEmpty() )				// nothing to do
      return "";

   char const *s = str.data();
   MyString result = s;
   int reslen = result.length();
   if ( !isspace(s[0]) && !isspace(s[reslen-1]) )
      return result;				// returns a copy

   s = result.data();
   int start = 0;
   int end = reslen - 1;
   while ( isspace(s[start]) )			// skip white space from start
      start++;
   if ( s[start] == '\0' )
   {			// only white space
      result.resize( 1 );
      return "";
   }

   while ( end && isspace(s[end]) )		// skip white space from end
      end--;

   end -= start - 1;

   result=str.mid(start,end);
   //memmove( result.data(), &s[start], end );
   //result.resize( end + 1 );
   return result;
}

//mainly taken from qcstring
int MyString::tqcontains(char c)
{
   int count = 0;
   char const *d = c_str();
   if ( d==0 )
      return 0;
   while ( *d )
      if ( *d++ == c )
         count++;
   return count;
}