1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sistr.cxx,v $
10 * $Revision: 1.7.10.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 // The following two header-files declare
35 // standard ANSI-C++ functions. They may be replaced
36 // by the corresponding header-file-names of the
37 // actually used runtime library.
38 #include <string.h> // strlen(), memcpy(), memset()
39 #include <ctype.h> // tolower()
40 #include <limits.h> // INT_MAX
43 #pragma warning(disable:4365)
46 const char NULCH
= '\0';
47 const int NO_POS
= -1;
50 Simstr::Simstr(const char * str_
)
62 memcpy(sz
,str_
,len
+1);
66 Simstr::Simstr( const char * anybytes
,
70 unsigned slen
= strlen(anybytes
);
71 if (anybytes
== 0 || slen
<= unsigned(firstBytesPos
))
79 int maxLen
= slen
- unsigned(firstBytesPos
);
80 len
= maxLen
< nrOfBytes
84 memcpy(sz
,anybytes
+firstBytesPos
,len
);
90 Simstr::Simstr(const Simstr
& S
)
94 memcpy(sz
,S
.sz
,len
+1);
97 Simstr
& Simstr::operator=(const Simstr
& S
)
105 sz
= new char[len
+1];
106 memcpy(sz
,S
.sz
,len
+1);
117 Simstr::operator+(const Simstr
& S
) const
125 Simstr::operator+=(const Simstr
& S
)
135 Simstr::operator==(const Simstr
& S
) const
136 { return !strcmp(sz
,S
.sz
) ? true : false; }
139 Simstr::operator!=(const Simstr
& S
) const
140 { return strcmp(sz
,S
.sz
) ? true : false; }
143 Simstr::operator<(const Simstr
& S
) const
144 { return (strcmp(sz
,S
.sz
) < 0) ? true : false; }
147 Simstr::operator>(const Simstr
& S
) const
148 { return (strcmp(sz
,S
.sz
) > 0) ? true : false; }
151 Simstr::operator<=(const Simstr
& S
) const
152 { return (strcmp(sz
,S
.sz
) <= 0) ? true : false; }
155 Simstr::operator>=(const Simstr
& S
) const
156 { return (strcmp(sz
,S
.sz
) >= 0) ? true : false; }
161 // ************** LIST - Funktionen *****************
166 Simstr::push_front(char c
)
168 char * result
= new char[len
+2];
171 memcpy(result
+1,sz
,len
+1);
179 Simstr::push_back(char c
)
181 char * result
= new char[len
+2];
183 memcpy(result
,sz
,len
);
193 Simstr::push_front(const Simstr
& S
)
195 char * result
= new char[len
+1+S
.len
];
197 memcpy(result
,S
.sz
,S
.len
);
198 memcpy(result
+S
.len
,sz
,len
+1);
206 Simstr::push_back(const Simstr
& S
)
208 char * result
= new char[len
+1+S
.len
];
210 memcpy(result
,sz
,len
);
211 memcpy(result
+len
,S
.sz
,S
.len
+1);
222 Simstr::remove(int pos
, int anzahl
)
224 if (pos
>= len
|| pos
< 0 || anzahl
< 1)
227 int anz
= len
- pos
< anzahl
? len
- pos
: anzahl
;
229 char * result
= new char[len
-anz
+1];
231 memcpy(result
,sz
,pos
);
232 memcpy(result
+pos
,sz
+pos
+anz
,len
-pos
-anz
+1);
240 Simstr::remove_trailing_blanks()
243 for ( ; newlen
> 1 && sz
[newlen
] <= 32; --newlen
) {}
246 remove ( newlen
+1, len
-newlen
);
252 Simstr::pos_first(char c
) const
255 for (i
= 0; i
< len
? sz
[i
] != c
: false; i
++) ;
263 Simstr::pos_last(char c
) const
266 for (i
= len
-1; i
>= 0 ? sz
[i
] != c
: false; i
--) ;
274 Simstr::is_no_text() const
280 for (i
= 0; sz
[i
] <= 32 && i
< len
; i
++) ;
289 Simstr::replace_all(char oldCh
, char newCh
)
291 for (int i
=0; i
< len
; i
++)
298 operator+(const char * str
, const Simstr
& S
)
306 operator+(const Simstr
& S
, const char * str
)
314 operator+(char c
, const Simstr
& S
)
322 operator+(const Simstr
& S
, char c
)
330 // Simstr-Vergleiche mit char *
332 operator==(const Simstr
& S
, const char * str
)
334 return strcmp(S
,str
) == 0;
338 operator!=(const Simstr
& S
, const char * str
)
340 return strcmp(S
,str
) != 0;
344 operator<(const Simstr
& S
, const char * str
)
346 return strcmp(S
,str
) < 0;
350 operator>(const Simstr
& S
, const char * str
)
352 return strcmp(S
,str
) > 0;
356 operator<=(const Simstr
& S
, const char * str
)
358 return strcmp(S
,str
) <= 0;
362 operator>=(const Simstr
& S
, const char * str
)
364 return strcmp(S
,str
) >= 0;
368 operator==(const char * str
, const Simstr
& S
)
370 return strcmp(str
,S
) == 0;
374 operator!=(const char * str
, const Simstr
& S
)
376 return strcmp(str
,S
) != 0;
380 operator<(const char * str
, const Simstr
& S
)
382 return strcmp(str
,S
) < 0;
386 operator>(const char * str
, const Simstr
& S
)
388 return strcmp(str
,S
) > 0;
392 operator<=(const char * str
, const Simstr
& S
)
394 return strcmp(str
,S
) <= 0;
398 operator>=(const char * str
, const Simstr
& S
)
400 return strcmp(str
,S
) >= 0;