![]() |
|
|||
File indexing completed on 2025-07-11 08:39:09
0001 // Created on: 1993-02-22 0002 // Created by: Mireille MERCIEN 0003 // Copyright (c) 1993-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_AsciiString_HeaderFile 0018 #define _TCollection_AsciiString_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <Standard_PCharacter.hxx> 0025 #include <Standard_CString.hxx> 0026 #include <Standard_Real.hxx> 0027 #include <Standard_OStream.hxx> 0028 #include <Standard_IStream.hxx> 0029 #include <Standard_Macro.hxx> 0030 class TCollection_ExtendedString; 0031 0032 //! Class defines a variable-length sequence of 8-bit characters. 0033 //! Despite class name (kept for historical reasons), it is intended to store UTF-8 string, not just ASCII characters. 0034 //! However, multi-byte nature of UTF-8 is not considered by the following methods: 0035 //! - Method ::Length() return the number of bytes, not the number of Unicode symbols. 0036 //! - Methods taking/returning symbol index work with 8-bit code units, not true Unicode symbols, 0037 //! including ::Remove(), ::SetValue(), ::Value(), ::Search(), ::Trunc() and others. 0038 //! If application needs to process multi-byte Unicode symbols explicitly, NCollection_Utf8Iter class can be used 0039 //! for iterating through Unicode string (UTF-32 code unit will be returned for each position). 0040 //! 0041 //! Class provides editing operations with built-in memory management to make AsciiString objects easier to use than ordinary character arrays. 0042 //! AsciiString objects follow value semantics; in other words, they are the actual strings, 0043 //! not handles to strings, and are copied through assignment. 0044 //! You may use HAsciiString objects to get handles to strings. 0045 class TCollection_AsciiString 0046 { 0047 public: 0048 0049 DEFINE_STANDARD_ALLOC 0050 0051 0052 //! Initializes a AsciiString to an empty AsciiString. 0053 Standard_EXPORT TCollection_AsciiString(); 0054 0055 //! Initializes a AsciiString with a CString. 0056 Standard_EXPORT TCollection_AsciiString(const Standard_CString message); 0057 0058 //! Initializes a AsciiString with a CString. 0059 Standard_EXPORT TCollection_AsciiString(const Standard_CString message, const Standard_Integer aLen); 0060 0061 //! Initializes a AsciiString with a single character. 0062 Standard_EXPORT TCollection_AsciiString(const Standard_Character aChar); 0063 0064 //! Initializes an AsciiString with <length> space allocated. 0065 //! and filled with <filler>. This is useful for buffers. 0066 Standard_EXPORT TCollection_AsciiString(const Standard_Integer length, const Standard_Character filler); 0067 0068 //! Initializes an AsciiString with an integer value 0069 Standard_EXPORT TCollection_AsciiString(const Standard_Integer value); 0070 0071 //! Initializes an AsciiString with a real value 0072 Standard_EXPORT TCollection_AsciiString(const Standard_Real value); 0073 0074 //! Initializes a AsciiString with another AsciiString. 0075 Standard_EXPORT TCollection_AsciiString(const TCollection_AsciiString& astring); 0076 0077 //! Move constructor 0078 Standard_EXPORT TCollection_AsciiString (TCollection_AsciiString&& theOther) Standard_Noexcept; 0079 0080 //! Initializes a AsciiString with copy of another AsciiString 0081 //! concatenated with the message character. 0082 Standard_EXPORT TCollection_AsciiString(const TCollection_AsciiString& astring, const Standard_Character message); 0083 0084 //! Initializes a AsciiString with copy of another AsciiString 0085 //! concatenated with the message string. 0086 Standard_EXPORT TCollection_AsciiString(const TCollection_AsciiString& astring, const Standard_CString message); 0087 0088 //! Initializes a AsciiString with copy of another AsciiString 0089 //! concatenated with the message string. 0090 Standard_EXPORT TCollection_AsciiString(const TCollection_AsciiString& astring, const TCollection_AsciiString& message); 0091 0092 //! Creation by converting an extended string to an ascii string. 0093 //! If replaceNonAscii is non-null character, it will be used 0094 //! in place of any non-ascii character found in the source string. 0095 //! Otherwise, creates UTF-8 unicode string. 0096 Standard_EXPORT TCollection_AsciiString(const TCollection_ExtendedString& astring, const Standard_Character replaceNonAscii = 0); 0097 0098 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) 0099 //! Initialize UTF-8 Unicode string from wide-char string considering it as Unicode string 0100 //! (the size of wide char is a platform-dependent - e.g. on Windows wchar_t is UTF-16). 0101 //! 0102 //! This constructor is unavailable if application is built with deprecated msvc option "-Zc:wchar_t-", 0103 //! since OCCT itself is never built with this option. 0104 Standard_EXPORT TCollection_AsciiString (const Standard_WideChar* theStringUtf); 0105 #endif 0106 0107 //! Appends <other> to me. This is an unary operator. 0108 Standard_EXPORT void AssignCat (const Standard_Character other); 0109 void operator += (const Standard_Character other) 0110 { 0111 AssignCat(other); 0112 } 0113 0114 //! Appends <other> to me. This is an unary operator. 0115 Standard_EXPORT void AssignCat (const Standard_Integer other); 0116 void operator += (const Standard_Integer other) 0117 { 0118 AssignCat(other); 0119 } 0120 0121 //! Appends <other> to me. This is an unary operator. 0122 Standard_EXPORT void AssignCat (const Standard_Real other); 0123 void operator += (const Standard_Real other) 0124 { 0125 AssignCat(other); 0126 } 0127 0128 //! Appends <other> to me. This is an unary operator. 0129 //! ex: aString += "Dummy" 0130 //! To catenate more than one CString, you must put a 0131 //! AsciiString before. 0132 //! Example: aString += "Hello " + "Dolly" IS NOT VALID ! 0133 //! But astring += anotherString + "Hello " + "Dolly" is valid. 0134 Standard_EXPORT void AssignCat (const Standard_CString other); 0135 void operator += (const Standard_CString other) 0136 { 0137 AssignCat(other); 0138 } 0139 0140 //! Appends <other> to me. This is an unary operator. 0141 //! Example: aString += anotherString 0142 Standard_EXPORT void AssignCat (const TCollection_AsciiString& other); 0143 void operator += (const TCollection_AsciiString& other) 0144 { 0145 AssignCat(other); 0146 } 0147 0148 //! Converts the first character into its corresponding 0149 //! upper-case character and the other characters into lowercase 0150 //! Example: before 0151 //! me = "hellO " 0152 //! after 0153 //! me = "Hello " 0154 Standard_EXPORT void Capitalize(); 0155 0156 //! Appends <other> to me. 0157 //! Syntax: 0158 //! aString = aString + "Dummy" 0159 //! Example: aString contains "I say " 0160 //! aString = aString + "Hello " + "Dolly" 0161 //! gives "I say Hello Dolly" 0162 //! To catenate more than one CString, you must put a String before. 0163 //! So the following example is WRONG ! 0164 //! aString = "Hello " + "Dolly" THIS IS NOT ALLOWED 0165 //! This rule is applicable to AssignCat (operator +=) too. 0166 TCollection_AsciiString Cat (const Standard_Character other) const; 0167 TCollection_AsciiString operator + (const Standard_Character other) const 0168 { 0169 return Cat(other); 0170 } 0171 0172 //! Appends <other> to me. 0173 //! Syntax: 0174 //! aString = aString + 15; 0175 //! Example: aString contains "I say " 0176 //! gives "I say 15" 0177 //! To catenate more than one CString, you must put a String before. 0178 //! So the following example is WRONG ! 0179 //! aString = "Hello " + "Dolly" THIS IS NOT ALLOWED 0180 //! This rule is applicable to AssignCat (operator +=) too. 0181 TCollection_AsciiString Cat (const Standard_Integer other) const; 0182 TCollection_AsciiString operator + (const Standard_Integer other) const 0183 { 0184 return Cat(other); 0185 } 0186 0187 //! Appends <other> to me. 0188 //! Syntax: 0189 //! aString = aString + 15.15; 0190 //! Example: aString contains "I say " 0191 //! gives "I say 15.15" 0192 //! To catenate more than one CString, you must put a String before. 0193 //! So the following example is WRONG ! 0194 //! aString = "Hello " + "Dolly" THIS IS NOT ALLOWED 0195 //! This rule is applicable to AssignCat (operator +=) too. 0196 TCollection_AsciiString Cat (const Standard_Real other) const; 0197 TCollection_AsciiString operator + (const Standard_Real other) const 0198 { 0199 return Cat(other); 0200 } 0201 0202 //! Appends <other> to me. 0203 //! Syntax: 0204 //! aString = aString + "Dummy" 0205 //! Example: aString contains "I say " 0206 //! aString = aString + "Hello " + "Dolly" 0207 //! gives "I say Hello Dolly" 0208 //! To catenate more than one CString, you must put a String before. 0209 //! So the following example is WRONG ! 0210 //! aString = "Hello " + "Dolly" THIS IS NOT ALLOWED 0211 //! This rule is applicable to AssignCat (operator +=) too. 0212 TCollection_AsciiString Cat (const Standard_CString other) const; 0213 TCollection_AsciiString operator + (const Standard_CString other) const 0214 { 0215 return Cat(other); 0216 } 0217 0218 //! Appends <other> to me. 0219 //! Example: aString = aString + anotherString 0220 TCollection_AsciiString Cat (const TCollection_AsciiString& other) const; 0221 TCollection_AsciiString operator + (const TCollection_AsciiString& other) const 0222 { 0223 return Cat(other); 0224 } 0225 0226 //! Modifies this ASCII string so that its length 0227 //! becomes equal to Width and the new characters 0228 //! are equal to Filler. New characters are added 0229 //! both at the beginning and at the end of this string. 0230 //! If Width is less than the length of this ASCII string, nothing happens. 0231 //! Example 0232 //! TCollection_AsciiString 0233 //! myAlphabet("abcdef"); 0234 //! myAlphabet.Center(9,' '); 0235 //! assert ( myAlphabet == " 0236 //! abcdef " ); 0237 Standard_EXPORT void Center (const Standard_Integer Width, const Standard_Character Filler); 0238 0239 //! Substitutes all the characters equal to aChar by NewChar 0240 //! in the AsciiString <me>. 0241 //! The substitution can be case sensitive. 0242 //! If you don't use default case sensitive, no matter whether aChar 0243 //! is uppercase or not. 0244 //! Example: me = "Histake" -> ChangeAll('H','M',Standard_True) 0245 //! gives me = "Mistake" 0246 Standard_EXPORT void ChangeAll (const Standard_Character aChar, const Standard_Character NewChar, const Standard_Boolean CaseSensitive = Standard_True); 0247 0248 //! Removes all characters contained in <me>. 0249 //! This produces an empty AsciiString. 0250 Standard_EXPORT void Clear(); 0251 0252 //! Copy <fromwhere> to <me>. 0253 //! Used as operator = 0254 //! Example: aString = anotherCString; 0255 Standard_EXPORT void Copy (const Standard_CString fromwhere); 0256 void operator = (const Standard_CString fromwhere) 0257 { 0258 Copy(fromwhere); 0259 } 0260 0261 //! Copy <fromwhere> to <me>. 0262 //! Used as operator = 0263 //! Example: aString = anotherString; 0264 Standard_EXPORT void Copy (const TCollection_AsciiString& fromwhere); 0265 0266 //! Copy assignment operator 0267 TCollection_AsciiString& operator= (const TCollection_AsciiString& theOther) 0268 { 0269 Copy(theOther); 0270 return *this; 0271 } 0272 0273 //! Moves string without reallocations 0274 Standard_EXPORT void Move (TCollection_AsciiString&& theOther); 0275 0276 //! Move assignment operator 0277 TCollection_AsciiString& operator= (TCollection_AsciiString&& theOther) noexcept 0278 { 0279 Move(std::forward<TCollection_AsciiString>(theOther)); 0280 return *this; 0281 } 0282 0283 //! Exchange the data of two strings (without reallocating memory). 0284 Standard_EXPORT void Swap (TCollection_AsciiString& theOther); 0285 0286 //! Frees memory allocated by AsciiString. 0287 Standard_EXPORT ~TCollection_AsciiString(); 0288 0289 //! Returns the index of the first character of <me> that is 0290 //! present in <Set>. 0291 //! The search begins to the index FromIndex and ends to the 0292 //! the index ToIndex. 0293 //! Returns zero if failure. 0294 //! Raises an exception if FromIndex or ToIndex is out of range. 0295 //! Example: before 0296 //! me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7 0297 //! after 0298 //! me = "aabAcAa" 0299 //! returns 0300 //! 1 0301 Standard_EXPORT Standard_Integer FirstLocationInSet (const TCollection_AsciiString& Set, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0302 0303 //! Returns the index of the first character of <me> 0304 //! that is not present in the set <Set>. 0305 //! The search begins to the index FromIndex and ends to the 0306 //! the index ToIndex in <me>. 0307 //! Returns zero if failure. 0308 //! Raises an exception if FromIndex or ToIndex is out of range. 0309 //! Example: before 0310 //! me = "aabAcAa", S = "Aa", FromIndex = 1, Toindex = 7 0311 //! after 0312 //! me = "aabAcAa" 0313 //! returns 0314 //! 3 0315 Standard_EXPORT Standard_Integer FirstLocationNotInSet (const TCollection_AsciiString& Set, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0316 0317 //! Inserts a Character at position <where>. 0318 //! Example: 0319 //! aString contains "hy not ?" 0320 //! aString.Insert(1,'W'); gives "Why not ?" 0321 //! aString contains "Wh" 0322 //! aString.Insert(3,'y'); gives "Why" 0323 //! aString contains "Way" 0324 //! aString.Insert(2,'h'); gives "Why" 0325 Standard_EXPORT void Insert (const Standard_Integer where, const Standard_Character what); 0326 0327 //! Inserts a CString at position <where>. 0328 //! Example: 0329 //! aString contains "O more" 0330 //! aString.Insert(2,"nce"); gives "Once more" 0331 Standard_EXPORT void Insert (const Standard_Integer where, const Standard_CString what); 0332 0333 //! Inserts a AsciiString at position <where>. 0334 Standard_EXPORT void Insert (const Standard_Integer where, const TCollection_AsciiString& what); 0335 0336 //! Pushing a string after a specific index in the string <me>. 0337 //! Raises an exception if Index is out of bounds. 0338 //! - less than 0 (InsertAfter), or less than 1 (InsertBefore), or 0339 //! - greater than the number of characters in this ASCII string. 0340 //! Example: 0341 //! before 0342 //! me = "cde" , Index = 0 , other = "ab" 0343 //! after 0344 //! me = "abcde" , other = "ab" 0345 Standard_EXPORT void InsertAfter (const Standard_Integer Index, const TCollection_AsciiString& other); 0346 0347 //! Pushing a string before a specific index in the string <me>. 0348 //! Raises an exception if Index is out of bounds. 0349 //! - less than 0 (InsertAfter), or less than 1 (InsertBefore), or 0350 //! - greater than the number of characters in this ASCII string. 0351 //! Example: 0352 //! before 0353 //! me = "cde" , Index = 1 , other = "ab" 0354 //! after 0355 //! me = "abcde" , other = "ab" 0356 Standard_EXPORT void InsertBefore (const Standard_Integer Index, const TCollection_AsciiString& other); 0357 0358 //! Returns True if the string <me> contains zero character. 0359 Standard_Boolean IsEmpty() const { return mylength == 0; } 0360 0361 //! Returns true if the characters in this ASCII string 0362 //! are identical to the characters in ASCII string other. 0363 //! Note that this method is an alias of operator ==. 0364 Standard_EXPORT Standard_Boolean IsEqual (const Standard_CString other) const; 0365 Standard_Boolean operator == (const Standard_CString other) const 0366 { 0367 return IsEqual(other); 0368 } 0369 0370 //! Returns true if the characters in this ASCII string 0371 //! are identical to the characters in ASCII string other. 0372 //! Note that this method is an alias of operator ==. 0373 Standard_EXPORT Standard_Boolean IsEqual (const TCollection_AsciiString& other) const; 0374 Standard_Boolean operator == (const TCollection_AsciiString& other) const 0375 { 0376 return IsEqual(other); 0377 } 0378 0379 //! Returns true if there are differences between the 0380 //! characters in this ASCII string and ASCII string other. 0381 //! Note that this method is an alias of operator != 0382 Standard_EXPORT Standard_Boolean IsDifferent (const Standard_CString other) const; 0383 Standard_Boolean operator != (const Standard_CString other) const 0384 { 0385 return IsDifferent(other); 0386 } 0387 0388 //! Returns true if there are differences between the 0389 //! characters in this ASCII string and ASCII string other. 0390 //! Note that this method is an alias of operator != 0391 Standard_EXPORT Standard_Boolean IsDifferent (const TCollection_AsciiString& other) const; 0392 Standard_Boolean operator != (const TCollection_AsciiString& other) const 0393 { 0394 return IsDifferent(other); 0395 } 0396 0397 //! Returns TRUE if <me> is 'ASCII' less than <other>. 0398 Standard_EXPORT Standard_Boolean IsLess (const Standard_CString other) const; 0399 Standard_Boolean operator < (const Standard_CString other) const 0400 { 0401 return IsLess(other); 0402 } 0403 0404 //! Returns TRUE if <me> is 'ASCII' less than <other>. 0405 Standard_EXPORT Standard_Boolean IsLess (const TCollection_AsciiString& other) const; 0406 Standard_Boolean operator < (const TCollection_AsciiString& other) const 0407 { 0408 return IsLess(other); 0409 } 0410 0411 //! Returns TRUE if <me> is 'ASCII' greater than <other>. 0412 Standard_EXPORT Standard_Boolean IsGreater (const Standard_CString other) const; 0413 Standard_Boolean operator > (const Standard_CString other) const 0414 { 0415 return IsGreater(other); 0416 } 0417 0418 //! Returns TRUE if <me> is 'ASCII' greater than <other>. 0419 Standard_EXPORT Standard_Boolean IsGreater (const TCollection_AsciiString& other) const; 0420 Standard_Boolean operator > (const TCollection_AsciiString& other) const 0421 { 0422 return IsGreater(other); 0423 } 0424 0425 //! Determines whether the beginning of this string instance matches the specified string. 0426 Standard_EXPORT Standard_Boolean StartsWith (const TCollection_AsciiString& theStartString) const; 0427 0428 //! Determines whether the end of this string instance matches the specified string. 0429 Standard_EXPORT Standard_Boolean EndsWith (const TCollection_AsciiString& theEndString) const; 0430 0431 //! Converts a AsciiString containing a numeric expression to 0432 //! an Integer. 0433 //! Example: "215" returns 215. 0434 Standard_EXPORT Standard_Integer IntegerValue() const; 0435 0436 //! Returns True if the AsciiString contains an integer value. 0437 //! Note: an integer value is considered to be a real value as well. 0438 Standard_EXPORT Standard_Boolean IsIntegerValue() const; 0439 0440 //! Returns True if the AsciiString starts with some characters that can be interpreted as integer or real value. 0441 //! @param theToCheckFull [in] when TRUE, checks if entire string defines a real value; 0442 //! otherwise checks if string starts with a real value 0443 //! Note: an integer value is considered to be a real value as well. 0444 Standard_EXPORT Standard_Boolean IsRealValue (Standard_Boolean theToCheckFull = Standard_False) const; 0445 0446 //! Returns True if the AsciiString contains only ASCII characters 0447 //! between ' ' and '~'. 0448 //! This means no control character and no extended ASCII code. 0449 Standard_EXPORT Standard_Boolean IsAscii() const; 0450 0451 //! Removes all space characters in the beginning of the string. 0452 Standard_EXPORT void LeftAdjust(); 0453 0454 //! left justify 0455 //! Length becomes equal to Width and the new characters are 0456 //! equal to Filler. 0457 //! If Width < Length nothing happens. 0458 //! Raises an exception if Width is less than zero. 0459 //! Example: 0460 //! before 0461 //! me = "abcdef" , Width = 9 , Filler = ' ' 0462 //! after 0463 //! me = "abcdef " 0464 Standard_EXPORT void LeftJustify (const Standard_Integer Width, const Standard_Character Filler); 0465 0466 //! Returns number of characters in <me>. 0467 //! This is the same functionality as 'strlen' in C. 0468 //! Example 0469 //! TCollection_AsciiString myAlphabet("abcdef"); 0470 //! assert ( myAlphabet.Length() == 6 ); 0471 //! - 1 is the position of the first character in this string. 0472 //! - The length of this string gives the position of its last character. 0473 //! - Positions less than or equal to zero, or 0474 //! greater than the length of this string are 0475 //! invalid in functions which identify a character 0476 //! of this string by its position. 0477 Standard_Integer Length() const; 0478 0479 //! Returns an index in the string <me> of the first occurrence 0480 //! of the string S in the string <me> from the starting index 0481 //! FromIndex to the ending index ToIndex 0482 //! returns zero if failure 0483 //! Raises an exception if FromIndex or ToIndex is out of range. 0484 //! Example: 0485 //! before 0486 //! me = "aabAaAa", S = "Aa", FromIndex = 1, ToIndex = 7 0487 //! after 0488 //! me = "aabAaAa" 0489 //! returns 0490 //! 4 0491 Standard_EXPORT Standard_Integer Location (const TCollection_AsciiString& other, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0492 0493 //! Returns the index of the nth occurrence of the character C 0494 //! in the string <me> from the starting index FromIndex to the 0495 //! ending index ToIndex. 0496 //! Returns zero if failure. 0497 //! Raises an exception if FromIndex or ToIndex is out of range. 0498 //! Example: 0499 //! before 0500 //! me = "aabAa", N = 3, C = 'a', FromIndex = 1, ToIndex = 5 0501 //! after 0502 //! me = "aabAa" 0503 //! returns 0504 //! 5 0505 Standard_EXPORT Standard_Integer Location (const Standard_Integer N, const Standard_Character C, const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0506 0507 //! Converts <me> to its lower-case equivalent. 0508 //! Example 0509 //! TCollection_AsciiString myString("Hello Dolly"); 0510 //! myString.UpperCase(); 0511 //! assert ( myString == "HELLO DOLLY" ); 0512 //! myString.LowerCase(); 0513 //! assert ( myString == "hello dolly" ); 0514 Standard_EXPORT void LowerCase(); 0515 0516 //! Inserts the string other at the beginning of this ASCII string. 0517 //! Example 0518 //! TCollection_AsciiString myAlphabet("cde"); 0519 //! TCollection_AsciiString myBegin("ab"); 0520 //! myAlphabet.Prepend(myBegin); 0521 //! assert ( myAlphabet == "abcde" ); 0522 Standard_EXPORT void Prepend (const TCollection_AsciiString& other); 0523 0524 //! Displays <me> on a stream. 0525 Standard_EXPORT void Print (Standard_OStream& astream) const; 0526 friend Standard_EXPORT Standard_OStream& operator << (Standard_OStream& astream,const TCollection_AsciiString& astring); 0527 0528 //! Read <me> from a stream. 0529 Standard_EXPORT void Read (Standard_IStream& astream); 0530 friend Standard_EXPORT Standard_IStream& operator >> (Standard_IStream& astream, TCollection_AsciiString& astring); 0531 0532 //! Converts an AsciiString containing a numeric expression. 0533 //! to a Real. 0534 //! Example: ex: "215" returns 215.0. 0535 //! ex: "3.14159267" returns 3.14159267. 0536 Standard_EXPORT Standard_Real RealValue() const; 0537 0538 //! Remove all the occurrences of the character C in the string. 0539 //! Example: 0540 //! before 0541 //! me = "HellLLo", C = 'L' , CaseSensitive = True 0542 //! after 0543 //! me = "Hello" 0544 Standard_EXPORT void RemoveAll (const Standard_Character C, const Standard_Boolean CaseSensitive); 0545 0546 //! Removes every <what> characters from <me>. 0547 Standard_EXPORT void RemoveAll (const Standard_Character what); 0548 0549 //! Erases <ahowmany> characters from position <where>, 0550 //! <where> included. 0551 //! Example: 0552 //! aString contains "Hello" 0553 //! aString.Remove(2,2) erases 2 characters from position 2 0554 //! This gives "Hlo". 0555 Standard_EXPORT void Remove (const Standard_Integer where, const Standard_Integer ahowmany = 1); 0556 0557 //! Removes all space characters at the end of the string. 0558 Standard_EXPORT void RightAdjust(); 0559 0560 //! Right justify. 0561 //! Length becomes equal to Width and the new characters are 0562 //! equal to Filler. 0563 //! if Width < Length nothing happens. 0564 //! Raises an exception if Width is less than zero. 0565 //! Example: 0566 //! before 0567 //! me = "abcdef" , Width = 9 , Filler = ' ' 0568 //! after 0569 //! me = " abcdef" 0570 Standard_EXPORT void RightJustify (const Standard_Integer Width, const Standard_Character Filler); 0571 0572 //! Searches a CString in <me> from the beginning 0573 //! and returns position of first item <what> matching. 0574 //! it returns -1 if not found. 0575 //! Example: 0576 //! aString contains "Sample single test" 0577 //! aString.Search("le") returns 5 0578 Standard_EXPORT Standard_Integer Search (const Standard_CString what) const; 0579 0580 //! Searches an AsciiString in <me> from the beginning 0581 //! and returns position of first item <what> matching. 0582 //! It returns -1 if not found. 0583 Standard_EXPORT Standard_Integer Search (const TCollection_AsciiString& what) const; 0584 0585 //! Searches a CString in a AsciiString from the end 0586 //! and returns position of first item <what> matching. 0587 //! It returns -1 if not found. 0588 //! Example: 0589 //! aString contains "Sample single test" 0590 //! aString.SearchFromEnd("le") returns 12 0591 Standard_EXPORT Standard_Integer SearchFromEnd (const Standard_CString what) const; 0592 0593 //! Searches a AsciiString in another AsciiString from the end 0594 //! and returns position of first item <what> matching. 0595 //! It returns -1 if not found. 0596 Standard_EXPORT Standard_Integer SearchFromEnd (const TCollection_AsciiString& what) const; 0597 0598 //! Replaces one character in the AsciiString at position <where>. 0599 //! If <where> is less than zero or greater than the length of <me> 0600 //! an exception is raised. 0601 //! Example: 0602 //! aString contains "Garbake" 0603 //! astring.Replace(6,'g') gives <me> = "Garbage" 0604 Standard_EXPORT void SetValue (const Standard_Integer where, const Standard_Character what); 0605 0606 //! Replaces a part of <me> by a CString. 0607 //! If <where> is less than zero or greater than the length of <me> 0608 //! an exception is raised. 0609 //! Example: 0610 //! aString contains "abcde" 0611 //! aString.SetValue(4,"1234567") gives <me> = "abc1234567" 0612 Standard_EXPORT void SetValue (const Standard_Integer where, const Standard_CString what); 0613 0614 //! Replaces a part of <me> by another AsciiString. 0615 Standard_EXPORT void SetValue (const Standard_Integer where, const TCollection_AsciiString& what); 0616 0617 //! Splits a AsciiString into two sub-strings. 0618 //! Example: 0619 //! aString contains "abcdefg" 0620 //! aString.Split(3) gives <me> = "abc" and returns "defg" 0621 Standard_EXPORT TCollection_AsciiString Split (const Standard_Integer where); 0622 0623 //! Creation of a sub-string of the string <me>. 0624 //! The sub-string starts to the index Fromindex and ends 0625 //! to the index ToIndex. 0626 //! Raises an exception if ToIndex or FromIndex is out of bounds 0627 //! Example: 0628 //! before 0629 //! me = "abcdefg", ToIndex=3, FromIndex=6 0630 //! after 0631 //! me = "abcdefg" 0632 //! returns 0633 //! "cdef" 0634 TCollection_AsciiString SubString (const Standard_Integer FromIndex, const Standard_Integer ToIndex) const; 0635 0636 //! Returns pointer to AsciiString (char *). 0637 //! This is useful for some casual manipulations. 0638 //! Warning: Because this "char *" is 'const', you can't modify its contents. 0639 Standard_CString ToCString() const; 0640 0641 //! Extracts <whichone> token from <me>. 0642 //! By default, the <separators> is set to space and tabulation. 0643 //! By default, the token extracted is the first one (whichone = 1). 0644 //! <separators> contains all separators you need. 0645 //! If no token indexed by <whichone> is found, it returns empty AsciiString. 0646 //! Example: 0647 //! aString contains "This is a message" 0648 //! aString.Token() returns "This" 0649 //! aString.Token(" ",4) returns "message" 0650 //! aString.Token(" ",2) returns "is" 0651 //! aString.Token(" ",9) returns "" 0652 //! Other separators than space character and tabulation are allowed : 0653 //! aString contains "1234; test:message , value" 0654 //! aString.Token("; :,",4) returns "value" 0655 //! aString.Token("; :,",2) returns "test" 0656 Standard_EXPORT TCollection_AsciiString Token (const Standard_CString separators = " \t", const Standard_Integer whichone = 1) const; 0657 0658 //! Truncates <me> to <ahowmany> characters. 0659 //! Example: me = "Hello Dolly" -> Trunc(3) -> me = "Hel" 0660 Standard_EXPORT void Trunc (const Standard_Integer ahowmany); 0661 0662 //! Converts <me> to its upper-case equivalent. 0663 Standard_EXPORT void UpperCase(); 0664 0665 //! Length of the string ignoring all spaces (' ') and the 0666 //! control character at the end. 0667 Standard_EXPORT Standard_Integer UsefullLength() const; 0668 0669 //! Returns character at position <where> in <me>. 0670 //! If <where> is less than zero or greater than the length of <me>, 0671 //! an exception is raised. 0672 //! Example: 0673 //! aString contains "Hello" 0674 //! aString.Value(2) returns 'e' 0675 Standard_EXPORT Standard_Character Value (const Standard_Integer where) const; 0676 0677 //! Computes a hash code for the given ASCII string 0678 //! Returns the same integer value as the hash function for TCollection_ExtendedString 0679 //! @return a computed hash code 0680 size_t HashCode() const; 0681 0682 //! Returns True when the two strings are the same. 0683 //! (Just for HashCode for AsciiString) 0684 static Standard_Boolean IsEqual (const TCollection_AsciiString& string1, const TCollection_AsciiString& string2); 0685 0686 //! Returns True when the two strings are the same. 0687 //! (Just for HashCode for AsciiString) 0688 static Standard_Boolean IsEqual (const TCollection_AsciiString& string1, const Standard_CString string2); 0689 0690 //! Returns True if the strings contain same characters. 0691 Standard_EXPORT static Standard_Boolean IsSameString (const TCollection_AsciiString& theString1, 0692 const TCollection_AsciiString& theString2, 0693 const Standard_Boolean theIsCaseSensitive); 0694 0695 friend class TCollection_HAsciiString; 0696 0697 private: 0698 0699 //! Internal wrapper to allocate on stack or heap 0700 void allocate(const int theLength); 0701 0702 //! Internal wrapper to reallocate on stack or heap 0703 void reallocate(const int theLength); 0704 0705 //! Internal wrapper to deallocate on stack 0706 void deallocate(); 0707 0708 private: 0709 0710 Standard_PCharacter mystring{}; //!< NULL-terminated string 0711 Standard_Integer mylength{}; //!< length in bytes (excluding terminating NULL symbol) 0712 }; 0713 0714 #include <TCollection_AsciiString.lxx> 0715 0716 #endif // _TCollection_AsciiString_HeaderFile
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |