0023864: An & symbol is read incorrectly from a XML Ocaf file
[occt.git] / src / Standard / Standard_String.hxx
1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 //
4 // The content of this file is subject to the Open CASCADE Technology Public
5 // License Version 6.5 (the "License"). You may not use the content of this file
6 // except in compliance with the License. Please obtain a copy of the License
7 // at http://www.opencascade.org and read it completely before using this file.
8 //
9 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 //
12 // The Original Code and all software distributed under the License is
13 // distributed on an "AS IS" basis, without warranty of any kind, and the
14 // Initial Developer hereby disclaims all such warranties, including without
15 // limitation, any warranties of merchantability, fitness for a particular
16 // purpose or non-infringement. Please see the License for the specific terms
17 // and conditions governing the rights and limitations under the License.
18
19
20 #ifndef _Standard_String_HeaderFile
21 # define _Standard_String_HeaderFile
22
23 # ifndef _Standard_TypeDef_HeaderFile
24 #  include <Standard_TypeDef.hxx>
25 # endif
26
27 #define INF(X,Y) (((X)<(Y))?(X):(Y))
28
29 # if OptJr
30
31 #define STRLEN(s,i) {(i) = 0;while((s)[(i)++] != '\0');(i)--;}
32 #define EXTSTRLEN(s,i) {(i) = 0;while((s)[(i)++] != 0);(i)--;}
33 #define STRCPY(s1,s2,i) {for(LoopIndex=0; LoopIndex<(i); LoopIndex++)(s1)[LoopIndex] = (s2)[LoopIndex];}
34 #define STRCAT(s1,i,s2,j) {for(LoopIndex=0; LoopIndex<(j); LoopIndex++) (s1)[(i)+LoopIndex] = (s2)[LoopIndex];}
35
36 //#   ifdef __Standard_DLL
37 #   ifdef _Standard_CString_SourceFile
38 __Standard_API const Standard_Integer *MaskEndIntegerString = static_MaskEndIntegerString ;
39 #   else
40 __Standard_APIEXTERN const Standard_Integer *MaskEndIntegerString ;
41 #   endif
42 //#   else
43 //Standard_IMPORT const Standard_Integer *MaskEndIntegerString ;
44 //#   endif
45
46 // JR 16-jul-1998
47 // Algorithme utilise pour le calcul des longueurs de strings
48 // Je suppose que les octets sont de l'ascii 7 bits.
49 // Si un des octets d'un mot est a zero et si on soustrait 0x01010101 a ce
50 //    mot, l'octet a zero change de signe.
51 // Reciproquement si (( Word - 0x01010101 ) & 0x80808080 ) != 0
52 //    alors Word a un octet a zero.
53
54 // Si on a des octets negatifs et si on applique le resultat ci-dessus a
55 // ( Word & 0x7f7f7f7f ), cela sera vrai sauf si un des octets vaut 0x80
56 // auquel cas on trouvera un octet a zero a tort.
57
58 // Conclusion : il suffit de controler la presence d'un octet a zero a partir
59 //              du debut du mot ou l'on croira en avoir trouve un pour traiter
60 //              correctement les octets qui valent 0x80.
61
62 // La meme chose est vraie pour les extendedstrings.
63
64 // D'autre part afin d'accelerer les traitements, on teste si les chaines
65 // sont alignees sur des mots de 32 bits ( AND de l'adresse avec 3 ) ou
66 // sont alignees sur des shorts de 16 bits ( AND de l'adresse avec 1 ).
67
68 inline Standard_Boolean CStringTestOfZero(const Standard_Integer aString )
69 {
70  return ( ((( aString & 0x7f7f7f7f ) - \
71             0x01010101 ) & 0x80808080 ) == 0 ) ;
72 }
73
74 inline Standard_Boolean HalfCStringTestOfZero(const Standard_ExtCharacter anExtCharacter )
75 {
76  return ( ((( anExtCharacter & 0x7f7f ) - 0x0101 ) & 0x8080 ) == 0 ) ;
77 }
78
79 inline Standard_Boolean ExtStringTestOfZero(const Standard_Integer anExtString )
80 {
81  return ( ((( anExtString & 0x7fff7fff ) - \
82             0x00010001 ) & 0x80008000 ) == 0 ) ;
83 }
84
85 #define STRINGLEN( aString , LoopIndex ) { \
86  if ((ptrdiff_t(aString) & 1) == 0) { \
87    LoopIndex = 0 ; \
88    if ((ptrdiff_t(aString) & 3) == 0) { \
89      while (CStringTestOfZero(((Standard_Integer *)aString)[LoopIndex++])); \
90      LoopIndex = ( LoopIndex << 2 ) - 4 ; \
91    } \
92    else { \
93      while (HalfCStringTestOfZero(((Standard_ExtCharacter *)aString)[LoopIndex++])); \
94      LoopIndex = ( LoopIndex << 1 ) - 2 ; \
95    } \
96    while (aString[LoopIndex++] != '\0'); \
97    LoopIndex -= 1 ; \
98  } \
99  else \
100    STRLEN( aString , LoopIndex ) ; \
101 }
102
103 #define EXTSTRINGLEN( anExtString , LoopIndex ) { \
104  if ((ptrdiff_t(anExtString) & 3) == 0) { \
105    LoopIndex = 0 ; \
106    while (ExtStringTestOfZero(((Standard_Integer *)anExtString)[LoopIndex++]));\
107    LoopIndex = ( LoopIndex << 1 ) - 2 ; \
108    if ( anExtString[ LoopIndex ] != 0 ) \
109      LoopIndex += 1 ; \
110  } \
111  else \
112    EXTSTRLEN( anExtString , LoopIndex ) ; \
113 }
114
115 // aStringOut is an AsciiString and is word aligned
116 // aStringIn is a CString and may be not word aligned
117 #define CSTRINGCOPY( aStringOut , aStringIn , aStringLen ) { \
118  Standard_Integer LoopIndex = (Standard_Integer)(ptrdiff_t(aStringIn) & 3) ; \
119  if ( ( LoopIndex & 1 ) == 0 ) { \
120    if ( LoopIndex == 0 ) { \
121      for (; LoopIndex <= ( aStringLen >> 2 ) ; LoopIndex++ ) { \
122         ((Standard_Integer *) aStringOut )[ LoopIndex ] = \
123                    ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \
124         } \
125    } \
126    else { \
127      for ( LoopIndex = 0 ; LoopIndex <= ( aStringLen >> 1) ; LoopIndex++ ) { \
128         ((Standard_ExtCharacter *) aStringOut )[ LoopIndex ] = \
129                       ((Standard_ExtCharacter *) aStringIn )[ LoopIndex ] ; \
130         } \
131    } \
132  } \
133  else \
134    STRCPY( aStringOut , aStringIn , aStringLen + 1 ) ; \
135 }
136
137 // aStringOut is an AsciiString and is word aligned
138 // aStringIn is an AsciiString and is word aligned
139 #define ASCIISTRINGCOPY( aStringOut , aStringIn , aStringLen ) { \
140  Standard_Integer LoopIndex ; \
141  LoopIndex = 0 ; \
142  for(; LoopIndex <= ( aStringLen >> 2 ) ; LoopIndex++ ) { \
143     ((Standard_Integer *) aStringOut )[ LoopIndex ] = \
144                     ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \
145     } \
146 }
147
148 #define STRINGCAT( aStringOut , aStringOutLen , aStringIn , aStringInLen ) { \
149  Standard_Integer LoopIndex ; \
150  if ((ptrdiff_t(&aStringOut[ aStringOutLen ]) & 1) == 0 && \
151      (ptrdiff_t(aStringIn) & 1 ) == 0 ) { \
152    LoopIndex = 0 ; \
153    if ((ptrdiff_t(&aStringOut[ aStringOutLen ]) & 3 ) == 0 && \
154        (ptrdiff_t(aStringIn) & 3 ) == 0 ) { \
155      for (; LoopIndex <= ( aStringInLen >> 2 ) ; LoopIndex++ ) { \
156         ((Standard_Integer *) aStringOut )[ ( aStringOutLen >> 2 ) + \
157          LoopIndex ] = ((Standard_Integer *) aStringIn )[ LoopIndex ] ; \
158         } \
159    } \
160    else { \
161      for (; LoopIndex <= ( aStringInLen >> 1 ) ; LoopIndex++ ) { \
162         ((Standard_ExtCharacter *) aStringOut )[ ( aStringOutLen >> 1 ) + \
163          LoopIndex ] = ((Standard_ExtCharacter *) aStringIn )[ LoopIndex ] ; \
164         } \
165    } \
166  } \
167  else \
168    STRCPY( &aStringOut[ aStringOutLen ] , aStringIn , aStringInLen + 1 ) ; \
169 }
170
171 // aString is an AsciiString and is word aligned
172 // anOtherString is aCString and may be not word aligned
173 // aStringLen is the length of aString and anOtherString
174 #define CSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \
175  KEqual = Standard_True ; \
176  Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \
177  if ( ( LoopIndex & 1 ) == 0 ) { \
178    if ( LoopIndex == 0 ) { \
179      for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
180         if (((Standard_Integer *) aString )[ LoopIndex ] != \
181             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
182           KEqual = Standard_False ; \
183           break ; \
184           } \
185         } \
186      if ( KEqual == Standard_True && \
187           (((Standard_Integer *) aString )[ LoopIndex ] & \
188            MaskEndIntegerString[ aStringLen & 3 ]) != \
189           (((Standard_Integer *) anOtherString )[ LoopIndex ] & \
190            MaskEndIntegerString[ aStringLen & 3 ] ) ) \
191        KEqual = Standard_False ; \
192    } \
193    else { \
194      for ( LoopIndex = 0 ; LoopIndex < (( aStringLen + 1) >> 1) ; LoopIndex++ ) { \
195         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
196             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
197           KEqual = Standard_False ; \
198           break ; \
199           } \
200         } \
201    } \
202  } \
203  else { \
204    for ( LoopIndex = 0 ; LoopIndex < aStringLen ; LoopIndex++ ) { \
205       if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
206         KEqual = Standard_False ; \
207         break ; \
208       } \
209    } \
210  } \
211 }
212
213 // aString is an AsciiString and is word aligned
214 // anOtherString is aCString and may be not word aligned
215 // aStringLen is the length of aString.
216 // The length of anOtherString is unknown
217 #define LCSTRINGEQUAL( aString , aStringLen , anOtherString , KEqual ) { \
218  KEqual = Standard_True ; \
219  Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \
220  if ( ( LoopIndex & 1 ) == 0 ) { \
221    if ( LoopIndex == 0 ) { \
222      for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
223         if (((Standard_Integer *) aString )[ LoopIndex ] != \
224             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
225           KEqual = Standard_False ; \
226           break ; \
227         } \
228      } \
229      LoopIndex = ( LoopIndex << 2) ; \
230    } \
231    else { \
232      for ( LoopIndex = 0 ; LoopIndex < (( aStringLen + 1) >> 1) ; LoopIndex++ ) { \
233         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
234             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
235           KEqual = Standard_False ; \
236           break ; \
237         } \
238      } \
239      LoopIndex = ( LoopIndex << 1) ; \
240    } \
241    if ( KEqual ) { \
242      for (; LoopIndex <= aStringLen ; LoopIndex++ ) { \
243           if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) { \
244             KEqual = Standard_False ; \
245             break ; \
246           } \
247      } \
248    } \
249  } \
250  else { \
251    for ( LoopIndex = 0 ; LoopIndex <= aStringLen ; LoopIndex++ ) { \
252       if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
253         KEqual = Standard_False ; \
254         break ; \
255       } \
256    } \
257  } \
258 }
259
260 // aString is an AsciiString and is word aligned
261 // anOtherString is an AsciiString and is word aligned
262 #define ASCIISTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \
263  Standard_Integer LoopIndex ; \
264  KEqual = Standard_True ; \
265  LoopIndex = 0 ; \
266  for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
267     if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
268          ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
269       KEqual = Standard_False ; \
270       break ; \
271       } \
272     } \
273  if ( KEqual == Standard_True && \
274       (((Standard_Integer *) aString )[ LoopIndex ] & \
275        MaskEndIntegerString[ aStringLen & 3 ]) != \
276       (((Standard_Integer *) anOtherString )[ LoopIndex ] & \
277        MaskEndIntegerString[ aStringLen & 3 ] ) ) \
278    KEqual = Standard_False ; \
279 }
280
281 // aString is an AsciiString and is word aligned
282 // anOtherString is aCString and may be not word aligned
283 #define CSTRINGLESS( aString , aStringLen , anOtherString , \
284                      anOtherStringLen , MinLen , KLess ) { \
285  Standard_Integer LoopIndex ; \
286  KLess = Standard_True ; \
287  LoopIndex = ptrdiff_t(anOtherString) & 3 ; \
288  if ( ( LoopIndex & 1 ) == 0 && MinLen > 3 ) { \
289    if ( LoopIndex == 0 ) { \
290      for (; LoopIndex < ( MinLen >> 2 ) ; LoopIndex++ ) { \
291         if (((Standard_Integer *) aString )[ LoopIndex ] != \
292             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
293           LoopIndex++ ; \
294           break ; \
295           } \
296         } \
297      LoopIndex = ( LoopIndex - 1 ) << 2 ; \
298    } \
299    else { \
300      for ( LoopIndex = 0 ; LoopIndex < ( MinLen >> 1 ) ; LoopIndex++ ) { \
301         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
302             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
303           LoopIndex++ ; \
304           break ; \
305           } \
306         } \
307      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
308    } \
309  } \
310  else \
311    LoopIndex = 0 ; \
312  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
313     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
314       break ; \
315     } \
316  if ( LoopIndex != MinLen ) { \
317    if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
318      KLess = Standard_False ; \
319  } \
320  else if ( aStringLen >= anOtherStringLen ) \
321    KLess = Standard_False ; \
322 }
323
324 // aString is an AsciiString and is word aligned
325 // anOtherString is aCString and may be not word aligned
326 // aStringLen is the length of aString
327 // The length of anOtherString is unknown
328 #define LCSTRINGLESS( aString , aStringLen , anOtherString , KLess ) { \
329  KLess = Standard_True ; \
330  Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \
331  if ( ( LoopIndex & 1 ) == 0 && aStringLen > 3 ) { \
332    if ( LoopIndex == 0 ) { \
333      for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
334         if (((Standard_Integer *) aString )[ LoopIndex ] != \
335             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
336           LoopIndex++ ; \
337           break ; \
338           } \
339         } \
340      LoopIndex = ( LoopIndex - 1 ) << 2 ; \
341    } \
342    else { \
343      for ( LoopIndex = 0 ; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
344         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
345             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
346           LoopIndex++ ; \
347           break ; \
348           } \
349         } \
350      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
351    } \
352  } \
353  else \
354    LoopIndex = 0 ; \
355  for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
356     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
357       break ; \
358     } \
359  if ( LoopIndex != aStringLen ) { \
360    if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
361      KLess = Standard_False ; \
362  } \
363  else if ( anOtherString[ LoopIndex ] == '\0' ) \
364    KLess = Standard_False ; \
365 }
366
367 // aString is an AsciiString and is word aligned
368 // anOtherString is an AsciiString and is word aligned
369 #define ASCIISTRINGLESS( aString , aStringLen , anOtherString , \
370                          anOtherStringLen , MinLen , KLess ) { \
371  Standard_Integer LoopIndex ; \
372  KLess = Standard_True ; \
373  LoopIndex = 0 ; \
374  if ( MinLen > 3 ) { \
375    for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
376       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
377            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
378         LoopIndex++ ; \
379         break ; \
380         } \
381       } \
382    LoopIndex = ( LoopIndex - 1 ) << 2 ; \
383  } \
384  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
385     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
386       break ; \
387     } \
388  if ( LoopIndex != MinLen ) { \
389    if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
390      KLess = Standard_False ; \
391  } \
392  else if ( aStringLen >= anOtherStringLen ) \
393    KLess = Standard_False ; \
394 }
395
396 // aString is an AsciiString and is word aligned
397 // anOtherString is aCString and may be not word aligned
398 #define CSTRINGGREATER( aString , aStringLen , anOtherString , \
399                         anOtherStringLen , MinLen , KGreater ) { \
400  KGreater = Standard_True ; \
401  Standard_Integer LoopIndex = Standard_Integer(ptrdiff_t(anOtherString) & 3); \
402  if ( ( LoopIndex & 1 ) == 0 && MinLen > 3 ) { \
403    if ( LoopIndex == 0 ) { \
404      for (; LoopIndex < ( MinLen >> 2 ) ; LoopIndex++ ) { \
405         if (((Standard_Integer *) aString )[ LoopIndex ] != \
406             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
407           LoopIndex++ ; \
408           break ; \
409           } \
410         } \
411      LoopIndex = ( LoopIndex - 1 ) << 2 ; \
412    } \
413    else { \
414      for ( LoopIndex = 0 ; LoopIndex < ( MinLen >> 1 ) ; LoopIndex++ ) { \
415         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
416             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
417           LoopIndex++ ; \
418           break ; \
419           } \
420         } \
421      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
422    } \
423  } \
424  else \
425    LoopIndex = 0 ; \
426  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
427     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
428       break ; \
429     } \
430  if ( LoopIndex != MinLen ) { \
431    if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
432      KGreater = Standard_False ; \
433  } \
434  else if ( aStringLen <= anOtherStringLen ) \
435    KGreater = Standard_False ; \
436 }
437
438 // aString is an AsciiString and is word aligned
439 // anOtherString is aCString and may be not word aligned
440 // aStringLen is the length of aString
441 // The length of anOtherString is unknown
442 #define LCSTRINGGREATER( aString , aStringLen , anOtherString , KGreater ) { \
443  Standard_Integer LoopIndex ; \
444  KGreater = Standard_True ; \
445  LoopIndex = (Standard_Integer)(ptrdiff_t(anOtherString) & 3) ; \
446  if ( ( LoopIndex & 1 ) == 0 && aStringLen > 3 ) { \
447    if ( LoopIndex == 0 ) { \
448      for (; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
449         if (((Standard_Integer *) aString )[ LoopIndex ] != \
450             ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
451           LoopIndex++ ; \
452           break ; \
453           } \
454         } \
455      LoopIndex = ( LoopIndex - 1 ) << 2 ; \
456    } \
457    else { \
458      for ( LoopIndex = 0 ; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
459         if (((Standard_ExtCharacter *) aString )[ LoopIndex ] != \
460             ((Standard_ExtCharacter *) anOtherString )[ LoopIndex ] ) { \
461           LoopIndex++ ; \
462           break ; \
463           } \
464         } \
465      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
466    } \
467  } \
468  else \
469    LoopIndex = 0 ; \
470  for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
471     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
472       break ; \
473     } \
474  if ( LoopIndex != aStringLen ) { \
475    if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
476      KGreater = Standard_False ; \
477  } \
478  else \
479    KGreater = Standard_False ; \
480 }
481
482 // aString is an AsciiString and is word aligned
483 // anOtherString is an AsciiString and is word aligned
484 #define ASCIISTRINGGREATER( aString , aStringLen , anOtherString , \
485                             anOtherStringLen , MinLen , KGreater ) { \
486  Standard_Integer LoopIndex ; \
487  KGreater = Standard_True ; \
488  LoopIndex = 0 ; \
489  if ( MinLen > 3 ) { \
490    for(; LoopIndex < ( aStringLen >> 2 ) ; LoopIndex++ ) { \
491       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
492            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
493         LoopIndex++ ; \
494         break ; \
495         } \
496       } \
497    LoopIndex = ( LoopIndex - 1 ) << 2 ; \
498  } \
499  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
500     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
501       break ; \
502     } \
503  if ( LoopIndex != MinLen ) { \
504    if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
505      KGreater = Standard_False ; \
506  } \
507  else if ( aStringLen <= anOtherStringLen ) \
508    KGreater = Standard_False ; \
509 }
510
511 // anExtStringOut is an ExtendedString and is word aligned
512 // anExtStringIn is an ExtString and may be not word aligned
513 #define EXTSTRINGCOPY( anExtStringOut , anExtStringIn , anExtStringLen ) { \
514  Standard_Integer LoopIndex ; \
515  LoopIndex = (Standard_Integer)(ptrdiff_t(anExtStringIn) & 3) ; \
516  if ( LoopIndex == 0 ) { \
517    for (; LoopIndex <= ( anExtStringLen >> 1 ) ; LoopIndex++ ) { \
518       ((Standard_Integer *) anExtStringOut )[ LoopIndex ] = \
519                    ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \
520       } \
521  } \
522  else \
523    STRCPY( anExtStringOut , anExtStringIn , anExtStringLen + 1 ) ; \
524 }
525
526 // anExtStringOut is an ExtendedString and is word aligned
527 // anExtStringIn is an ExtendedString and is word aligned
528 // We copy the ending zero and possibly the ExtCharacter folowing
529 #define EXTENDEDSTRINGCOPY( anExtStringOut , anExtStringIn , anExtStringLen ) {\
530  Standard_Integer LoopIndex ; \
531  for (LoopIndex = 0 ; LoopIndex <= ( anExtStringLen >> 1 ) ; LoopIndex++ ) { \
532     ((Standard_Integer *) anExtStringOut )[ LoopIndex ] = \
533                 ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \
534  } \
535 }
536
537 // anExtStringOut is an ExtendedString and is word aligned
538 // anExtStringIn is an ExtendedString and is word aligned
539 // We copy the ending zero and possibly the ExtCharacter folowing
540 #define EXTENDEDSTRINGCAT( anExtStringOut , anExtStringOutLen , anExtStringIn , anExtStringInLen ) {\
541  Standard_Integer LoopIndex ; \
542  if ( ( anExtStringOutLen & 1 ) == 0 ) { \
543    for (LoopIndex = 0 ; LoopIndex <= ( anExtStringInLen >> 1 ) ; LoopIndex++ ) { \
544       ((Standard_Integer *) anExtStringOut )[ ( anExtStringOutLen >> 1 ) + LoopIndex ] = \
545                   ((Standard_Integer *) anExtStringIn )[ LoopIndex ] ; \
546       } \
547  } \
548  else { \
549    STRCAT( anExtStringOut , anExtStringOutLen , anExtStringIn , anExtStringInLen + 1 ) ; \
550  } \
551 }
552
553 // aString is an ExtendedString and is word aligned
554 // anOtherString is an ExtString and may be not word aligned
555 // We compare the last two ExtCharacters or the last ExtCharacter and the
556 // ending zero if it's word aligned
557 // aStringLen is the length of aString and anOtherString
558 #define EXTSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \
559  Standard_Integer LoopIndex ; \
560  KEqual = Standard_True ; \
561  LoopIndex = 0 ; \
562  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
563    for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \
564       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
565            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
566         KEqual = Standard_False ; \
567         break ; \
568         } \
569       } \
570  } \
571  else { \
572    for(; LoopIndex < aStringLen ; LoopIndex++ ) { \
573       if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
574         KEqual = Standard_False ; \
575         break ; \
576         } \
577       } \
578  } \
579 }
580
581 // aString is an ExtendedString and is word aligned
582 // anOtherString is an ExtString and may be not word aligned
583 // We compare the last two ExtCharacters or the last ExtCharacter and the
584 // ending zero if it's word aligned
585 // aStringLen is the length of aString.
586 // The length of anOtherString is unknown
587 #define LEXTSTRINGEQUAL( aString , aStringLen , anOtherString , KEqual ) { \
588  Standard_Integer LoopIndex ; \
589  KEqual = Standard_True ; \
590  LoopIndex = 0 ; \
591  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
592    for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \
593       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
594            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
595         KEqual = Standard_False ; \
596         break ; \
597       } \
598    } \
599    if ( KEqual && aString [ aStringLen ] != anOtherString [ aStringLen ] ) \
600      KEqual = Standard_False ; \
601  } \
602  else { \
603    for(; LoopIndex <= aStringLen ; LoopIndex++ ) { \
604       if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
605         KEqual = Standard_False ; \
606         break ; \
607       } \
608    } \
609  } \
610 }
611
612 // aString is an ExtendedString and is word aligned
613 // anOtherString is an ExtendedString and is word aligned
614 // We compare the last two ExtCharacters or the last ExtCharacter and the
615 // ending zero
616 #define EXTENDEDSTRINGEQUAL( aString , anOtherString , aStringLen , KEqual ) { \
617  Standard_Integer LoopIndex ; \
618  KEqual = Standard_True ; \
619  LoopIndex = 0 ; \
620  for(; LoopIndex < (( aStringLen + 1) >> 1 ) ; LoopIndex++ ) { \
621     if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
622          ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
623       KEqual = Standard_False ; \
624       break ; \
625       } \
626     } \
627 }
628
629 // aString is an ExtendedString and is word aligned
630 // anOtherString is an ExtendedString and may be not word aligned
631 #define EXTSTRINGLESS( aString , aStringLen , anOtherString , \
632                        anOtherStringLen , MinLen , KLess ) { \
633  Standard_Integer LoopIndex ; \
634  KLess = Standard_True ; \
635  LoopIndex = 0 ; \
636  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
637    if ( MinLen > 1 ) { \
638      for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
639         if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
640              ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
641           LoopIndex++ ; \
642           break ; \
643           } \
644         } \
645      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
646    } \
647    for (; LoopIndex < MinLen ; LoopIndex++ ) { \
648       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
649         break ; \
650       } \
651    if ( LoopIndex != MinLen ) { \
652      if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
653        KLess = Standard_False ; \
654    } \
655    else if ( aStringLen >= anOtherStringLen ) \
656      KLess = Standard_False ; \
657  } \
658  else { \
659    if ( MinLen > 1 ) { \
660      for(; LoopIndex < aStringLen ; LoopIndex++ ) { \
661         if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
662           LoopIndex++ ; \
663           break ; \
664           } \
665         } \
666      LoopIndex = LoopIndex - 1 ; \
667    } \
668    for (; LoopIndex < MinLen ; LoopIndex++ ) { \
669       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
670         break ; \
671       } \
672    if ( LoopIndex != MinLen ) { \
673      if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
674        KLess = Standard_False ; \
675    } \
676    else if ( aStringLen >= anOtherStringLen ) \
677      KLess = Standard_False ; \
678  } \
679 }
680
681 // aString is an ExtendedString and is word aligned
682 // anOtherString is an ExtendedString and may be not word aligned
683 // aStringLen is the length of aString
684 // The length of anOtherString is unknown
685 #define LEXTSTRINGLESS( aString , aStringLen , anOtherString , KLess ) { \
686  Standard_Integer LoopIndex ; \
687  KLess = Standard_True ; \
688  LoopIndex = 0 ; \
689  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
690    if ( aStringLen > 1 ) { \
691      for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
692         if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
693              ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
694           LoopIndex++ ; \
695           break ; \
696           } \
697         } \
698      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
699    } \
700    for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
701       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
702         break ; \
703       } \
704    if ( LoopIndex != aStringLen ) { \
705      if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
706        KLess = Standard_False ; \
707    } \
708    else if ( anOtherString[ LoopIndex ] == 0 ) \
709      KLess = Standard_False ; \
710  } \
711  else { \
712    if ( aStringLen > 1 ) { \
713      for(; LoopIndex < aStringLen ; LoopIndex++ ) { \
714         if ( aString [ LoopIndex ] != anOtherString [ LoopIndex ] ) { \
715           LoopIndex++ ; \
716           break ; \
717           } \
718         } \
719      LoopIndex = LoopIndex - 1 ; \
720    } \
721    for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
722       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
723         break ; \
724       } \
725    if ( LoopIndex != aStringLen ) { \
726      if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
727        KLess = Standard_False ; \
728    } \
729    else if ( anOtherString[ LoopIndex ] == 0 ) \
730      KLess = Standard_False ; \
731  } \
732 }
733
734 // aString is an ExtendedString and is word aligned
735 // anOtherString is an ExtendedString and is word aligned
736 #define EXTENDEDSTRINGLESS( aString , aStringLen , anOtherString , \
737                             anOtherStringLen , MinLen , KLess ) { \
738  Standard_Integer LoopIndex ; \
739  KLess = Standard_True ; \
740  LoopIndex = 0 ; \
741  if ( MinLen > 1 ) { \
742    for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
743       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
744            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
745         LoopIndex++ ; \
746         break ; \
747         } \
748       } \
749    LoopIndex = ( LoopIndex - 1 ) << 1 ; \
750  } \
751  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
752     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
753       break ; \
754     } \
755  if ( LoopIndex != MinLen ) { \
756    if ( aString[ LoopIndex ] > anOtherString[ LoopIndex ] ) \
757      KLess = Standard_False ; \
758  } \
759  else if ( aStringLen >= anOtherStringLen ) \
760    KLess = Standard_False ; \
761 }
762
763 // aString is an ExtendedString and is word aligned
764 // anOtherString is an ExtendedString and may be not word aligned
765 #define EXTSTRINGGREATER( aString , aStringLen , anOtherString , \
766                           anOtherStringLen , MinLen , KGreater ) { \
767  Standard_Integer LoopIndex ; \
768  KGreater = Standard_True ; \
769  LoopIndex = 0 ; \
770  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
771    if ( MinLen > 1 ) { \
772      for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
773         if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
774              ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
775           LoopIndex++ ; \
776           break ; \
777           } \
778         } \
779      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
780    } \
781    for (; LoopIndex < MinLen ; LoopIndex++ ) { \
782       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
783         break ; \
784       } \
785    if ( LoopIndex != MinLen ) { \
786      if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
787        KGreater = Standard_False ; \
788    } \
789    else if ( aStringLen <= anOtherStringLen ) \
790      KGreater = Standard_False ; \
791  } \
792  else { \
793    if ( MinLen > 1 ) { \
794      for(; LoopIndex < aStringLen ; LoopIndex++ ) { \
795         if ( aString [ LoopIndex ] !=  anOtherString [ LoopIndex ] ) { \
796           LoopIndex++ ; \
797           break ; \
798           } \
799         } \
800      LoopIndex = LoopIndex - 1 ; \
801    } \
802    for (; LoopIndex < MinLen ; LoopIndex++ ) { \
803       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
804         break ; \
805       } \
806    if ( LoopIndex != MinLen ) { \
807      if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
808        KGreater = Standard_False ; \
809    } \
810    else if ( aStringLen <= anOtherStringLen ) \
811      KGreater = Standard_False ; \
812  } \
813 }
814
815 // aString is an ExtendedString and is word aligned
816 // anOtherString is an ExtendedString and may be not word aligned
817 // aStringLen is the length of aString
818 // The length of anOtherString is unknown
819 #define LEXTSTRINGGREATER( aString , aStringLen , anOtherString , KGreater ) { \
820  Standard_Integer LoopIndex ; \
821  KGreater = Standard_True ; \
822  LoopIndex = 0 ; \
823  if ((ptrdiff_t(anOtherString) & 3 ) == 0 ) { \
824    if ( aStringLen > 1 ) { \
825      for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
826         if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
827              ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
828           LoopIndex++ ; \
829           break ; \
830           } \
831         } \
832      LoopIndex = ( LoopIndex - 1 ) << 1 ; \
833    } \
834    for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
835       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
836         break ; \
837       } \
838    if ( LoopIndex != aStringLen ) { \
839      if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
840        KGreater = Standard_False ; \
841    } \
842    else \
843      KGreater = Standard_False ; \
844  } \
845  else { \
846    if ( aStringLen > 1 ) { \
847      for(; LoopIndex < aStringLen ; LoopIndex++ ) { \
848         if ( aString [ LoopIndex ] !=  anOtherString [ LoopIndex ] ) { \
849           LoopIndex++ ; \
850           break ; \
851           } \
852         } \
853      LoopIndex = LoopIndex - 1 ; \
854    } \
855    for (; LoopIndex < aStringLen ; LoopIndex++ ) { \
856       if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
857         break ; \
858       } \
859    if ( LoopIndex != aStringLen ) { \
860      if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
861        KGreater = Standard_False ; \
862    } \
863    else \
864      KGreater = Standard_False ; \
865  } \
866 }
867
868 // aString is an ExtendedString and is word aligned
869 // anOtherString is an ExtendedString and is word aligned
870 #define EXTENDEDSTRINGGREATER( aString , aStringLen , anOtherString , \
871                                anOtherStringLen , MinLen , KGreater ) { \
872  Standard_Integer LoopIndex ; \
873  KGreater = Standard_True ; \
874  LoopIndex = 0 ; \
875  if ( MinLen > 1 ) { \
876    for(; LoopIndex < ( aStringLen >> 1 ) ; LoopIndex++ ) { \
877       if ( ((Standard_Integer *) aString )[ LoopIndex ] != \
878            ((Standard_Integer *) anOtherString )[ LoopIndex ] ) { \
879         LoopIndex++ ; \
880         break ; \
881         } \
882       } \
883    LoopIndex = ( LoopIndex - 1 ) << 1 ; \
884  } \
885  for (; LoopIndex < MinLen ; LoopIndex++ ) { \
886     if ( aString[ LoopIndex ] != anOtherString[ LoopIndex ] ) \
887       break ; \
888     } \
889  if ( LoopIndex != MinLen ) { \
890    if ( aString[ LoopIndex ] < anOtherString[ LoopIndex ] ) \
891      KGreater = Standard_False ; \
892  } \
893  else if ( aStringLen <= anOtherStringLen ) \
894    KGreater = Standard_False ; \
895 }
896
897 #  else
898
899 #define STRLEN(s,i) {(i) = 0;while((s)[(i)++] != '\0');(i)--;}
900 #define EXTSTRLEN(s,i) {(i) = 0;while((s)[(i)++] != 0);(i)--;}
901 #define STRCPY(s1,s2,i) {for(int j=0; j<(i); j++)(s1)[j] = (s2)[j];}
902 #define STRCAT(s1,i,s2,j) {for(int k=0; k<(j); k++) (s1)[(i)+k] = (s2)[k];}
903
904 # endif
905
906 #endif