|
||||
File indexing completed on 2025-01-18 10:05:18
0001 // Created on: 1992-12-15 0002 // Created by: Mireille MERCIEN 0003 // Copyright (c) 1992-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _TCollection_HAsciiString_HeaderFile 0018 #define _TCollection_HAsciiString_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_Type.hxx> 0022 0023 #include <TCollection_AsciiString.hxx> 0024 #include <Standard_Transient.hxx> 0025 #include <Standard_CString.hxx> 0026 #include <Standard_Integer.hxx> 0027 #include <Standard_OStream.hxx> 0028 class TCollection_HExtendedString; 0029 0030 0031 class TCollection_HAsciiString; 0032 DEFINE_STANDARD_HANDLE(TCollection_HAsciiString, Standard_Transient) 0033 0034 //! A variable-length sequence of ASCII characters 0035 //! (normal 8-bit character type). It provides editing 0036 //! operations with built-in memory management to 0037 //! make HAsciiString objects easier to use than ordinary character arrays. 0038 //! HAsciiString objects are handles to strings. 0039 //! - HAsciiString strings may be shared by several objects. 0040 //! - You may use an AsciiString object to get the actual string. 0041 //! Note: HAsciiString objects use an AsciiString string as a field. 0042 class TCollection_HAsciiString : public Standard_Transient 0043 { 0044 0045 public: 0046 0047 0048 //! Initializes a HAsciiString to an empty AsciiString. 0049 Standard_EXPORT TCollection_HAsciiString(); 0050 0051 //! Initializes a HAsciiString with a CString. 0052 Standard_EXPORT TCollection_HAsciiString(const Standard_CString message); 0053 0054 //! Initializes a HAsciiString with a single character. 0055 Standard_EXPORT TCollection_HAsciiString(const Standard_Character aChar); 0056 0057 //! Initializes a HAsciiString with <length> space allocated. 0058 //! and filled with <filler>.This is useful for buffers. 0059 Standard_EXPORT TCollection_HAsciiString(const Standard_Integer length, const Standard_Character filler); 0060 0061 //! Initializes a HAsciiString with an integer value 0062 Standard_EXPORT TCollection_HAsciiString(const Standard_Integer value); 0063 0064 //! Initializes a HAsciiString with a real value 0065 Standard_EXPORT TCollection_HAsciiString(const Standard_Real value); 0066 0067 //! Initializes a HAsciiString with a AsciiString. 0068 Standard_EXPORT TCollection_HAsciiString(const TCollection_AsciiString& aString); 0069 0070 //! Initializes a HAsciiString with a AsciiString. 0071 TCollection_HAsciiString(TCollection_AsciiString&& theString) noexcept : 0072 myString(std::move(theString)) 0073 {} 0074 0075 //! Initializes a HAsciiString with a HAsciiString. 0076 Standard_EXPORT TCollection_HAsciiString(const Handle(TCollection_HAsciiString)& aString); 0077 0078 //! Initializes a HAsciiString with a HExtendedString. 0079 //! If replaceNonAscii is non-null character, it will be used 0080 //! in place of any non-ascii character found in the source string. 0081 //! Otherwise, creates UTF-8 unicode string. 0082 Standard_EXPORT TCollection_HAsciiString(const Handle(TCollection_HExtendedString)& aString, const Standard_Character replaceNonAscii); 0083 0084 //! Appends <other> to me. 0085 void AssignCat (const Standard_CString other); 0086 0087 //! Appends <other> to me. 0088 //! Example: aString = aString + anotherString 0089 void AssignCat (const Handle(TCollection_HAsciiString)& other); 0090 0091 //! Converts the first character into its corresponding 0092 //! upper-case character and the other characters into lowercase. 0093 //! Example: 0094 //! before 0095 //! me = "hellO " 0096 //! after 0097 //! me = "Hello " 0098 Standard_EXPORT void Capitalize(); 0099 0100 //! Creates a new string by concatenation of this 0101 //! ASCII string and the other ASCII string. 0102 //! Example: 0103 //! aString = aString + anotherString 0104 //! aString = aString + "Dummy" 0105 //! aString contains "I say " 0106 //! aString = aString + "Hello " + "Dolly" 0107 //! gives "I say Hello Dolly" 0108 //! Warning: To catenate more than one CString, you must put a String before. 0109 //! So the following example is WRONG ! 0110 //! aString = "Hello " + "Dolly" THIS IS NOT ALLOWED 0111 //! This rule is applicable to AssignCat (operator +=) too. 0112 Standard_EXPORT Handle(TCollection_HAsciiString) Cat (const Standard_CString other) const; 0113 0114 //! Creates a new string by concatenation of this 0115 //! ASCII string and the other ASCII string. 0116 //! Example: aString = aString + anotherString 0117 Standard_EXPORT Handle(TCollection_HAsciiString) Cat (const Handle(TCollection_HAsciiString)& other) const; 0118 0119 //! Modifies this ASCII string so that its length 0120 //! becomes equal to Width and the new characters 0121 //! are equal to Filler. New characters are added 0122 //! both at the beginning and at the end of this string. 0123 //! If Width is less than the length of this ASCII string, nothing happens. 0124 //! Example 0125 //! Handle(TCollection_HAsciiString) 0126 //! myAlphabet 0127 //! = new 0128 //! TCollection_HAsciiString 0129 //! ("abcdef"); 0130 //! myAlphabet->Center(9,' '); 0131 //! assert ( !strcmp( 0132 //! myAlphabet->ToCString(), 0133 //! " abcdef ") ); 0134 Standard_EXPORT void Center (const Standard_Integer Width, const Standard_Character Filler); 0135 0136 //! Replaces all characters equal to aChar by 0137 //! NewChar in this ASCII string. The substitution is 0138 //! case sensitive if CaseSensitive is true (default value). 0139 //! If you do not use the default case sensitive 0140 //! option, it does not matter whether aChar is upper-case or not. 0141 //! Example 0142 //! Handle(TCollection_HAsciiString) 0143 //! myMistake = new 0144 //! TCollection_HAsciiString 0145 //! ("Hather"); 0146 //! myMistake->ChangeAll('H','F'); 0147 //! assert ( !strcmp( 0148 //! myMistake->ToCString(), 0149 //! "Father") ); 0150 Standard_EXPORT void ChangeAll (const Standard_Character aChar, const Standard_Character NewChar, const Standard_Boolean CaseSensitive = Standard_True); 0151 0152 //! Removes all characters contained in <me>. 0153 //! This produces an empty HAsciiString. 0154 Standard_EXPORT void Clear(); 0155 0156 //! Returns the index of the first character of <me> that is 0157 //! present in <Set>. 0158 //! The search begins to the index FromIndex and ends to the 0159 //! the index ToIndex. 0160 //! Returns zero if failure. 0161 //! Raises an exception if FromIndex or ToIndex is out of range 0162 //! Example: 0163 //! before 0164 //! me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7 0165 //! after 0166 //! me = "aabAcAa" 0167 //! returns 0168 //! 1 0169 Standard_EXPORT Standard_Integer FirstLocationInSet (const Handle(TCollection_HAsciiString)& Set, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0170 0171 //! Returns the index of the first character of <me> 0172 //! that is not present in the set <Set>. 0173 //! The search begins to the index FromIndex and ends to the 0174 //! the index ToIndex in <me>. 0175 //! Returns zero if failure. 0176 //! Raises an exception if FromIndex or ToIndex is out of range. 0177 //! Example: 0178 //! before 0179 //! me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7 0180 //! after 0181 //! me = "aabAcAa" 0182 //! returns 0183 //! 3 0184 Standard_EXPORT Standard_Integer FirstLocationNotInSet (const Handle(TCollection_HAsciiString)& Set, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0185 0186 //! Insert a Character at position <where>. 0187 //! Example: 0188 //! aString contains "hy not ?" 0189 //! aString.Insert(1,'W'); gives "Why not ?" 0190 //! aString contains "Wh" 0191 //! aString.Insert(3,'y'); gives "Why" 0192 //! aString contains "Way" 0193 //! aString.Insert(2,'h'); gives "Why" 0194 Standard_EXPORT void Insert (const Standard_Integer where, const Standard_Character what); 0195 0196 //! Insert a HAsciiString at position <where>. 0197 Standard_EXPORT void Insert (const Standard_Integer where, const Standard_CString what); 0198 0199 //! Insert a HAsciiString at position <where>. 0200 Standard_EXPORT void Insert (const Standard_Integer where, const Handle(TCollection_HAsciiString)& what); 0201 0202 //! Inserts the other ASCII string a after a specific index in the string <me> 0203 //! Example: 0204 //! before 0205 //! me = "cde" , Index = 0 , other = "ab" 0206 //! after 0207 //! me = "abcde" , other = "ab" 0208 Standard_EXPORT void InsertAfter (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& other); 0209 0210 //! Inserts the other ASCII string a before a specific index in the string <me> 0211 //! Raises an exception if Index is out of bounds 0212 //! Example: 0213 //! before 0214 //! me = "cde" , Index = 1 , other = "ab" 0215 //! after 0216 //! me = "abcde" , other = "ab" 0217 Standard_EXPORT void InsertBefore (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& other); 0218 0219 //! Returns True if the string <me> contains zero character 0220 Standard_EXPORT Standard_Boolean IsEmpty() const; 0221 0222 //! Returns TRUE if <me> is 'ASCII' less than <other>. 0223 Standard_EXPORT Standard_Boolean IsLess (const Handle(TCollection_HAsciiString)& other) const; 0224 0225 //! Returns TRUE if <me> is 'ASCII' greater than <other>. 0226 Standard_EXPORT Standard_Boolean IsGreater (const Handle(TCollection_HAsciiString)& other) const; 0227 0228 //! Converts a HAsciiString containing a numeric expression to 0229 //! an Integer. 0230 //! Example: "215" returns 215. 0231 Standard_EXPORT Standard_Integer IntegerValue() const; 0232 0233 //! Returns True if the string contains an integer value. 0234 Standard_EXPORT Standard_Boolean IsIntegerValue() const; 0235 0236 //! Returns True if the string contains a real value. 0237 Standard_EXPORT Standard_Boolean IsRealValue() const; 0238 0239 //! Returns True if the string contains only ASCII characters 0240 //! between ' ' and '~'. 0241 //! This means no control character and no extended ASCII code. 0242 Standard_EXPORT Standard_Boolean IsAscii() const; 0243 0244 //! Returns True if the string S not contains same characters than 0245 //! the string <me>. 0246 Standard_EXPORT Standard_Boolean IsDifferent (const Handle(TCollection_HAsciiString)& S) const; 0247 0248 //! Returns True if the string S contains same characters than the 0249 //! string <me>. 0250 Standard_EXPORT Standard_Boolean IsSameString (const Handle(TCollection_HAsciiString)& S) const; 0251 0252 //! Returns True if the string S contains same characters than the 0253 //! string <me>. 0254 Standard_EXPORT Standard_Boolean IsSameString (const Handle(TCollection_HAsciiString)& S, const Standard_Boolean CaseSensitive) const; 0255 0256 //! Removes all space characters in the beginning of the string 0257 Standard_EXPORT void LeftAdjust(); 0258 0259 //! Left justify. 0260 //! Length becomes equal to Width and the new characters are 0261 //! equal to Filler 0262 //! if Width < Length nothing happens 0263 //! Raises an exception if Width is less than zero 0264 //! Example: 0265 //! before 0266 //! me = "abcdef" , Width = 9 , Filler = ' ' 0267 //! after 0268 //! me = "abcdef " 0269 Standard_EXPORT void LeftJustify (const Standard_Integer Width, const Standard_Character Filler); 0270 0271 //! Returns number of characters in <me>. 0272 //! This is the same functionality as 'strlen' in C. 0273 Standard_Integer Length() const; 0274 0275 //! returns an index in the string <me> of the first occurrence 0276 //! of the string S in the string <me> from the starting index 0277 //! FromIndex to the ending index ToIndex 0278 //! returns zero if failure 0279 //! Raises an exception if FromIndex or ToIndex is out of range. 0280 //! Example: 0281 //! before 0282 //! me = "aabAaAa", S = "Aa", FromIndex = 1, ToIndex = 7 0283 //! after 0284 //! me = "aabAaAa" 0285 //! returns 0286 //! 4 0287 Standard_EXPORT Standard_Integer Location (const Handle(TCollection_HAsciiString)& other, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0288 0289 //! Returns the index of the nth occurrence of the character C 0290 //! in the string <me> from the starting index FromIndex to the 0291 //! ending index ToIndex. 0292 //! Returns zero if failure. 0293 //! Raises an exception if FromIndex or ToIndex is out of range 0294 //! Example: 0295 //! before 0296 //! me = "aabAa", N = 3, C = 'a', FromIndex = 1, ToIndex = 5 0297 //! after 0298 //! me = "aabAa" 0299 //! returns 5 0300 Standard_EXPORT Standard_Integer Location (const Standard_Integer N, const Standard_Character C, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0301 0302 //! Converts <me> to its lower-case equivalent. 0303 Standard_EXPORT void LowerCase(); 0304 0305 //! Inserts the other string at the beginning of the string <me> 0306 //! Example: 0307 //! before 0308 //! me = "cde" , S = "ab" 0309 //! after 0310 //! me = "abcde" , S = "ab" 0311 Standard_EXPORT void Prepend (const Handle(TCollection_HAsciiString)& other); 0312 0313 //! Prints this string on the stream <astream>. 0314 Standard_EXPORT void Print (Standard_OStream& astream) const; 0315 0316 //! Converts a string containing a numeric expression to a Real. 0317 //! Example: 0318 //! "215" returns 215.0. 0319 //! "3.14159267" returns 3.14159267. 0320 Standard_EXPORT Standard_Real RealValue() const; 0321 0322 //! Remove all the occurrences of the character C in the string 0323 //! Example: 0324 //! before 0325 //! me = "HellLLo", C = 'L' , CaseSensitive = True 0326 //! after 0327 //! me = "Hello" 0328 Standard_EXPORT void RemoveAll (const Standard_Character C, const Standard_Boolean CaseSensitive); 0329 0330 //! Removes every <what> characters from <me> 0331 Standard_EXPORT void RemoveAll (const Standard_Character what); 0332 0333 //! Erases <ahowmany> characters from position <where>, 0334 //! <where> included. 0335 //! Example: 0336 //! aString contains "Hello" 0337 //! aString.Erase(2,2) erases 2 characters from position 1 0338 //! This gives "Hlo". 0339 Standard_EXPORT void Remove (const Standard_Integer where, const Standard_Integer ahowmany = 1); 0340 0341 //! Removes all space characters at the end of the string. 0342 Standard_EXPORT void RightAdjust(); 0343 0344 //! Right justify. 0345 //! Length becomes equal to Width and the new characters are 0346 //! equal to Filler 0347 //! if Width < Length nothing happens 0348 //! Raises an exception if Width is less than zero 0349 //! Example: 0350 //! before 0351 //! me = "abcdef" , Width = 9 , Filler = ' ' 0352 //! after 0353 //! me = " abcdef" 0354 Standard_EXPORT void RightJustify (const Standard_Integer Width, const Standard_Character Filler); 0355 0356 //! Searches a CString in <me> from the beginning 0357 //! and returns position of first item <what> matching. 0358 //! It returns -1 if not found. 0359 //! Example: 0360 //! aString contains "Sample single test" 0361 //! aString.Search("le") returns 5 0362 Standard_EXPORT Standard_Integer Search (const Standard_CString what) const; 0363 0364 //! Searches a String in <me> from the beginning 0365 //! and returns position of first item <what> matching. 0366 //! it returns -1 if not found. 0367 Standard_EXPORT Standard_Integer Search (const Handle(TCollection_HAsciiString)& what) const; 0368 0369 //! Searches a CString in a String from the end 0370 //! and returns position of first item <what> matching. 0371 //! It returns -1 if not found. 0372 //! Example: 0373 //! aString contains "Sample single test" 0374 //! aString.SearchFromEnd("le") returns 12 0375 Standard_EXPORT Standard_Integer SearchFromEnd (const Standard_CString what) const; 0376 0377 //! Searches a HAsciiString in another HAsciiString from the end 0378 //! and returns position of first item <what> matching. 0379 //! It returns -1 if not found. 0380 Standard_EXPORT Standard_Integer SearchFromEnd (const Handle(TCollection_HAsciiString)& what) const; 0381 0382 //! Replaces one character in the string at position <where>. 0383 //! If <where> is less than zero or greater than the length of <me> 0384 //! an exception is raised. 0385 //! Example: 0386 //! aString contains "Garbake" 0387 //! astring.Replace(6,'g') gives <me> = "Garbage" 0388 Standard_EXPORT void SetValue (const Standard_Integer where, const Standard_Character what); 0389 0390 //! Replaces a part of <me> in the string at position <where>. 0391 //! If <where> is less than zero or greater than the length of <me> 0392 //! an exception is raised. 0393 //! Example: 0394 //! aString contains "Garbake" 0395 //! astring.Replace(6,'g') gives <me> = "Garbage" 0396 Standard_EXPORT void SetValue (const Standard_Integer where, const Standard_CString what); 0397 0398 //! Replaces a part of <me> by another string. 0399 Standard_EXPORT void SetValue (const Standard_Integer where, const Handle(TCollection_HAsciiString)& what); 0400 0401 //! Splits a HAsciiString into two sub-strings. 0402 //! Example: 0403 //! aString contains "abcdefg" 0404 //! aString.Split(3) gives <me> = "abc" and returns "defg" 0405 Standard_EXPORT Handle(TCollection_HAsciiString) Split (const Standard_Integer where); 0406 0407 //! Creation of a sub-string of the string <me>. 0408 //! The sub-string starts to the index Fromindex and ends 0409 //! to the index ToIndex. 0410 //! Raises an exception if ToIndex or FromIndex is out of 0411 //! bounds 0412 //! Example: 0413 //! before 0414 //! me = "abcdefg", ToIndex=3, FromIndex=6 0415 //! after 0416 //! me = "abcdefg" 0417 //! returns 0418 //! "cdef" 0419 Standard_EXPORT Handle(TCollection_HAsciiString) SubString (const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0420 0421 //! Returns pointer to string (char *) 0422 //! This is useful for some casual manipulations 0423 //! Because this "char *" is 'const', you can't modify its contents. 0424 Standard_CString ToCString() const; 0425 0426 //! Extracts <whichone> token from <me>. 0427 //! By default, the <separators> is set to space and tabulation. 0428 //! By default, the token extracted is the first one (whichone = 1). 0429 //! <separators> contains all separators you need. 0430 //! If no token indexed by <whichone> is found, it returns an empty String. 0431 //! Example: 0432 //! aString contains "This is a message" 0433 //! aString.Token() returns "This" 0434 //! aString.Token(" ",4) returns "message" 0435 //! aString.Token(" ",2) returns "is" 0436 //! aString.Token(" ",9) returns "" 0437 //! Other separators than space character and tabulation are allowed 0438 //! aString contains "1234; test:message , value" 0439 //! aString.Token("; :,",4) returns "value" 0440 //! aString.Token("; :,",2) returns "test" 0441 Standard_EXPORT Handle(TCollection_HAsciiString) Token (const Standard_CString separators = " \t", const Standard_Integer whichone = 1) const; 0442 0443 //! Truncates <me> to <ahowmany> characters. 0444 //! Example: me = "Hello Dolly" -> Trunc(3) -> me = "Hel" 0445 Standard_EXPORT void Trunc (const Standard_Integer ahowmany); 0446 0447 //! Converts <me> to its upper-case equivalent. 0448 Standard_EXPORT void UpperCase(); 0449 0450 //! Length of the string ignoring all spaces (' ') and the 0451 //! control character at the end. 0452 Standard_EXPORT Standard_Integer UsefullLength() const; 0453 0454 //! Returns character at position <where> in <me>. 0455 //! If <where> is less than zero or greater than the length of 0456 //! <me>, an exception is raised. 0457 //! Example: 0458 //! aString contains "Hello" 0459 //! aString.Value(2) returns 'e' 0460 Standard_EXPORT Standard_Character Value (const Standard_Integer where) const; 0461 0462 //! Returns the field myString. 0463 const TCollection_AsciiString& String() const; 0464 0465 Standard_EXPORT Standard_Boolean IsSameState (const Handle(TCollection_HAsciiString)& other) const; 0466 0467 0468 0469 0470 DEFINE_STANDARD_RTTIEXT(TCollection_HAsciiString,Standard_Transient) 0471 0472 protected: 0473 0474 0475 0476 0477 private: 0478 0479 0480 TCollection_AsciiString myString; 0481 0482 0483 }; 0484 0485 0486 #include <TCollection_HAsciiString.lxx> 0487 0488 0489 0490 0491 0492 #endif // _TCollection_HAsciiString_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |