xref: /illumos-gate/usr/src/lib/libfru/include/Str.h (revision 1a2d662a91cee3bf82f41cd47c7ae6f3825d9db2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2000 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_STR_H
28 #define	_STR_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifdef	__cplusplus
35 }
36 #endif
37 
38 struct Str
39 {
40 	Str();
41 	Str(const char *str);
42 	Str(const char *str, int len);
43 	Str(const Str& rhs);
44 	virtual ~Str();
45 
46 	void operator=(const Str& rhs);
47 	void operator=(const char *str);
48 
49 	int operator != (const Str& rhs) const;
50 	int operator == (const Str& rhs) const;
51 
52 	char& operator[](int index) const;
53 	Str& operator<<(Str rhs);
54 	Str& operator<<(long long i);
55 	Str& operator<<(long i);
56 	Str& operator<<(int i);
57 	Str& operator<<(char c);
58 
59 	// normal "C" strcmp
60 	int compare(const Str& rhs) const;
61 
62 	int length(void) const;
63 
64 	// returns character found or 0x00 if nothing found.
65 	char tokenize(Str& token, const Str& separators, Str& remainder);
66 	void resetToken(void);
67 
68 	const char *peak(void) const;
69 
70 	void replaceAll(char c, char newc);
71 
72 private:
73 	char *str_;
74 	char *nextTok_;
75 };
76 
77 #ifdef __cplusplus
78 extern "C" {
79 #endif
80 
81 #ifdef	__cplusplus
82 }
83 #endif
84 
85 #endif /* _STR_H */
86