1 // Copyright (c) 1993-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <TCollection_ExtendedString.hxx>
17 #include <NCollection_UtfIterator.hxx>
18 #include <Standard.hxx>
19 #include <Standard_ExtString.hxx>
20 #include <Standard_NegativeValue.hxx>
21 #include <Standard_NullObject.hxx>
22 #include <Standard_NumericError.hxx>
23 #include <Standard_OutOfRange.hxx>
24 #include <TCollection_AsciiString.hxx>
31 //! Allocate string buffer (automatically adding extra symbol for NULL-termination).
32 static Standard_ExtCharacter* allocateExtChars (const Standard_Size theLength)
34 return (Standard_ExtCharacter* )Standard::Allocate ((theLength + 1) * sizeof(Standard_ExtCharacter));
37 //! Re-allocate string buffer (automatically adding extra symbol for NULL-termination).
38 static Standard_ExtCharacter* reallocateExtChars (Standard_Address theAddr,
39 const Standard_Size theLength)
41 return (Standard_ExtCharacter* )Standard::Reallocate (theAddr, (theLength + 1) * sizeof(Standard_ExtCharacter));
44 static const Standard_ExtCharacter NULL_EXTSTRING[1] = {0};
46 //! Returns the number of 16-bit code units in Unicode string
48 static Standard_Integer nbSymbols (const T* theUtfString)
50 Standard_Integer aNbCodeUnits = 0;
51 for (NCollection_UtfIterator<T> anIter (theUtfString); *anIter != 0; ++anIter)
53 aNbCodeUnits += anIter.AdvanceCodeUnitsUtf16();
58 //! Convert from wchar_t* to extended string.
59 //! Default implementation when size of wchar_t and extended char is different (e.g. Linux / UNIX).
60 template<size_t CharSize>
61 inline Standard_ExtCharacter* Standard_UNUSED fromWideString (const Standard_WideChar* theUtfString,
62 Standard_Integer& theLength)
64 theLength = nbSymbols (theUtfString);
65 Standard_ExtCharacter* aString = allocateExtChars (theLength);
66 NCollection_UtfWideIter anIterRead (theUtfString);
67 for (Standard_ExtCharacter* anIterWrite = aString; *anIterRead != 0; ++anIterRead)
69 anIterWrite = anIterRead.GetUtf (anIterWrite);
71 aString[theLength] = '\0';
75 //! Use memcpy() conversion when size is the same (e.g. on Windows).
77 inline Standard_ExtCharacter* Standard_UNUSED fromWideString<sizeof(Standard_ExtCharacter)> (const Standard_WideChar* theUtfString,
78 Standard_Integer& theLength)
80 for (theLength = 0; theUtfString[theLength] != L'\0'; ++theLength) {}
81 Standard_ExtCharacter* aString = allocateExtChars (theLength);
82 const Standard_Integer aSize = theLength * sizeof(Standard_ExtCharacter);
83 memcpy (aString, theUtfString, aSize);
84 aString[theLength] = '\0';
90 //-----------------------------------------------------------------------------
91 // Create an empty ExtendedString
92 // ----------------------------------------------------------------------------
93 TCollection_ExtendedString::TCollection_ExtendedString()
94 : mystring (allocateExtChars (0)),
100 //----------------------------------------------------------------------------
101 // Create an ExtendedString from a Standard_CString
102 //----------------------------------------------------------------------------
103 TCollection_ExtendedString::TCollection_ExtendedString
104 (const Standard_CString theString,
105 const Standard_Boolean isMultiByte)
109 if (theString == NULL)
111 throw Standard_NullObject("TCollection_ExtendedString : null parameter ");
116 mylength = nbSymbols (theString);
117 mystring = allocateExtChars (mylength);
118 mystring[mylength] = '\0';
119 if (ConvertToUnicode (theString))
125 mylength = (int)strlen(theString);
126 mystring = reallocateExtChars (mystring, mylength);
127 for (int aCharIter = 0; aCharIter < mylength; ++aCharIter)
129 mystring[aCharIter] = ToExtCharacter (theString[aCharIter]);
131 mystring[mylength] = '\0';
134 //---------------------------------------------------------------------------
135 // Create an ExtendedString from an ExtString
136 //--------------------------------------------------------------------------
137 TCollection_ExtendedString::TCollection_ExtendedString (const Standard_ExtString theString)
141 if (theString == NULL)
143 throw Standard_NullObject("TCollection_ExtendedString : null parameter ");
146 for (mylength = 0; theString[mylength] != '\0'; ++mylength) {}
147 mystring = allocateExtChars (mylength);
148 const Standard_Integer aSizeBytes = mylength * sizeof(Standard_ExtCharacter);
149 memcpy (mystring, theString, aSizeBytes);
150 mystring[mylength] = '\0';
153 // ----------------------------------------------------------------------------
154 // TCollection_ExtendedString
155 // ----------------------------------------------------------------------------
156 TCollection_ExtendedString::TCollection_ExtendedString (const Standard_WideChar* theStringUtf)
160 if (theStringUtf == NULL)
162 throw Standard_NullObject("TCollection_ExtendedString : null parameter ");
165 mystring = fromWideString<sizeof(Standard_WideChar)> (theStringUtf, mylength);
168 // ----------------------------------------------------------------------------
169 // Create an asciistring from a Standard_Character
170 // ----------------------------------------------------------------------------
171 TCollection_ExtendedString::TCollection_ExtendedString
172 (const Standard_Character aChar)
174 if ( aChar != '\0' ) {
176 mystring = allocateExtChars (1);
177 mystring[0] = ToExtCharacter(aChar);
183 mystring = allocateExtChars (0);
188 //--------------------------------------------------------------------------
189 // Create a string from a ExtCharacter
190 // ----------------------------------------------------------------------------
191 TCollection_ExtendedString::TCollection_ExtendedString
192 (const Standard_ExtCharacter aChar)
195 mystring = allocateExtChars (1);
200 // ----------------------------------------------------------------------------
201 // Create an AsciiString from a filler
202 // ----------------------------------------------------------------------------
203 TCollection_ExtendedString::TCollection_ExtendedString
204 (const Standard_Integer length,
205 const Standard_ExtCharacter filler )
207 mystring = allocateExtChars (length);
209 for (int i = 0 ; i < length ; i++) mystring[i] = filler;
210 mystring[mylength] = '\0';
213 // ----------------------------------------------------------------------------
214 // Create a String from an Integer
215 // ----------------------------------------------------------------------------
216 TCollection_ExtendedString::TCollection_ExtendedString
217 (const Standard_Integer aValue)
221 Sprintf(&CHN.t[0],"%d",aValue);
222 mylength = (int)strlen(CHN.t);
223 mystring = allocateExtChars (mylength);
224 for (int i = 0 ; i < mylength ; i++) mystring[i] = ToExtCharacter(CHN.t[i]);
225 mystring[mylength] = '\0';
228 // ----------------------------------------------------------------------------
229 // Create a String from a real
230 // ----------------------------------------------------------------------------
231 TCollection_ExtendedString::TCollection_ExtendedString
232 (const Standard_Real aValue)
236 Sprintf(&CHN.t[0],"%g",aValue);
237 mylength = (int)strlen( CHN.t );
238 mystring = allocateExtChars (mylength);
239 for (int i = 0 ; i < mylength ; i++) mystring[i] = ToExtCharacter(CHN.t[i]);
240 mystring[mylength] = '\0';
243 //-----------------------------------------------------------------------------
244 // create an extendedstring from an extendedstring
245 // ----------------------------------------------------------------------------
246 TCollection_ExtendedString::TCollection_ExtendedString
247 (const TCollection_ExtendedString& astring)
249 const Standard_Integer aSizeBytes = astring.mylength * sizeof(Standard_ExtCharacter);
250 mylength = astring.mylength;
251 mystring = allocateExtChars (astring.mylength);
252 memcpy (mystring, astring.mystring, aSizeBytes);
253 mystring[mylength] = '\0';
256 //---------------------------------------------------------------------------
257 // Create an extendedstring from an AsciiString
258 //---------------------------------------------------------------------------
259 TCollection_ExtendedString::TCollection_ExtendedString
260 (const TCollection_AsciiString& theString)
262 mylength = nbSymbols (theString.ToCString());
263 mystring = allocateExtChars (mylength);
264 mystring[mylength] = '\0';
265 if (ConvertToUnicode (theString.ToCString()))
270 mylength = theString.Length();
271 mystring = reallocateExtChars (mystring, mylength);
272 Standard_CString aCString = theString.ToCString();
273 for (Standard_Integer aCharIter = 0; aCharIter <= mylength; ++aCharIter)
275 mystring[aCharIter] = ToExtCharacter (aCString[aCharIter]);
277 mystring[mylength] = '\0';
280 // ----------------------------------------------------------------------------
282 // ----------------------------------------------------------------------------
283 void TCollection_ExtendedString::AssignCat (const TCollection_ExtendedString& theOther)
285 if (theOther.mylength == 0)
290 const Standard_Integer anOtherLength = theOther.mylength;
291 const Standard_Integer aNewlength = mylength + anOtherLength;
292 if (mystring != NULL)
294 mystring = reallocateExtChars (mystring, aNewlength);
295 memcpy (mystring + mylength, theOther.mystring, anOtherLength * sizeof(Standard_ExtCharacter));
299 mystring = allocateExtChars (aNewlength);
300 memcpy (mystring, theOther.mystring, anOtherLength * sizeof(Standard_ExtCharacter));
302 mylength = aNewlength;
303 mystring[mylength] = '\0';
306 // ----------------------------------------------------------------------------
308 // ----------------------------------------------------------------------------
309 TCollection_ExtendedString TCollection_ExtendedString::Cat
310 (const TCollection_ExtendedString& other) const
312 TCollection_ExtendedString res( mylength + other.mylength, 0 );
314 memcpy( res.mystring, mystring, mylength*2 );
315 if ( other.mylength > 0 )
316 memcpy( res.mystring + mylength, other.mystring, other.mylength*2 );
320 // ----------------------------------------------------------------------------
322 // ----------------------------------------------------------------------------
323 void TCollection_ExtendedString::ChangeAll(const Standard_ExtCharacter aChar,
324 const Standard_ExtCharacter NewChar)
326 for (int i = 0 ; i < mylength; i++)
327 if (mystring[i] == aChar) mystring[i] = NewChar;
330 // ----------------------------------------------------------------------------
332 // ----------------------------------------------------------------------------
333 void TCollection_ExtendedString::Clear()
340 Standard::Free (mystring);
342 mystring = allocateExtChars (mylength);
346 // ----------------------------------------------------------------------------
348 // ----------------------------------------------------------------------------
349 void TCollection_ExtendedString::Copy (const TCollection_ExtendedString& fromwhere)
352 if (fromwhere.mystring) {
353 const Standard_Integer newlength = fromwhere.mylength;
354 const Standard_Integer aSizeBytes = newlength * sizeof(Standard_ExtCharacter);
355 if (mystring != NULL)
357 mystring = reallocateExtChars (mystring, newlength);
360 mystring = allocateExtChars (newlength);
362 mylength = newlength;
363 memcpy (mystring, fromwhere.mystring, aSizeBytes);
364 mystring[mylength] = '\0';
376 // ----------------------------------------------------------------------------
378 // ----------------------------------------------------------------------------
379 TCollection_ExtendedString::~TCollection_ExtendedString()
381 if (mystring) Standard::Free(mystring);
385 //----------------------------------------------------------------------------
386 // Insert a character before 'where'th character
387 // ----------------------------------------------------------------------------
388 void TCollection_ExtendedString::Insert(const Standard_Integer where,
389 const Standard_ExtCharacter what)
391 if (where > mylength + 1 )
392 throw Standard_OutOfRange("TCollection_ExtendedString::Insert : "
393 "Parameter where is too big");
395 throw Standard_OutOfRange("TCollection_ExtendedString::Insert : "
396 "Parameter where is negative");
398 if (mystring != NULL)
400 mystring = reallocateExtChars (mystring, mylength + 1);
403 mystring = allocateExtChars (mylength + 1);
405 if (where != mylength +1) {
406 for (int i=mylength-1; i >= where-1; i--)
407 mystring[i+1] = mystring[i];
409 mystring[where-1] = what;
411 mystring[mylength] = '\0';
414 // ----------------------------------------------------------------------------
416 // ----------------------------------------------------------------------------
417 void TCollection_ExtendedString::Insert(const Standard_Integer where,
418 const TCollection_ExtendedString& what)
420 Standard_ExtString swhat = what.mystring;
421 if (where <= mylength + 1) {
422 Standard_Integer whatlength = what.mylength;
424 Standard_Integer newlength = mylength + whatlength;
427 mystring = reallocateExtChars (mystring, newlength);
430 mystring = allocateExtChars (newlength);
432 if (where != mylength +1) {
433 for (int i=mylength-1; i >= where-1; i--)
434 mystring[i+whatlength] = mystring[i];
436 for (int i=0; i < whatlength; i++)
437 mystring[where-1+i] = swhat[i];
439 mylength = newlength;
440 mystring[mylength] = '\0';
444 throw Standard_OutOfRange("TCollection_ExtendedString::Insert : "
445 "Parameter where is too big");
449 // ----------------------------------------------------------------------------
451 // ----------------------------------------------------------------------------
452 Standard_Boolean TCollection_ExtendedString::IsEqual
453 (const Standard_ExtString other) const
455 return ( memcmp( mystring, other, (mylength+1)*2 ) == 0 );
458 // ----------------------------------------------------------------------------
460 // ----------------------------------------------------------------------------
461 Standard_Boolean TCollection_ExtendedString::IsEqual
462 (const TCollection_ExtendedString& other) const
464 return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) == 0 );
467 // ----------------------------------------------------------------------------
469 // ----------------------------------------------------------------------------
470 Standard_Boolean TCollection_ExtendedString::IsDifferent
471 (const Standard_ExtString other ) const
473 return ( memcmp( mystring, other, (mylength+1)*2 ) != 0 );
476 // ----------------------------------------------------------------------------
478 // ----------------------------------------------------------------------------
479 Standard_Boolean TCollection_ExtendedString::IsDifferent
480 (const TCollection_ExtendedString& other) const
482 return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) != 0 );
485 // ----------------------------------------------------------------------------
487 // ----------------------------------------------------------------------------
488 Standard_Boolean TCollection_ExtendedString::IsLess
489 (const Standard_ExtString other) const
491 return ( memcmp( mystring, other, (mylength+1)*2 ) < 0 );
494 // ----------------------------------------------------------------------------
496 // ----------------------------------------------------------------------------
497 Standard_Boolean TCollection_ExtendedString::IsLess
498 (const TCollection_ExtendedString& other) const
500 return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) < 0 );
503 // ----------------------------------------------------------------------------
505 // ----------------------------------------------------------------------------
506 Standard_Boolean TCollection_ExtendedString::IsGreater
507 (const Standard_ExtString other) const
509 return ( memcmp( mystring, other, (mylength+1)*2 ) > 0 );
512 // ----------------------------------------------------------------------------
514 // ----------------------------------------------------------------------------
515 Standard_Boolean TCollection_ExtendedString::IsGreater
516 (const TCollection_ExtendedString& other) const
518 return ( memcmp( mystring, other.mystring, (mylength+1)*2 ) > 0 );
521 // ----------------------------------------------------------------------------
523 // ----------------------------------------------------------------------------
524 Standard_Boolean TCollection_ExtendedString::StartsWith (const TCollection_ExtendedString& theStartString) const
526 if (this == &theStartString)
531 return mylength >= theStartString.mylength
532 && memcmp (theStartString.mystring, mystring, theStartString.mylength) == 0;
535 // ----------------------------------------------------------------------------
537 // ----------------------------------------------------------------------------
538 Standard_Boolean TCollection_ExtendedString::EndsWith (const TCollection_ExtendedString& theEndString) const
540 if (this == &theEndString)
545 return mylength >= theEndString.mylength
546 && memcmp (theEndString.mystring, mystring + mylength - theEndString.mylength, theEndString.mylength) == 0;
549 // ----------------------------------------------------------------------------
551 // ----------------------------------------------------------------------------
552 Standard_Boolean TCollection_ExtendedString::IsAscii() const
554 for( Standard_Integer i = 0 ; i < mylength ; i++)
555 if (!IsAnAscii(mystring[i])) return Standard_False;
556 return Standard_True;
559 //------------------------------------------------------------------------
561 // ----------------------------------------------------------------------------
562 Standard_Integer TCollection_ExtendedString::Length() const
567 // ----------------------------------------------------------------------------
569 // ----------------------------------------------------------------------------
570 void TCollection_ExtendedString::Print(Standard_OStream& astream) const
572 // ASCII symbols (including extended Ascii) are printed as is;
573 // other Unicode characters are encoded as SGML numeric character references
574 for (Standard_Integer i = 0 ; i < mylength ; i++) {
575 Standard_ExtCharacter c = mystring[i];
577 astream << ToCharacter(c);
579 astream << "&#" << c << ";";
584 // ----------------------------------------------------------------------------
585 Standard_OStream& operator << (Standard_OStream& astream,
586 const TCollection_ExtendedString& astring)
588 astring.Print(astream);
592 // ----------------------------------------------------------------------------
594 // ----------------------------------------------------------------------------
595 void TCollection_ExtendedString::RemoveAll(const Standard_ExtCharacter what)
598 if (mylength == 0) return;
600 for (int i=0; i < mylength; i++)
601 if (mystring[i] != what) mystring[c++] = mystring[i];
603 mystring[mylength] = '\0';
606 // ----------------------------------------------------------------------------
608 // ----------------------------------------------------------------------------
609 void TCollection_ExtendedString::Remove (const Standard_Integer where,
610 const Standard_Integer ahowmany)
612 if (where+ahowmany <= mylength+1) {
614 for (i = where+ahowmany-1, j = where-1; i < mylength; i++, j++)
615 mystring[j] = mystring[i];
616 mylength -= ahowmany;
617 mystring[mylength] = '\0';
620 throw Standard_OutOfRange("TCollection_ExtendedString::Remove: "
621 "Too many characters to erase or "
622 "invalid starting value.");
625 // ----------------------------------------------------------------------------
627 // ----------------------------------------------------------------------------
628 Standard_Integer TCollection_ExtendedString::Search
629 (const TCollection_ExtendedString& what) const
631 Standard_Integer size = what.mylength;
632 Standard_ExtString swhat = what.mystring;
636 Standard_Boolean find = Standard_False;
637 while ( i < mylength-size+1 && !find) {
640 while (j < size && mystring[k++] == swhat[j++])
641 if (j == size) find = Standard_True;
648 // ----------------------------------------------------------------------------
650 // ----------------------------------------------------------------------------
651 Standard_Integer TCollection_ExtendedString::SearchFromEnd
652 (const TCollection_ExtendedString& what) const
654 Standard_Integer size = what.mylength;
656 Standard_ExtString swhat = what.mystring;
659 Standard_Boolean find = Standard_False;
660 while ( i >= size-1 && !find) {
663 while (j >= 0 && mystring[k--] == swhat[j--])
664 if (j == -1) find = Standard_True;
666 if (find) return i-size+3;
671 // ----------------------------------------------------------------------------
673 // ----------------------------------------------------------------------------
674 void TCollection_ExtendedString::SetValue(const Standard_Integer where,
675 const Standard_ExtCharacter what)
677 if (where > 0 && where <= mylength) {
678 mystring[where-1] = what;
681 throw Standard_OutOfRange("TCollection_ExtendedString::SetValue : parameter where");
685 // ----------------------------------------------------------------------------
687 // ----------------------------------------------------------------------------
688 void TCollection_ExtendedString::SetValue
689 (const Standard_Integer where,
690 const TCollection_ExtendedString& what)
692 if (where > 0 && where <= mylength+1) {
693 Standard_Integer size = what.mylength;
694 Standard_ExtString swhat = what.mystring;
696 if (size >= mylength){
698 mystring = reallocateExtChars (mystring, size);
701 mystring = allocateExtChars (size);
705 for (int i = where-1; i < size; i++)
706 mystring[i] = swhat[i-(where-1)];
707 mystring[mylength] = '\0';
710 throw Standard_OutOfRange("TCollection_ExtendedString::SetValue : "
714 // ----------------------------------------------------------------------------
716 // ----------------------------------------------------------------------------
717 TCollection_ExtendedString TCollection_ExtendedString::Split
718 (const Standard_Integer where)
720 if (where >= 0 && where < mylength) {
721 TCollection_ExtendedString res(&mystring[where]);
725 throw Standard_OutOfRange("TCollection_ExtendedString::Split index");
728 // ----------------------------------------------------------------------------
730 // ----------------------------------------------------------------------------
731 TCollection_ExtendedString TCollection_ExtendedString::Token
732 (const Standard_ExtString separators,
733 const Standard_Integer whichone) const
735 TCollection_ExtendedString res;
737 throw Standard_NullObject("TCollection_ExtendedString::Token : "
738 "parameter 'separators'");
741 Standard_PExtCharacter buftmp = allocateExtChars (mylength);
742 Standard_ExtCharacter aSep;
744 Standard_Boolean isSepFound = Standard_False, otherSepFound;
748 for (i = 0; i < whichone && j < mylength; i++) {
749 isSepFound = Standard_False;
753 // Avant de commencer il faut virer les saloperies devant
755 otherSepFound = Standard_True;
756 while (j < mylength && otherSepFound) {
758 otherSepFound = Standard_False;
759 aSep = separators[l];
761 if (aSep == mystring[j]) {
763 otherSepFound = Standard_True;
766 aSep = separators[l++];
769 if (otherSepFound) j++;
772 while (!isSepFound && k < mylength && j<mylength ) {
774 aSep = separators[l];
776 while (aSep != 0 && !isSepFound) {
777 if (aSep == mystring[j]) {
779 isSepFound = Standard_True;
782 buftmp[k] = mystring[j];
785 aSep = separators[l];
788 if(j==mylength) buftmp[k] = 0;
794 Standard::Free(buftmp);
797 Standard::Free(res.mystring);
798 res.mystring = buftmp;
799 for ( res.mylength=0; buftmp[res.mylength]; ++res.mylength );
800 res.mystring[res.mylength] = '\0';
805 // ----------------------------------------------------------------------------
807 // ----------------------------------------------------------------------------
808 Standard_ExtString TCollection_ExtendedString::ToExtString() const
810 if(mystring) return mystring;
811 return NULL_EXTSTRING;
814 // ----------------------------------------------------------------------------
816 // ----------------------------------------------------------------------------
817 void TCollection_ExtendedString::Trunc(const Standard_Integer ahowmany)
819 if (ahowmany < 0 || ahowmany > mylength)
820 throw Standard_OutOfRange("TCollection_ExtendedString::Trunc : "
821 "parameter 'ahowmany'");
823 mystring[mylength] = '\0';
826 // ----------------------------------------------------------------------------
828 // ----------------------------------------------------------------------------
829 Standard_ExtCharacter TCollection_ExtendedString::Value
830 (const Standard_Integer where) const
832 if (where > 0 && where <= mylength) {
833 if(mystring) return mystring[where-1];
836 throw Standard_OutOfRange("TCollection_ExtendedString::Value : "
841 //----------------------------------------------------------------------------
842 // Convert CString (including multibyte case) to UniCode representation
843 //----------------------------------------------------------------------------
844 Standard_Boolean TCollection_ExtendedString::ConvertToUnicode (const Standard_CString theStringUtf)
846 NCollection_Utf8Iter anIterRead (theStringUtf);
847 Standard_ExtCharacter* anIterWrite = mystring;
848 if (*anIterRead == 0)
851 return Standard_True;
854 for (; *anIterRead != 0; ++anIterRead)
856 if (!anIterRead.IsValid())
858 return Standard_False;
861 anIterWrite = anIterRead.GetUtf (anIterWrite);
863 return Standard_True;
866 //----------------------------------------------------------------------------
867 // Returns expected CString length in UTF8 coding.
868 //----------------------------------------------------------------------------
869 Standard_Integer TCollection_ExtendedString::LengthOfCString() const
871 Standard_Integer aSizeBytes = 0;
872 for (NCollection_Utf16Iter anIter (mystring); *anIter != 0; ++anIter)
874 aSizeBytes += anIter.AdvanceBytesUtf8();
879 //----------------------------------------------------------------------------
880 // Converts the internal <mystring> to UTF8 coding and returns length of the
882 //----------------------------------------------------------------------------
883 Standard_Integer TCollection_ExtendedString::ToUTF8CString(Standard_PCharacter& theCString) const
885 NCollection_Utf16Iter anIterRead (mystring);
886 Standard_Utf8Char* anIterWrite = theCString;
887 if (*anIterRead == 0)
893 for (; *anIterRead != 0; ++anIterRead)
895 anIterWrite = anIterRead.GetUtf (anIterWrite);
898 return Standard_Integer(anIterWrite - theCString);