Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-10 09:18:23

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