Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / TAO_IDL / util / utl_string.cpp
blobd9070dfa65f9a8232c4ada3103130fff736e8cd7
1 /*
3 COPYRIGHT
5 Copyright 1992, 1993, 1994 Sun Microsystems, Inc. Printed in the United
6 States of America. All Rights Reserved.
8 This product is protected by copyright and distributed under the following
9 license restricting its use.
11 The Interface Definition Language Compiler Front End (CFE) is made
12 available for your use provided that you include this license and copyright
13 notice on all media and documentation and the software program in which
14 this product is incorporated in whole or part. You may copy and extend
15 functionality (but may not remove functionality) of the Interface
16 Definition Language CFE without charge, but you are not authorized to
17 license or distribute it to anyone else except as part of a product or
18 program developed by you or with the express written consent of Sun
19 Microsystems, Inc. ("Sun").
21 The names of Sun Microsystems, Inc. and any of its subsidiaries or
22 affiliates may not be used in advertising or publicity pertaining to
23 distribution of Interface Definition Language CFE as permitted herein.
25 This license is effective until terminated by Sun for failure to comply
26 with this license. Upon termination, you shall destroy or return all code
27 and documentation for the Interface Definition Language CFE.
29 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED AS IS WITH NO WARRANTIES OF
30 ANY KIND INCLUDING THE WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS
31 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR ARISING FROM A COURSE OF
32 DEALING, USAGE OR TRADE PRACTICE.
34 INTERFACE DEFINITION LANGUAGE CFE IS PROVIDED WITH NO SUPPORT AND WITHOUT
35 ANY OBLIGATION ON THE PART OF Sun OR ANY OF ITS SUBSIDIARIES OR AFFILIATES
36 TO ASSIST IN ITS USE, CORRECTION, MODIFICATION OR ENHANCEMENT.
38 SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES SHALL HAVE NO LIABILITY WITH
39 RESPECT TO THE INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY
40 INTERFACE DEFINITION LANGUAGE CFE OR ANY PART THEREOF.
42 IN NO EVENT WILL SUN OR ANY OF ITS SUBSIDIARIES OR AFFILIATES BE LIABLE FOR
43 ANY LOST REVENUE OR PROFITS OR OTHER SPECIAL, INDIRECT AND CONSEQUENTIAL
44 DAMAGES, EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
46 Use, duplication, or disclosure by the government is subject to
47 restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
48 Technical Data and Computer Software clause at DFARS 252.227-7013 and FAR
49 52.227-19.
51 Sun, Sun Microsystems and the Sun logo are trademarks or registered
52 trademarks of Sun Microsystems, Inc.
54 SunSoft, Inc.
55 2550 Garcia Avenue
56 Mountain View, California 94043
58 NOTE:
60 SunOS, SunSoft, Sun, Solaris, Sun Microsystems or the Sun logo are
61 trademarks or registered trademarks of Sun Microsystems, Inc.
65 #include "utl_string.h"
66 #include "global_extern.h"
67 #include "fe_extern.h"
68 #include "utl_err.h"
70 // FUZZ: disable check_for_streams_include
71 #include "ace/streams.h"
73 #include "ace/OS_NS_ctype.h"
75 //////////////////////////////////////////////////////////////////////
76 //// Static functions may be used by non-UTL_String i.e. const char *
77 //////////////////////////////////////////////////////////////////////
79 bool
80 UTL_String::strcmp_caseless (
81 const char *lhs,
82 const char *rhs,
83 bool &mixed_case)
85 int difference;
87 // Advance until (difference between the strings is found) or (End of String)
88 while (!(difference= static_cast<int> (*lhs) - static_cast<int> (*rhs)) && *lhs)
90 ++lhs;
91 ++rhs;
94 // If not (End of Strings, therefore difference found above) check if a
95 // caseless match would work instead.
96 mixed_case=
97 (*lhs &&
98 *rhs &&
99 !(static_cast<int> (ACE_OS::ace_toupper (*lhs)) -
100 static_cast<int> (ACE_OS::ace_toupper (*rhs))
101 ) );
102 if (mixed_case)
104 ++lhs;
105 ++rhs;
107 // Continue caseless compare until (difference between strings) or (End of String)
108 while (!(difference= static_cast<int> (ACE_OS::ace_toupper (*lhs)) -
109 static_cast<int> (ACE_OS::ace_toupper (*rhs))) && *lhs)
111 ++lhs;
112 ++rhs;
116 // true is match (no difference found), false is difference found.
117 return !difference;
120 // Compare two const char *.
121 bool
122 UTL_String::compare (const char *lhs, const char *rhs)
124 bool result= false;
125 bool mixed= false;
127 if (lhs && rhs && strcmp_caseless (lhs, rhs, mixed))
129 result= !mixed;
130 if (mixed) // Strings match (differing case)
132 if (idl_global->case_diff_error ())
134 idl_global->err ()->name_case_error (
135 const_cast<char *> (lhs),
136 const_cast<char *> (rhs));
138 // If we try to continue from here, we risk a crash.
139 throw Bailout ();
141 else
143 idl_global->err ()->name_case_warning (
144 const_cast<char *> (lhs),
145 const_cast<char *> (rhs));
150 return result;
153 // Like the above but without error or warning message output.
154 bool
155 UTL_String::compare_quiet (const char *lhs, const char *rhs)
157 bool result= false;
158 bool mixed= false;
160 if (lhs && rhs && strcmp_caseless (lhs, rhs, mixed))
162 result= mixed;
165 return result;
168 // Get canonical representation. This is (implemented as) the all upper
169 // case corresponding string.
170 void
171 UTL_String::get_canonical_rep (const char *src, char *dest)
173 while (!!(*dest++= static_cast<char> (ACE_OS::ace_toupper (*src++))))
177 // Get canonical representation. This is (implemented as) the all upper
178 // case corresponding string.
179 void
180 UTL_String::get_canonical_rep (ACE_CString &cstr)
182 get_canonical_rep (&cstr [0], &cstr [0]);
185 //////////////////////////////////////////////////////////////////////
187 UTL_String::UTL_String ()
188 : copy_taken (false),
189 p_str (nullptr),
190 c_str (nullptr)
194 UTL_String::UTL_String (const char *str, bool take_copy)
195 : copy_taken (str ? take_copy : false),
196 p_str (this->copy_taken ? ACE::strnew (str)
197 : const_cast<char *>(str)),
198 c_str (nullptr)
202 UTL_String::UTL_String (UTL_String *s, bool force_copy)
203 : copy_taken (force_copy ? true : s->copy_taken),
204 p_str (this->copy_taken ? ACE::strnew (s->p_str)
205 : const_cast<char *> (s->p_str)),
206 c_str (nullptr)
210 UTL_String::~UTL_String ()
212 delete [] this->c_str;
213 if (copy_taken)
215 ACE::strdelete (this->p_str);
219 void
220 UTL_String::destroy ()
222 delete [] this->c_str;
223 this->c_str = nullptr;
224 if (this->copy_taken)
226 ACE::strdelete (this->p_str);
227 this->copy_taken = false;
229 this->p_str = nullptr;
232 // Compare two UTL_String *.
233 bool
234 UTL_String::compare (UTL_String *s)
236 return (this->p_str && s && s->get_string () &&
237 compare (this->p_str, s->get_string ()));
240 bool
241 UTL_String::compare_quiet (UTL_String *s)
243 return (this->p_str && s && s->get_string () &&
244 compare_quiet (this->p_str, s->get_string ()));
247 // Get the canonical representation from a String.
248 char *
249 UTL_String::get_canonical_rep ()
251 if (!this->c_str && this->p_str)
253 get_canonical_rep (
254 this->p_str,
255 this->c_str = new char [ACE_OS::strlen (this->p_str)+1]);
258 return this->c_str;
261 // AST Dumping.
262 void
263 UTL_String::dump (ACE_OSTREAM_TYPE &o)
265 o << this->p_str;