File indexing completed on 2025-01-18 10:04:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef NCollection_UtfIterator_HeaderFile
0017 #define NCollection_UtfIterator_HeaderFile
0018
0019 #include <Standard_Handle.hxx>
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 template<typename Type>
0030 class NCollection_UtfIterator
0031 {
0032
0033 public:
0034
0035
0036
0037 NCollection_UtfIterator (const Type* theString)
0038 : myPosition(theString),
0039 myPosNext(theString),
0040 myCharIndex(0),
0041 myCharUtf32(0)
0042 {
0043 if (theString != NULL)
0044 {
0045 ++(*this);
0046 myCharIndex = 0;
0047 }
0048 }
0049
0050
0051 void Init (const Type* theString)
0052 {
0053 myPosition = theString;
0054 myPosNext = theString;
0055 myCharUtf32 = 0;
0056 if (theString != NULL)
0057 {
0058 ++(*this);
0059 }
0060 myCharIndex = 0;
0061 }
0062
0063
0064
0065 NCollection_UtfIterator& operator++()
0066 {
0067 myPosition = myPosNext;
0068 ++myCharIndex;
0069 readNext (static_cast<const typename CharTypeChooser<Type>::type*>(0));
0070 return *this;
0071 }
0072
0073
0074
0075 NCollection_UtfIterator operator++ (int )
0076 {
0077 NCollection_UtfIterator aCopy = *this;
0078 ++*this;
0079 return aCopy;
0080 }
0081
0082
0083 bool operator== (const NCollection_UtfIterator& theRight) const
0084 {
0085 return myPosition == theRight.myPosition;
0086 }
0087
0088
0089 bool IsValid() const
0090 {
0091 return myCharUtf32 <= UTF32_MAX_LEGAL;
0092 }
0093
0094
0095
0096 Standard_Utf32Char operator*() const
0097 {
0098 return myCharUtf32;
0099 }
0100
0101
0102 const Type* BufferHere() const { return myPosition; }
0103
0104
0105 Type* ChangeBufferHere() { return (Type* )myPosition; }
0106
0107
0108 const Type* BufferNext() const { return myPosNext; }
0109
0110
0111
0112 Standard_Integer Index() const
0113 {
0114 return myCharIndex;
0115 }
0116
0117
0118
0119
0120 Standard_Integer AdvanceBytesUtf8() const;
0121
0122
0123
0124
0125
0126 Standard_Integer AdvanceBytesUtf16() const;
0127
0128
0129
0130
0131
0132 Standard_Integer AdvanceCodeUnitsUtf16() const;
0133
0134
0135
0136 Standard_Integer AdvanceBytesUtf32() const
0137 {
0138 return Standard_Integer(sizeof(Standard_Utf32Char));
0139 }
0140
0141
0142
0143
0144
0145 Standard_Utf8Char* GetUtf8 (Standard_Utf8Char* theBuffer) const;
0146 Standard_Utf8UChar* GetUtf8 (Standard_Utf8UChar* theBuffer) const;
0147
0148
0149
0150
0151
0152 Standard_Utf16Char* GetUtf16 (Standard_Utf16Char* theBuffer) const;
0153
0154
0155
0156
0157
0158 Standard_Utf32Char* GetUtf32 (Standard_Utf32Char* theBuffer) const;
0159
0160
0161 template<typename TypeWrite>
0162 inline Standard_Integer AdvanceBytesUtf() const
0163 {
0164 return advanceBytes(static_cast<const typename CharTypeChooser<TypeWrite>::type*>(0));
0165 }
0166
0167
0168
0169
0170
0171 template<typename TypeWrite>
0172 inline TypeWrite* GetUtf (TypeWrite* theBuffer) const
0173 {
0174 return (TypeWrite*)(getUtf (reinterpret_cast<typename CharTypeChooser<TypeWrite>::type*>(theBuffer)));
0175 }
0176
0177 private:
0178
0179
0180
0181
0182
0183
0184
0185
0186 template <typename TypeChar>
0187 class CharTypeChooser :
0188 public std::conditional< sizeof(TypeChar) == 1, Standard_Utf8Char,
0189 typename std::conditional< sizeof(TypeChar) == 2, Standard_Utf16Char,
0190 typename std::conditional< sizeof(TypeChar) == 4, Standard_Utf32Char, void >::type >::type >
0191 {
0192 };
0193
0194
0195
0196 void readUTF8();
0197
0198
0199
0200 void readUTF16();
0201
0202
0203 void readNext (const Standard_Utf8Char*) { readUTF8(); }
0204 void readNext (const Standard_Utf16Char*) { readUTF16(); }
0205 void readNext (const Standard_Utf32Char*) { myCharUtf32 = *myPosNext++; }
0206
0207
0208 Standard_Integer advanceBytes (const Standard_Utf8Char*) const { return AdvanceBytesUtf8(); }
0209 Standard_Integer advanceBytes (const Standard_Utf16Char*) const { return AdvanceBytesUtf16(); }
0210 Standard_Integer advanceBytes (const Standard_Utf32Char*) const { return AdvanceBytesUtf32(); }
0211
0212
0213 Standard_Utf8Char* getUtf (Standard_Utf8Char* theBuffer) const { return GetUtf8 (theBuffer); }
0214 Standard_Utf16Char* getUtf (Standard_Utf16Char* theBuffer) const { return GetUtf16(theBuffer); }
0215 Standard_Utf32Char* getUtf (Standard_Utf32Char* theBuffer) const { return GetUtf32(theBuffer); }
0216
0217 private:
0218
0219 static const unsigned char UTF8_BYTES_MINUS_ONE[256];
0220 static const Standard_Utf32Char offsetsFromUTF8[6];
0221 static const unsigned char UTF8_FIRST_BYTE_MARK[7];
0222 static const Standard_Utf32Char UTF8_BYTE_MASK;
0223 static const Standard_Utf32Char UTF8_BYTE_MARK;
0224 static const Standard_Utf32Char UTF16_SURROGATE_HIGH_START;
0225 static const Standard_Utf32Char UTF16_SURROGATE_HIGH_END;
0226 static const Standard_Utf32Char UTF16_SURROGATE_LOW_START;
0227 static const Standard_Utf32Char UTF16_SURROGATE_LOW_END;
0228 static const Standard_Utf32Char UTF16_SURROGATE_HIGH_SHIFT;
0229 static const Standard_Utf32Char UTF16_SURROGATE_LOW_BASE;
0230 static const Standard_Utf32Char UTF16_SURROGATE_LOW_MASK;
0231 static const Standard_Utf32Char UTF32_MAX_BMP;
0232 static const Standard_Utf32Char UTF32_MAX_LEGAL;
0233
0234 private:
0235
0236 const Type* myPosition;
0237 const Type* myPosNext;
0238 Standard_Integer myCharIndex;
0239 Standard_Utf32Char myCharUtf32;
0240
0241 };
0242
0243 typedef NCollection_UtfIterator<Standard_Utf8Char> NCollection_Utf8Iter;
0244 typedef NCollection_UtfIterator<Standard_Utf16Char> NCollection_Utf16Iter;
0245 typedef NCollection_UtfIterator<Standard_Utf32Char> NCollection_Utf32Iter;
0246 typedef NCollection_UtfIterator<Standard_WideChar> NCollection_UtfWideIter;
0247
0248
0249 #include "NCollection_UtfIterator.lxx"
0250
0251 #endif